楼主: myfriend2010

[FAQ] sql 使CPU使用100%,棘手!

[复制链接]
招聘 : Linux运维
论坛徽章:
235
紫蜘蛛
日期:2007-09-26 17:05:46玉兔
日期:2007-09-26 17:05:05现任管理团队成员
日期:2011-05-07 01:45:08玉兔
日期:2006-08-29 20:38:48紫蜘蛛
日期:2007-09-26 17:05:34阿斯顿马丁
日期:2013-11-19 10:38:16奔驰
日期:2013-10-16 09:08:58红旗
日期:2014-01-09 11:57:39路虎
日期:2013-08-13 14:52:35林肯
日期:2015-05-19 13:01:16
51#
 楼主| 发表于 2007-12-9 18:24 | 只看该作者
明天我发这3张表的reorgchk结果你你看看!

使用道具 举报

回复
招聘 : c/c++研发
论坛徽章:
45
技术图书徽章
日期:2014-03-10 14:09:192012新春纪念徽章
日期:2012-02-13 15:12:092012新春纪念徽章
日期:2012-02-13 15:12:092012新春纪念徽章
日期:2012-01-04 11:51:22ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15现任管理团队成员
日期:2011-05-07 01:45:082011新春纪念徽章
日期:2011-01-25 15:42:562011新春纪念徽章
日期:2011-01-25 15:42:332011新春纪念徽章
日期:2011-01-25 15:42:152011新春纪念徽章
日期:2011-01-25 15:41:50
52#
发表于 2007-12-9 21:13 | 只看该作者
reorgchk在这个时候有啥用???

使用道具 举报

回复
论坛徽章:
21
在线时间
日期:2007-07-25 04:01:022012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
53#
发表于 2007-12-10 06:40 | 只看该作者
Can LZ do the following in SEQUENCE:

1) Truncate 09 tables, and load 09 data into these three tables, and runstats on these tables, then do the query explain and save the output to tab09_stats09_data09.plan

2) Run the query below:
select max(cnt), avg(cnt), min(cnt), sum(cnt)
from (select cust_id, count(cust_id) as cnt from <table_name> group by cust_id)

Replace <table_name> with the three table names and save the output as pattern09.out

3) Truncate 09 tables, and load 10 data into 09 tables, DON'T runstats any more. Do the query explain and save the output to tab09_stats09_data10.plan

4) Run the query as in step 2 and save the output as pattern10.out

5) RUNSTATS on 09 tables, and do the query explain and save the output as tab09_stats10_data10.plan

6) Upload the outputs from the above steps

使用道具 举报

回复
招聘 : Linux运维
论坛徽章:
235
紫蜘蛛
日期:2007-09-26 17:05:46玉兔
日期:2007-09-26 17:05:05现任管理团队成员
日期:2011-05-07 01:45:08玉兔
日期:2006-08-29 20:38:48紫蜘蛛
日期:2007-09-26 17:05:34阿斯顿马丁
日期:2013-11-19 10:38:16奔驰
日期:2013-10-16 09:08:58红旗
日期:2014-01-09 11:57:39路虎
日期:2013-08-13 14:52:35林肯
日期:2015-05-19 13:01:16
54#
 楼主| 发表于 2007-12-10 15:40 | 只看该作者
我的 IE坏掉了,不能回贴

使用道具 举报

回复
论坛徽章:
21
在线时间
日期:2007-07-25 04:01:022012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
55#
发表于 2007-12-10 15:41 | 只看该作者
Performance.zip (11.04 KB, 下载次数: 16)

I just created a test case to show how the data pattern change will affect the SQL statement.

In the all the test scenarios, there is no change to table definition, no change to SQL statement, and the only change is the data pattern, and the outdated/updated statistics.

使用道具 举报

回复
论坛徽章:
21
在线时间
日期:2007-07-25 04:01:022012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
56#
发表于 2007-12-10 15:56 | 只看该作者
My first glance at the original SQLs posted by LZ puzzled me. What is the exact relationship between the three tables?

I have to say that I will be very reluctant to join any two tables if the two tables are M-M relationship. I have no idea about the actual data pattern in LZ's 09/10 data, but they may be significant enough to trigger DB2 optimizer to choose different access plan even all the corresponding tables are having the same structure - once DB2 knows the exact statistics.

When tuning a query or explain a query behavior, data pattern is important but unfortunately ignored in many occasions.

I have not tested the performance of the two different queries in my test, but I always believe my t2.sql should perform equally if not better.

[ 本帖最后由 askgyliu 于 2007-12-10 15:59 编辑 ]

使用道具 举报

回复
论坛徽章:
21
在线时间
日期:2007-07-25 04:01:022012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
57#
发表于 2007-12-10 17:56 | 只看该作者
原帖由 askgyliu 于 2007-12-10 06:40 发表
Can LZ do the following in SEQUENCE:

3) Truncate 09 tables, and load 10 data into 09 tables, DON'T runstats any more. Do the query explain and save the output to tab09_stats09_data10.plan

5) RUNSTATS on 09 tables, and do the query explain and save the output as tab09_stats10_data10.plan


If the explain result from these two steps are different, it is almost for sure (10) data has very different pattern from (09) data, and you should not expect the two having the same access plan nor the same kind of performance. DB2 is smart enough to use different access path if it detects the difference.

Try to avoid any M-M relationship in the joining, as to avoid the performance uncertainty, and the potential double counting etc.

使用道具 举报

回复
论坛徽章:
21
在线时间
日期:2007-07-25 04:01:022012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
58#
发表于 2007-12-10 21:44 | 只看该作者
The test case I created shows:

1) When both tables are joining with columns with distinct values, DB2 will use MS Join. This should be the case for (09) data with (09) statistics;

2) When a new set of data is loaded but statistics is not updated, DB2 has no additional information and it will simply adapt the old(wrong) statistics. This is a simulation of loading (10) data into (09) table without statistics update.

3) After statistics update, DB2 realizes one participating table in fact has very few distinct values in the joining column, so DB2 decides to use NL Join with the table with few distinct values as the driving table.

The optimizer just works as what is expected.

使用道具 举报

回复
论坛徽章:
21
在线时间
日期:2007-07-25 04:01:022012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:232012新春纪念徽章
日期:2012-02-13 15:09:23马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:09:23
59#
发表于 2007-12-10 21:47 | 只看该作者
I would really suspect PAR_CUST_CUST_GRP_ASSOC_200710 and PAR_CUST_CUST_GRP_ASSOC_200709 have very different distinct values on CUST_ID. LZ may confirm on this?

使用道具 举报

回复
招聘 : Linux运维
论坛徽章:
235
紫蜘蛛
日期:2007-09-26 17:05:46玉兔
日期:2007-09-26 17:05:05现任管理团队成员
日期:2011-05-07 01:45:08玉兔
日期:2006-08-29 20:38:48紫蜘蛛
日期:2007-09-26 17:05:34阿斯顿马丁
日期:2013-11-19 10:38:16奔驰
日期:2013-10-16 09:08:58红旗
日期:2014-01-09 11:57:39路虎
日期:2013-08-13 14:52:35林肯
日期:2015-05-19 13:01:16
60#
 楼主| 发表于 2007-12-11 19:43 | 只看该作者
不是的,count(distinct CUST_ID) from the two tables are almost number!

askgyliu,ENGLIST 太好了,我直接看不懂,还有就是我的IE有问题,你有QQ没有,加我为好友:51219748
或者msn:
myfriend_2010@hotmail.com

原帖由 askgyliu 于 2007-12-10 21:47 发表
I would really suspect PAR_CUST_CUST_GRP_ASSOC_200710 and PAR_CUST_CUST_GRP_ASSOC_200709 have very different distinct values on CUST_ID. LZ may confirm on this?

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表