12
返回列表 发新帖
楼主: woshiyiziyuma

oracle执行计划选择了不合适的索引

[复制链接]
论坛徽章:
16
ITPUB十周年纪念徽章
日期:2011-11-01 16:24:5120周年集字徽章-周
日期:2020-10-28 14:51:0420周年集字徽章-20	
日期:2020-10-28 14:31:2119周年集字徽章-年
日期:2019-09-06 18:37:2619周年集字徽章-19
日期:2019-09-06 18:23:36弗兰奇
日期:2018-11-22 09:22:28ITPUB18周年纪念章
日期:2018-11-13 15:40:45ITPUB18周年纪念章
日期:2018-09-17 10:12:57ITPUB18周年纪念章
日期:2018-09-17 10:09:49妮可·罗宾
日期:2018-08-15 15:16:15
11#
 楼主| 发表于 2011-9-20 10:25 | 只看该作者
最新的sap ags回复:
Dear Mr. Sun,

Sorry for late reply. Your message has been forwarded to SV-BO
component to check performanc related issues.

Due to no variant for issue reproduction, and the SQL statement doesn't
exist in SQL cache anymore. I fetched the SQL from AWR and found,
in the index COEP~Z01 you mentioned as 'right index', the first column
is 'MATNR', which is not specified in where clause. That's reason
why CBO doesn't use this index and it is the normal behaviour but not a
bug.

I have noticed that you have added hint to force using index~Z01 in
ABAP coding ZCOR051. And I have found the second column of COEP~1 is
LEDNR with distinct 1. If it can be hardcoded in ABAP then index COEP~1
access should be more optimal.

I'll discuss with you later on the phone.

BR,
Alex Li
Support Consultant
SAP AGS China

我不能赞同他说的关于不走索引coep~z01的解释,他给的解释是正确的吗?
索引的相关信息:

使用道具 举报

回复
论坛徽章:
1
ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15
12#
发表于 2011-9-20 15:15 | 只看该作者
woshiyiziyuma 发表于 2011-9-15 23:59
索引COEP~1和COEP~Z01的信息,如图所示:

我已经分析过表,analyze table SAPSR3.COEP  compute statist ...

"我已经分析过表,analyze table SAPSR3.COEP  compute statistics;"

Note that ANALYZE command is deprecated in 10g, use DBMS_STATS instead.

使用道具 举报

回复
论坛徽章:
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
13#
发表于 2011-9-21 01:42 | 只看该作者
OK. I think you're hitting this bug
Bug 8795753: FULL INDEX SCAN NOT CHOSEN EVEN THOUGH COST IS CHEAPER

Also read
CBO Biases FTS Over The Cheaper Index Full Scan (Doc ID 953273.1)

The case in the bug is that higher-cost full table scan is chosen instead of cheaper full index scan. Your case is actually the same, except your lower optimizer_index_cost_adj masked the FTS, i.e. changed it to using the higher cost index coep~1. (Again, please change the wrong index name in your msg #8! It confuses other readers.)

The workaround is exactly what you did: use the index hint. I can't find more information about this bug.

Yong Huang

使用道具 举报

回复
论坛徽章:
16
ITPUB十周年纪念徽章
日期:2011-11-01 16:24:5120周年集字徽章-周
日期:2020-10-28 14:51:0420周年集字徽章-20	
日期:2020-10-28 14:31:2119周年集字徽章-年
日期:2019-09-06 18:37:2619周年集字徽章-19
日期:2019-09-06 18:23:36弗兰奇
日期:2018-11-22 09:22:28ITPUB18周年纪念章
日期:2018-11-13 15:40:45ITPUB18周年纪念章
日期:2018-09-17 10:12:57ITPUB18周年纪念章
日期:2018-09-17 10:09:49妮可·罗宾
日期:2018-08-15 15:16:15
14#
 楼主| 发表于 2011-9-21 10:46 | 只看该作者
Yong Huang 发表于 2011-9-21 01:42
OK. I think you're hitting this bug
Bug 8795753: FULL INDEX SCAN NOT CHOSEN EVEN THOUGH COST IS CHE ...

再次感谢Yong Huang,我已经在8楼改过了。

使用道具 举报

回复
论坛徽章:
16
ITPUB十周年纪念徽章
日期:2011-11-01 16:24:5120周年集字徽章-周
日期:2020-10-28 14:51:0420周年集字徽章-20	
日期:2020-10-28 14:31:2119周年集字徽章-年
日期:2019-09-06 18:37:2619周年集字徽章-19
日期:2019-09-06 18:23:36弗兰奇
日期:2018-11-22 09:22:28ITPUB18周年纪念章
日期:2018-11-13 15:40:45ITPUB18周年纪念章
日期:2018-09-17 10:12:57ITPUB18周年纪念章
日期:2018-09-17 10:09:49妮可·罗宾
日期:2018-08-15 15:16:15
15#
 楼主| 发表于 2011-9-23 14:53 | 只看该作者
我看了953273.1和8795753,但是我觉得文章里描述的bug和我的情况不太像,文章里描述的bug是全表扫描和索引全扫描,而我这里是索引范围扫描和索引全扫描。
不过我不想再纠结这个问题了,因为根据sap的建议,我在where 子句里加上了lednr = “00”,该程序的运行时间大大的缩短了,由原来的至少30分钟减小到了1分钟。

使用道具 举报

回复
论坛徽章:
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
16#
发表于 2011-9-24 01:10 | 只看该作者
> 文章里描述的bug是全表扫描和索引全扫描,而我这里是索引范围扫描和索引全扫描

You didn't read my words:
"The case in the bug is that higher-cost full table scan is chosen instead of cheaper full index scan. Your case is actually the same, except your lower optimizer_index_cost_adj masked the FTS, i.e. changed it to using the higher cost index coep~1."

Normally you should not mess with optimizer_index_cost_adj. It's a parameter to be used by beginners or people not willing to know more about Oracle's CBO.

> 运行时间大大的缩短

Adding lednr = “00” is probably good. But never base your conclusion on execution time. Check buffer gets or consistent gets.

Yong Huang

使用道具 举报

回复
论坛徽章:
16
ITPUB十周年纪念徽章
日期:2011-11-01 16:24:5120周年集字徽章-周
日期:2020-10-28 14:51:0420周年集字徽章-20	
日期:2020-10-28 14:31:2119周年集字徽章-年
日期:2019-09-06 18:37:2619周年集字徽章-19
日期:2019-09-06 18:23:36弗兰奇
日期:2018-11-22 09:22:28ITPUB18周年纪念章
日期:2018-11-13 15:40:45ITPUB18周年纪念章
日期:2018-09-17 10:12:57ITPUB18周年纪念章
日期:2018-09-17 10:09:49妮可·罗宾
日期:2018-08-15 15:16:15
17#
 楼主| 发表于 2011-9-24 08:27 | 只看该作者
Yong Huang 发表于 2011-9-24 01:10
> 文章里描述的bug是全表扫描和索引全扫描,而我这里是索引范围扫描和索引全扫描

You didn't read my wo ...

Note 830576 - Parameter recommendations for Oracle 10g.pdf (147.51 KB, 下载次数: 9)
optimizer_index_cost_adj  是sap建议我们改成20的,附件是sap 的notes。

使用道具 举报

回复
论坛徽章:
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
18#
发表于 2011-9-25 11:23 | 只看该作者
> optimizer_index_cost_adj  是sap建议我们改成20的,附件是sap 的notes。

It's OK. SAP or not, messing with that parameter indicates not putting enough effort into finding the real problem. But since you're running vendor's app, you may not have a choice other than following their suggestion. Once we were told by a vendor to set cursor_sharing=similar in spite of our explanation of its bugs, its ineffectiveness and other issues. I think the DBA managing that app obliged, because the vendor may desupport us if we don't.

Yong Huang

使用道具 举报

回复

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

本版积分规则 发表回复

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