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的更多相关文章

  1. SQL TUNNING

    In a Nested Loops Join, for example, the first accessed table is called the outer table and the seco ...

  2. advisor调优工具优化sql(基于sql_id)

    advisor调优工具优化sql(基于sql_id) 问题背景:客户反馈数据库迁移后cpu负载激增,帮忙查看原因 解决思路:1> 查看问题系统发现有大量的latch: cache buffers ...

  3. 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 ...

  4. 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 ...

  5. 为什么需要SQL Profile

    为什么需要SQL Profile Why oracle need SQL Profiles,how it work and what are SQL Profiles... 使用DBMS_XPLAN. ...

  6. Oracle - PL/SQL Commands

    第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> a ...

  7. ORACLE SQL TUNING ADVISOR 使用方法

    sql tunning advisor 使用的主要步骤: 1 建立tunning task 2 执行task 3 显示tunning 结果 4 根据建议来运行相应的调优方法  下面来按照这个顺序来实施 ...

  8. SQL Server 2012 books

    SQL Server 2012 Introducing Microsoft SQL Server 2012 Microsoft SQL Server 2012 High-Performance T-S ...

  9. Performance Tunning - OCP

    This artical is forcused on Oracle 11g Release 2.  It is an summary from the OCP documentation. The ...

随机推荐

  1. hdu 4144 状态压缩dp

    #include<map> #include<set> #include<cmath> #include<queue> #include<cstd ...

  2. 【转】PS学堂之一:展示一下自己做的圆形印章

    共分七个步骤: 1.点击文件--新建,新建一个500×500像素,背景为透明的文件,选择RGB颜色. 2.把前景色和文字颜色设置为正红(R为255,G和B为0). 3.在视图下拉菜单中选择标尺,将横. ...

  3. java操作xml的一个小例子

    最近两天公司事比较多,这两天自己主要跟xml打交道,今天更一下用java操作xml的一个小例子. 原来自己操作xml一直用这个包:xstream-1.4.2.jar.然后用注解的方式,很方便,自己只要 ...

  4. jQuery插件的编写和使用 <思维导图>

    以下是jQuery插件的编写和使用的思维导图,全屏观看,请点击:jQuery插件的编写和使用

  5. Sql Server 数据库之间如何进行跨网远程连接访问

    场景说明 现在有一台A电脑和一台B电脑,两台电脑都安装了Sql Server数据库,两台电脑不在一个局域网(我们考虑的是不同网络的两台数据库连接),比如A电脑在公司,B电脑在家里,现在我要在家里用B电 ...

  6. cocos2dx-lua之断点调试支持

    cocos2dx 3.2版对cocos code ide支持已经相当棒了,不过话说,编辑器用起来感觉没有sublime顺手 支持cocos code ide已经支持创建lua项目了,可是默认创建的项目 ...

  7. 配置Rip的认证

      实验拓扑图 PS:我做实验使用的是DynamipsDUI模拟器,并且加载的是真实的ios镜像(c3745-advipservicesk9-mz.124-3c.bin) 1. 配置路由器R1 2. ...

  8. (转)RabbitMQ消息队列(七):适用于云计算集群的远程调用(RPC)

    在云计算环境中,很多时候需要用它其他机器的计算资源,我们有可能会在接收到Message进行处理时,会把一部分计算任务分配到其他节点来完成.那么,RabbitMQ如何使用RPC呢?在本篇文章中,我们将会 ...

  9. ResourceBundle和Properties(转载)

    转载: 一般来说,ResourceBundle类通常是用于针对不同的语言来使用的属性文件. 而如果你的应用程序中的属性文件只是一些配置,并不是针对多国语言的目的.那么使用Properties类就可以了 ...

  10. <Linux下FTP服务的搭建>

    默认安装好ftp软件包匿名用户是可以下载的.匿名以后可以上传:anon_upload_enable=YES# getsebool -a | grep ftpallow_ftpd_anon_write ...