ITPUB??ì3
ITPUB论坛 » MS SQL Server » 求优化高手指导!1000PUB币相送,只有这么多了

标题: [笔记] 求优化高手指导!1000PUB币相送,只有这么多了
离线 lovexueer
开心就好



精华贴数 0
个人空间 0
技术积分 2072 (754)
社区积分 364 (1651)
注册日期 2004-5-20
论坛徽章:1
生肖徽章2007版:鼠     
      

发表于 2008-6-30 18:10 
晕,你不会看logical reads ?

用set statistics io on,然后看一下logical reads 是多少?


__________________
---------------------
重出江湖
只看该作者    顶部
离线 xnk9499
一般会员


精华贴数 0
个人空间 0
技术积分 334 (5776)
社区积分 415 (1537)
注册日期 2005-11-2
论坛徽章:3
授权会员生肖徽章2007版:鸡ITPUB新首页上线纪念徽章   
      

发表于 2008-6-30 18:16 
啊!是诶!
怎么看呢?老大指教下!呵呵


只看该作者    顶部
离线 xnk9499
一般会员


精华贴数 0
个人空间 0
技术积分 334 (5776)
社区积分 415 (1537)
注册日期 2005-11-2
论坛徽章:3
授权会员生肖徽章2007版:鸡ITPUB新首页上线纪念徽章   
      

发表于 2008-6-30 18:29 
使用inner merge join
duration  cpu     reads            write
129    176        165        0

使用inner join
241        88        197        0

原sql执行:
  173
101        13        0       
是这个吗?


只看该作者    顶部
离线 lovexueer
开心就好



精华贴数 0
个人空间 0
技术积分 2072 (754)
社区积分 364 (1651)
注册日期 2004-5-20
论坛徽章:1
生肖徽章2007版:鼠     
      

发表于 2008-6-30 18:32 


QUOTE:
原帖由 xnk9499 于 2008-6-30 17:59 发表
使用inner  merge  join :




__________________
---------------------
重出江湖
只看该作者    顶部
离线 xnk9499
一般会员


精华贴数 0
个人空间 0
技术积分 334 (5776)
社区积分 415 (1537)
注册日期 2005-11-2
论坛徽章:3
授权会员生肖徽章2007版:鸡ITPUB新首页上线纪念徽章   
      

发表于 2008-6-30 18:47 
原sql执行:
資料表 'CUSTOMER_PROFILE'。掃描次數 2,邏輯讀入 1471,實體讀取 0,先讀讀入 0。
資料表 'SALES_RECORD'。掃描次數 39,邏輯讀入 82515,實體讀取 0,先讀讀入 0。

使用inner merge join :

資料表 'SALES_RECORD'。掃描次數 58,邏輯讀入 82572,實體讀取 0,先讀讀入 0。
資料表 'CUSTOMER_PROFILE'。掃描次數 2,邏輯讀入 1471,實體讀取 0,先讀讀入 0。

使用inner  join :
資料表 'SALES_RECORD'。掃描次數 1,邏輯讀入 82400,實體讀取 0,先讀讀入 0。
資料表 'CUSTOMER_PROFILE'。掃描次數 1,邏輯讀入 1471,實體讀取 0,先讀讀入 0。


只看该作者    顶部
离线 lovexueer
开心就好



精华贴数 0
个人空间 0
技术积分 2072 (754)
社区积分 364 (1651)
注册日期 2004-5-20
论坛徽章:1
生肖徽章2007版:鼠     
      

发表于 2008-7-1 11:45 
select customer_id, rev,convert(char(8),purchase_date,112)as purchase_date              from (
select x.customer_id,sum(x.quantity*x.actual_price)as rev,x.purchase_date      
from customer_profile y inner join  sales_record x               
on x.customer_id=y.customer_id                                                                        
where x.purchase_date=y.apply_date and x.trx_type='va'                                                               
group by x.customer_id,x.purchase_date
union
select x.customer_id,sum(x.quantity*x.actual_price)as rev,x.purchase_date      
from customer_profile y inner join  sales_record x               
on x.customer_id=y.customer_id                                                                        
where x.purchase_date>y.apply_date and x.trx_type='va'                                                               
group by x.customer_id,x.purchase_date          ) a


select customer_id, rev,convert(char(8),purchase_date,112)as purchase_date              from (
select x.customer_id,sum(x.quantity*x.actual_price)as rev,x.purchase_date      
from customer_profile y inner join  sales_record x               
on x.customer_id=y.customer_id                                                                        
where x.purchase_date=y.apply_date and x.trx_type='va'                                                               
group by x.customer_id,x.purchase_date
union
select x.customer_id,sum(x.quantity*x.actual_price)as rev,x.purchase_date      
from customer_profile y inner merge join  sales_record x               
on x.customer_id=y.customer_id                                                                        
where x.purchase_date>y.apply_date and x.trx_type='va'                                                               
group by x.customer_id,x.purchase_date          ) a

这两个logical reads 和执行计划怎样?

[ 本帖最后由 lovexueer 于 2008-7-1 11:48 编辑 ]


__________________
---------------------
重出江湖
只看该作者    顶部
离线 xnk9499
一般会员


精华贴数 0
个人空间 0
技术积分 334 (5776)
社区积分 415 (1537)
注册日期 2005-11-2
论坛徽章:3
授权会员生肖徽章2007版:鸡ITPUB新首页上线纪念徽章   
      

发表于 2008-7-1 12:16 
强人修改后的执行计划:




xnk9499 上传了这个附件:
2008-7-1 12:17
未命名.JPG (34.5 KB)
 

2008-7-1 12:17
未命名2.JPG (48.01 KB)
 

只看该作者    顶部
离线 xnk9499
一般会员


精华贴数 0
个人空间 0
技术积分 334 (5776)
社区积分 415 (1537)
注册日期 2005-11-2
论坛徽章:3
授权会员生肖徽章2007版:鸡ITPUB新首页上线纪念徽章   
      

发表于 2008-7-1 12:19 
(63327 row(s) affected)

資料表 'SALES_RECORD'。掃描次數 2,邏輯讀入 164800,實體讀取 26,先讀讀入 98886。
資料表 'CUSTOMER_PROFILE'。掃描次數 2,邏輯讀入 2946,實體讀取 0,先讀讀入 0。

(63327 row(s) affected)

資料表 'SALES_RECORD'。掃描次數 121,邏輯讀入 165159,實體讀取 0,先讀讀入 0。
資料表 'CUSTOMER_PROFILE'。掃描次數 4,邏輯讀入 2946,實體讀取 0,先讀讀入 0。


只看该作者    顶部
离线 lovexueer
开心就好



精华贴数 0
个人空间 0
技术积分 2072 (754)
社区积分 364 (1651)
注册日期 2004-5-20
论坛徽章:1
生肖徽章2007版:鼠     
      

发表于 2008-7-1 13:30 
你再比较一下cpu时间,就可以确定那个最优了.


__________________
---------------------
重出江湖
只看该作者    顶部
离线 smthgdin
老会员



精华贴数 0
个人空间 0
技术积分 1319 (1285)
社区积分 1 (34700)
注册日期 2004-5-13
论坛徽章:2
ITPUB元老开发板块每日发贴之星    
      

发表于 2008-7-1 13:33 
赞,呵呵。


__________________
www.kooboy.net
只看该作者    顶部
相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问