楼主: alexanderr

[讨论] 一条语句不走索引!

[复制链接]
论坛徽章:
2
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
21#
 楼主| 发表于 2010-9-8 11:22 | 只看该作者

回复 #19 杨奇龙 的帖子

这个clustering_factor有临界值吗?
就是在多少以上CBO会选择FTS,在多少以下又会走index?
还是说这个选择本身就很模糊,对不同表或者语句有不同的标准?
谢谢

使用道具 举报

回复
论坛徽章:
2
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
22#
 楼主| 发表于 2010-9-8 11:23 | 只看该作者

回复 #20 janeson_lin 的帖子

这两种修改都是对全局的吗?
如果是这样,我想我就不会做修改了

谢谢

使用道具 举报

回复
论坛徽章:
2
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
23#
 楼主| 发表于 2010-9-8 16:09 | 只看该作者

回复 #8 Yong Huang 的帖子

这是10053的trace文件

请帮忙分析,谢谢

[ 本帖最后由 alexanderr 于 2010-9-8 16:16 编辑 ]

ora_4815.txt

54.12 KB, 下载次数: 15

ora_23595.txt

39.7 KB, 下载次数: 12

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
24#
发表于 2010-9-9 04:11 | 只看该作者
According to the 10053 trace in ora_23595.txt, the SQL
select * from SFISM4.R_SN_DETAIL_T WHERE IN_STATION_TIME <= SYSDATE - 30
chooses FTS because
(1) your table has 842467 blocks, Oracle uses its internal algorithm for multiblock reads to reach a cost of 187494.82 for FTS (which means the multiblock read factor is about 4.5);
(2) index range scan followed by table scan has a cost of 3274969, which is about 2 + 36015*0.41925 + 7775560*0.41925, i.e. index blevel + index leaf blocks*index selectivity + clustering factor*table selectivity (ix_sel_with_filters).

You can see the index access path is about 17 times higher. If the table and index stats are fairly accurate, you can't blame CBO. One thing you can easily verify is number of rows and blocks. If they are close to what you see in select count(*) ... and dba_segments, then check index selectivity. If you think you should only get 25% of the rows, then the selectivity of 0.41925 is way too high. Can you check again to see if the stats are up-to-date? If yes, are the data on IN_STATION_TIME somewhat skewed? If yes, try collecting a histogram with 254 buckets.

Yong Huang

使用道具 举报

回复
论坛徽章:
2
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
25#
 楼主| 发表于 2010-9-9 14:47 | 只看该作者

回复 #24 Yong Huang 的帖子

execute 'select count(*) from table' ,the number of rows is 12688271,
i can see that the table was gathered statistics on Sep 2ed and the number of rows is 13130285 from the ORACLE EM.
the blocks number is exactly the same.
is this table stats accurate enough?


which means the multiblock read factor is about 4.5);
i don't understand this,can you tell me how the result 4.5 is calculated?

i.e. index blevel + index leaf blocks*index selectivity + clustering factor*table selectivity (ix_sel_with_filters).
i am so interested in where i can learn the above fomula and even more comprehensive
i will appreciate it if u can give me some links to study

使用道具 举报

回复
论坛徽章:
47
蒙奇·D·路飞
日期:2017-03-27 08:04:23马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11一汽
日期:2013-09-01 20:46:27复活蛋
日期:2013-03-13 07:55:232013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-09 18:03:322012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20
26#
发表于 2010-9-10 04:46 | 只看该作者
13130285 is close enough to 12688271 in my opinion.

You can find answers to your latter two questions in Woflgang Breitling's articles at www.centrexcc.com and Jonathan Lewis's book "Cost Based Optimizer".

Yong Huang

使用道具 举报

回复
论坛徽章:
0
27#
发表于 2010-9-10 23:21 | 只看该作者

回复 #22 alexanderr 的帖子

修改clustering_factor只是给表本身一个假的统计信息,将它调小,在计算成本的时候,使采用索引的时候成本变低,可以观察执行计划,当clustering_factor小到一定程度的时候,采用索引的成本将比采用全部扫描的成本要低的时候,它就采用索引方式,这只对用到这张表的这个索引的相关语句有影响,并不是全局的。

使用道具 举报

回复
论坛徽章:
2
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
28#
 楼主| 发表于 2010-9-13 09:18 | 只看该作者

回复 #27 janeson_lin 的帖子

谢谢

使用道具 举报

回复
论坛徽章:
2
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:51ITPUB十周年纪念徽章
日期:2011-11-01 16:24:04
29#
 楼主| 发表于 2010-9-13 09:19 | 只看该作者

回复 #26 Yong Huang 的帖子

thank u , master

使用道具 举报

回复
论坛徽章:
27
授权会员
日期:2005-10-30 17:05:33管理团队成员
日期:2011-05-07 01:45:082012新春纪念徽章
日期:2012-02-13 15:11:362012新春纪念徽章
日期:2012-02-13 15:11:362012新春纪念徽章
日期:2012-02-13 15:11:362012新春纪念徽章
日期:2012-02-13 15:11:362012新春纪念徽章
日期:2012-02-13 15:11:36优秀写手
日期:2013-12-18 09:29:13马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14
30#
发表于 2010-9-19 04:07 | 只看该作者
在返回结果集大的情况下,全表扫描未必比走索引慢

使用道具 举报

回复

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

本版积分规则 发表回复

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