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 ...
随机推荐
- .NET下实现分布式缓存系统Memcached (转自网络)
Memcached在.NET中的应用 一.Memcached服务器端的安装(此处将其作为系统服务安装) 下载文件:memcached 1.2.1 for Win32 binaries (Dec 23, ...
- SQLite&&SharedPreferences&&IO读写Sdcard学习笔记
SQLite 轻量级的.嵌入式的.关系型数据库 Android.IOS等广泛使用的的数据库系统 SQLite数据库之中可以方便的使用SQL语句,实现数据的增加.修改.删除.查询等操作 SQLiteOp ...
- asp.net运算符之逻辑运算符以及其他运算符
逻辑(布尔型)运算符用于对boolean型的结果的表达式进行运算,运算的结果都是boolean型.其运算结果如下所示: 运算符 运算 例子 结果 & AND(与) false&true ...
- Cocos2d-x场景切换相关函数介绍
场景切换是通过导演类Director实现的,其中的相关函数如下: runWithScene(Scene* scene).该函数可以运行场景.只能在启动第一个场景时候调用该函数.如果已经有一个场景运行情 ...
- 密码强度的js插件(完成)
效果如下图: 低:
- 《CSS3秘笈》备忘录
第一部分 1. 类名称区分大小写:.special和.SPECIAL不一样 2. :focus 是通过单击或跳格集中在某个地方 3. ::selection 没有单冒号,被选中的文本[ 但是在I ...
- Controller层的写法
项目中的两个Controller层实现类,一个是跳转到jsp页面,一个是以Json形式返回Map键值对. 跳转到jsp页面: package com.controller; import java.i ...
- 跨frame操作dom元素
今天,一群友问到跨frame操作dom元素的问题.于是写了个demo,在此发表在博客里面,供其他同道中人参考! 创建child.html内容如下: <!DOCTYPE HTML PUBLIC & ...
- rest介绍
REST介绍 描述 rest即表述性状态传递(英文:Representational State Transfer,简称REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软 ...
- Windows下MySQLroot密码破解
Win下MySQL修改root密码的多种方法 ##win2003mysql的密码破解 方法1: 用SET PASSWORD命令 mysql -u root mysql> SET PA ...