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

[讨论] 能不能避免sql硬解析

[复制链接]
论坛徽章:
0
11#
 楼主| 发表于 2012-10-18 15:12 | 只看该作者
Yong Huang 发表于 2012-10-18 00:07
I still don't see how you come to the conclusion that (1) your parse time is high, (2) your first fe ...

感谢回复!
你提供的方法很有效,我已经将测试结果添加到了一楼,请查看。
根据以上结果我觉得可以回答你提出的两个问题。
先回答第二个 (2) your first few parses are hard.根据上面的测试结果,确实表明了前面6次是hard parsing。

然后是第一个 (1) your parse time is high
针对这个问题,我是这么测试的
执行alter system flush buffer_cache,再执行sql,对查询速度基本没有影响,6次之前还是慢,6次之后还是快。
执行alter system flush shared_pool, 再执行sql,本来执行6次后会变快,此时会变慢,重新执行6 次后,再变快。
根据以上现象,buffer cache对速度没影响,shared pool对速度有直接影响。加上根据新的测试结果,软解析的时候sql速度变快,所以我认为该sql的主要执行时间花在了hard parsing上面。

不知道我理解得对不对,请继续发表你的见解,谢谢!

使用道具 举报

回复
论坛徽章:
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
12#
发表于 2012-10-19 00:53 | 只看该作者
本帖最后由 Yong Huang 于 2012-10-18 10:57 编辑

I think the first few parses are hard because of CBO's feedback control, which you can disable by

alter session set "_optimizer_use_feedback" = false;

Setting optimizer_features_enable to anything before 11.2 (not necessarily 10.2) can of course disable that too. I've seen quite a number of reports and anecdotes about the trouble caused by this 11gR2 new feature. Disabling it is advised in all the cases. Are you sure v$sql_shared_cursor has no column with value 'Y', including use_feedback_stats?

Parse time statistics exist in v$sesstat. Why not check their values? You can compare them with elapsed_time to see the ratio or percentage parsing takes.

使用道具 举报

回复
论坛徽章:
0
13#
 楼主| 发表于 2012-10-19 15:50 | 只看该作者
本帖最后由 zkbucciarati 于 2012-10-19 15:53 编辑
Yong Huang 发表于 2012-10-19 00:53
I think the first few parses are hard because of CBO's feedback control, which you can disable by

...

你好,问题基本解决,你的分析基本是正确的,非常谢谢!最终的效果是sql执行只产生一个父游标一个子游标,执行计划得到重用。
但是还是有些奇怪的地方,总结如下:

在windows 32bit oracle企业版11.2.0.1.0上面,v$sql_shared_cursor视图是没有use_feedback_stats这个字段的。这是我们的测试系统,我之前的测试都是在这个环境下做的。修改_optimizer_use_feedback=false之后,问题解决,虽然use_feedback_stats这个字段是没有的,这个很奇怪。

在hp ux 64bit oracle企业版11.2.0.2.0上面,v$sql_shared_cursor视图有use_feedback_stats这个字段,这个字段列在了最后面,估计是这个版本才加入的。修改_optimizer_use_feedback=false之后,问题也解决。



使用道具 举报

回复
论坛徽章:
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
14#
发表于 2012-10-19 22:01 | 只看该作者
本帖最后由 Yong Huang 于 2012-10-19 08:19 编辑

Good to know the problem was indeed caused by CBO's feedback control. That's a feature introduced in 11.2.0.1, judging from the fact that parameters _optimizer_feedback_control and _optimizer_use_feedback both started to appear in x$ksppi in that version. V$sql_shared_cursor in 11.2.0.1 apparently didn't catch up with this new technology. If you really want, you can try the SQL underneath this view, i.e. the SQL shown in the output of this query:

SQL> select view_definition from v$fixed_view_definition where view_name = 'GV$SQL_SHARED_CURSOR';

VIEW_DEFINITION
--------------------------------------------------------------------------------------------------
select inst_id, sql_id, kglhdpar, kglhdadr, childno, decode(bitand(bitvector, POWER(2,0)), POWER(2
...

in 11.2.0.1 when you logon as sys. The only problem is that you need to get that SQL from 11.2.0.1 first and find the fixed table (fixed view) to be x$kkscs because 11.2.0.2 (and above) has the long definition of the view cut off. But the bit in bitvector column representing use_feedback_stats is not in 11.2.0.1. You just have to guess that bit by comparing this long SQL in 11.2.0.1 and 11.2.0.2.

Actually, there's an easier way. Run this command on your 11.2.0.2 server:

strings $ORACLE_HOME/bin/oracle | grep x\$kkscs

You should be able to see the full SQL that queries x$kkscs. Run this SQL in your 11.2.0.1 database when you logon as sys. You still need to find the bit that corresponds to use_feedback_stats.

But if you don't want to pursue further, that's fine. The problem has been fixed anyway. I was just trying to give you a way to check use_feedback_stats in 11.2.0.1.

使用道具 举报

回复
论坛徽章:
5
2011新春纪念徽章
日期:2011-02-18 11:43:33ITPUB官方微博粉丝徽章
日期:2011-06-29 13:52:50紫蛋头
日期:2011-07-11 13:32:25ITPUB十周年纪念徽章
日期:2011-11-01 16:20:28茶鸡蛋
日期:2013-03-12 13:17:50
15#
发表于 2012-10-22 15:50 | 只看该作者
学习了哇

使用道具 举报

回复
论坛徽章:
86
2015中国数据库技术大会纪念徽章
日期:2015-04-24 16:04:24马上有车
日期:2014-02-19 11:55:14马上有车
日期:2014-02-18 16:41:112014年新春福章
日期:2014-02-18 16:41:11优秀写手
日期:2013-12-18 09:29:11日产
日期:2013-10-17 08:44:39马自达
日期:2013-08-26 16:28:022013年新春福章
日期:2013-02-25 14:51:24ITPUB 11周年纪念徽章
日期:2012-10-23 16:55:51马上有房
日期:2014-02-19 11:55:14
16#
发表于 2012-10-23 11:19 | 只看该作者
很好的案例,充分体现了Yong Huang版主经验的丰富程度。

使用道具 举报

回复
招聘 : Java研发
论坛徽章:
71
马上加薪
日期:2014-02-19 11:55:14蜘蛛蛋
日期:2012-12-26 18:16:01茶鸡蛋
日期:2012-11-16 08:12:48ITPUB 11周年纪念徽章
日期:2012-10-09 18:05:07奥运会纪念徽章:网球
日期:2012-08-23 14:58:08奥运会纪念徽章:沙滩排球
日期:2012-07-19 17:28:14版主2段
日期:2012-07-07 02:21:02咸鸭蛋
日期:2012-03-23 18:17:482012新春纪念徽章
日期:2012-02-13 15:13:512012新春纪念徽章
日期:2012-02-13 15:13:51
17#
发表于 2012-10-23 14:22 | 只看该作者
看起来Cardinality Feedback bug不少呢
Bug 12557401 - Suboptimal plan on 2nd execution caused by cardinality feedback
Bug 14673831 - Suboptimal plan due to bad cardinality feedback with multiple similar schemas and SQL
Bug 9465425 - New cursors generated after cardinality feedback
Bug 8608703 - SubOptimal Execution Plan created by Cardinality Feedback

使用道具 举报

回复
论坛徽章:
6
奥运纪念徽章
日期:2012-11-20 10:27:31奥运纪念徽章
日期:2012-11-28 09:33:312013年新春福章
日期:2013-02-25 14:51:242013年新春福章
日期:2013-06-05 15:29:212013年新春福章
日期:2013-06-05 15:29:212013年新春福章
日期:2013-06-05 15:29:21
18#
发表于 2012-10-23 15:20 | 只看该作者
11.2的版本,在优化器中有一些新特性,比如:在使用绑定变量时,之前的版本,是不能根据绑定变量的实际值,来调整选择best的plan的,也就是一次产生,后面都用这个,尽管有时候会因为一些绑定值,选择比较烂的执行计划。
新版本中,会在选择执行计划的时候,偷窥绑定变量的值,决定选择比较优化的执行计划,或者重新解析。
所以,想要重现,是比较困难。
6个子游标,这个还是可以的。至于执行计划,能否保存,这个貌似没有,profile也只是影响优化器的选择倾向,并不能解决你的问题。

使用道具 举报

回复
论坛徽章:
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
19#
发表于 2012-10-24 01:27 | 只看该作者
> 至于执行计划,能否保存,这个貌似没有

I may have lost context in this part of the discussion. But if you use dbms_shared_pool.keep to keep the child cursor you want (based on the plan for this child, and of course relatively low buffer_gets per execution), does it count as 保存执行计划 ?

使用道具 举报

回复
论坛徽章:
0
20#
发表于 2012-11-13 14:27 | 只看该作者
本帖最后由 Yong Huang 于 2012-11-13 08:54 编辑

也就是说,这条sql的主要瓶颈在paring sql上面,时间主要花在了生成子游标上面,游标能够重用的话,真正取数据是非常快的,由于我们报表中有多条类似的sql,总的执行时间就比较长了。

用set autotrace查看执行计划和统计信息,发现recursive calls这个指标比较异常。第一次执行sql时,recursive calls为13529,之后5次执行,recursive calls都为512,第7次执行开始,recursive calls都为0。

目前解决该问题是暂时将optimizer_features_enable设为10.2.0.5。

使用道具 举报

回复

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

本版积分规则 发表回复

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