creating indexing for SQL tunning
1. Not so long time ago, I got a report from customer. It's reported that they had a report getted very slow and finally throw an error. I finded fout the problem sql in source code and excuted it in sql managment studio. It costs 1 minute and 46 seconds to run this sql. Indeed, it's quite slowly.

orginal sql:
SELECT distinct case when tblShopPayment.AccountID=0 then 1 else 0 end as Category, tblShopPayment.PaymentID, tblShopPayment.OperatorID, tblShopPayment.AccountID,
tblShopPayment.PaymentCreateDate, tblShopPayment.PaymentModeID, tblShopPayment.FlagPaid, tblShopPaymentDetail.ProductName, tblShopPaymentDetail.Quantity, tblShopPaymentDetail.Price,
vw_ShopAccountInfo.FirstName, vw_ShopAccountInfo.LastName, tblShopPaymentMode.PaymentModeName FROM tblShopPaymentMode INNER JOIN tblShopPayment INNER JOIN tblShopPaymentDetail
ON tblShopPayment.PaymentID = tblShopPaymentDetail.PaymentID ON tblShopPaymentMode.PaymentModeID = tblShopPayment.PaymentModeID INNER JOIN TblShopProduct
ON tblShopPaymentDetail.ProductID = TblShopProduct.ProductID INNER JOIN tblShopProductCategory ON TblShopProduct.CategoryID = tblShopProductCategory.ProductCategoryID
LEFT OUTER JOIN vw_ShopAccountInfo INNER JOIN tblShopAccount ON vw_ShopAccountInfo.UniqueNo = tblShopAccount.UniqueNo ON tblShopPayment.AccountID = tblShopAccount.AccountID
WHERE tblShopPayment.PaymentCreateDate >=convert(datetime,'9.1.2015',104) and tblShopPayment.PaymentCreateDate <=convert(datetime,'10.1.2015',104) and SysTypeID = 3 order by LastName
2. solving the problem
There are 2 solutions to solve the problem.
One way is rebuild the sql , One way is to create index.
I don't want to rebuild the sql. It's so complex and hard to rebuild.
So , I chose to create index.
After creating following indexes, the query reduce to 1 second. Yes, 1s.
--creating following index to improve performance
--creating following index to improve performance --CREATE NONCLUSTERED INDEX [IXZY_tblShopPaymentDetail1]
--ON [dbo].[tblShopPaymentDetail] ([PaymentID])
--INCLUDE ([ProductID],[ProductName],[Quantity],[Price]) --CREATE NONCLUSTERED INDEX [IXZY_1Students1]
--ON [dbo].[Students] ([Enter_schooltime],[Leave_schooltime])
--INCLUDE ([First_name],[Last_name],[UniqueNo]) --CREATE NONCLUSTERED INDEX [IXZY_1Students12]
--ON [dbo].[Students] ([UniqueNo],[Enter_schooltime],[Leave_schooltime])
--INCLUDE ([First_name],[Last_name]) --CREATE NONCLUSTERED INDEX [IXZY_STAFF1]
--ON [dbo].[Staff] ([AttendStart],[AttendEnd])
--INCLUDE ([FirstName],[LastName],[UniqueNO]) --CREATE NONCLUSTERED INDEX [IXZY_Staff2]
--ON [dbo].[Staff] ([UniqueNO],[AttendStart],[AttendEnd])
--INCLUDE ([FirstName],[LastName]) --CREATE NONCLUSTERED INDEX [IXZY_Parent1]
--ON [dbo].[Parent] ([UniqueNo])
--INCLUDE ([FirstName],[LastName],[Family_ID])
creating indexing for SQL tunning的更多相关文章
- SQL TUNNING
In a Nested Loops Join, for example, the first accessed table is called the outer table and the seco ...
- advisor调优工具优化sql(基于sql_id)
advisor调优工具优化sql(基于sql_id) 问题背景:客户反馈数据库迁移后cpu负载激增,帮忙查看原因 解决思路:1> 查看问题系统发现有大量的latch: cache buffers ...
- Indexed (materialized) views in SQL Server,different with Oracle (materialized) views
Thanks to MS sql could have materialized views ,similar with oracle MVs, using indexed views. what i ...
- P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1
P6 Professional Installation and Configuration Guide (Microsoft SQL Server Database) 16 R1 May ...
- 为什么需要SQL Profile
为什么需要SQL Profile Why oracle need SQL Profiles,how it work and what are SQL Profiles... 使用DBMS_XPLAN. ...
- Oracle - PL/SQL Commands
第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> a ...
- ORACLE SQL TUNING ADVISOR 使用方法
sql tunning advisor 使用的主要步骤: 1 建立tunning task 2 执行task 3 显示tunning 结果 4 根据建议来运行相应的调优方法 下面来按照这个顺序来实施 ...
- SQL Server 2012 books
SQL Server 2012 Introducing Microsoft SQL Server 2012 Microsoft SQL Server 2012 High-Performance T-S ...
- Performance Tunning - OCP
This artical is forcused on Oracle 11g Release 2. It is an summary from the OCP documentation. The ...
随机推荐
- CSS之密码强度检测
输入密码后单击空白处即可检测. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "ht ...
- linux中mail函数不能发送邮件
没有安装或启动 sendmail 组件 解决办法 我是新手,命令不熟,所以写的很详细,老鸟勿喷哦 1.重新安装 sendmail 组件,我用的是 CentOS ,使用下面的命令安装 代码如下 复制代码 ...
- express模块安装后cmd中不能运行
在各种关于NodeJS的教材中,必定会有关于express的介绍.express本身是一个很赞的库. 在之前的express版本中,在全局模式安装(npm -g install express)之后, ...
- State模式
地铁十字转门 状态迁移表格. 起始状态 触发迁移的事件 终止状态 要执行的动作. Locked Coin UnLocked UnLock UnLocked Pass ...
- ./configure:command not found 解决方法
有些下载下来的源码没有MAKEFILE文件,但是会有MAKEFILE.IN 和 configure, MAKEFILE文件则由后两个文件生成. 如果执行: $./configure 提示错误:./ ...
- think in java 第四版读书笔记 第一章对象导论
很久没有碰过java了,为了项目需要以及以后找工作,还是有必要将think in java通读一遍.欢迎大家一起讨论学习 1.1抽象过程 面向对象语言的5个特性: 1.万物皆对象 任何事物都可以抽象为 ...
- 小米pad MI PAD 开发者选项、USB调试开启方式
设置->关于平板->在MIUI版本一行连续点击7次. 之后就出现了开发者选项.可以开启USB调试等. 你能想到吗……??
- NFS网络操作系统介绍以及相关应用
1. NFS服务简介 NFS是Network File System 的缩写,中文名称为网络文件系统,由Sun公司开发,功能是通过网络让不同的机器.不同的操作能够彼此分享数据,让应用程序在客户端通过网 ...
- 使用struct实现面向对象编程的封装
虽然C是面向过程的语言,但是这不代表C不能使用面向对象的思想,本质上说语言只是一种手段而已,一种外在的表现形式,支持面向对象的语言只是通过设计的特定的关键字更好的表现了面向对象编程而已.C中也可以使用 ...
- svn不能更新也不能提交【svn A conflict in the working copy obstructs the current operation】
SVN不能提交解决方法: 最近发现了svn有一种特殊的冲突,跟svn版本库同步的时候,还提示代码没有不一样的,但是文件图标上又是一个特殊的冲突符号,不是那种大红的冲突符号.更新不了也 ...