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 ...
随机推荐
- C#导出数据至excel模板
开源分享最近一个客户要做一个将数据直接输出到指定格式的Excel模板中,略施小计,搞定 其中包含了对Excel的增行和删行,打印预览,表头,表体,表尾的控制 using System; using S ...
- ES6:JavaScript 新特性
我相信,在ECMAScript.next到来的时候,我们现在每天都在写的JavaScript代码将会发生巨大的变化.接下来的一年将会是令JavaScript开发者们兴奋的一年,越来越多的特性提案将被最 ...
- sql server 中 syscolumns 各个字段的意义
列名 数据类型 描述 name sysname 列名或过程参数的名称. id int 该列所属的表对象 ID,或与该参数关联的存储过程 ID. xtype tinyint systypes 中的物理存 ...
- AsyncTask实现的原理和适用的优缺点
AsyncTask,是android提供的轻量级的异步类,可以直接继承AsyncTask,在类中实现异步操作,并提供接口反馈当前异步执行的程度(可以通过接口实现UI进度更新),最后反馈执行的结果给UI ...
- XML DOM 循环(foreach)读取PHP数据 和 PHP 编写 XML DOM 【转载】
用 PHP 读取和编写可扩展标记语言(XML)看起来可能有点恐怖.实际上,XML 和它的所有相关技术可能是恐怖的,但是用 PHP 读取和编写 XML 不一定是项恐怖的任务.首先,需要学习一点关于 XM ...
- php中magic_quotes_gpc对unserialize的影响
昨天朋友让我帮他解决下他网站的购物车程序的问题,程序用的是PHPCMS,换空间前是好的(刚换的空间),具体问题是提示成功加入购物车后跳转到购物车页面,购物车里为空. 我看了下代码,大致的原理就是将产品 ...
- Mvc项目右键没有控制器选项
今天遇到了一个比较少见的问题,我用vs2010打开一个从Svn上拉下来的mvc2项目,在Controller文件夹上右键却发现没有新建控制器的选项,在View文件夹上右键也没有新建视图的选项. 我的第 ...
- eBay 开发流程
1[记录]注册成为eBay开发者(eBay Developers Program)+创建Sanbox Key和Production Key http://www.crifan.com/register ...
- iOS 触摸的位置放一个大头针
iOS 触摸的位置放一个大头针 UITapGestureRecognizer *mTap = [[UITapGestureRecognizer alloc] initWithTarget:self a ...
- 【学习笔记】【C语言】常量
1. 什么是常量 常量,表示一些固定的数据 2. 常量的分类 1> 整型常量(int) 包括了所有的整数,比如6.27.109.256.-10.0.-289等 2> 浮点型常量(float ...