楼主: beyond_sea

关于绑定变量,直方图,和bind peeking

[复制链接]
论坛徽章:
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
11#
发表于 2008-12-6 14:04 | 只看该作者
原帖由 zergduan 于 2008-12-4 17:04 发表

版主,我记得如果将bind peeking关闭,将回到9i之前的方式,直方图不会被用于计算,东南西北将使用25%被考虑,这样的执行计划并不好,我认为既然lz可以修改sql,还不如不使用绑定变量,大不了硬解析多一些罢了


It depends on the application. It's OK if hard parsing doesn't cause too much library cache latch contention and shared pool memory pressure to the level that can't be tolerated.

If you search on the Internet, you'll find that many people don't like bind peeking. One reason is that users would rather have predictable performance than performance problems that can't be (easily) explained. In the particular case of 4 values of directions (东南西北), turning off bind peeking thus not using histograms probably causes the SQLs querying 南,西,北 to use an index, which is correct. So at least the users and DBAs know queries of these three values always run OK and the query of 东 always runs bad. With bind peeking, there's no telling when it's OK when it's not.

Many shops take the approach of writing two queries as beyond_sea mentioned. I think it's a good solution. Otherwise, use higher-than-default-level dynamic sampling. I think Tom Kyte shows an example of it to overcome this dilemma.

Yong Huang

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
22
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15复活蛋
日期:2011-07-06 18:52:312011新春纪念徽章
日期:2011-03-29 08:35:29ITPUB9周年纪念徽章
日期:2010-10-08 09:32:262010广州亚运会纪念徽章:曲棍球
日期:2010-09-18 22:57:592010新春纪念徽章
日期:2010-03-01 11:21:03祖国60周年纪念徽章
日期:2009-10-09 08:28:002009新春纪念徽章
日期:2009-01-04 14:52:28生肖徽章2007版:狗
日期:2008-12-28 21:42:40
12#
 楼主| 发表于 2008-12-6 17:23 | 只看该作者
原帖由 Yong Huang 于 2008-12-6 14:04 发表


It depends on the application. It's OK if hard parsing doesn't cause too much library cache latch contention and shared pool memory pressure to the level that can't be tolerated.

If you search on the Internet, you'll find that many people don't like bind peeking. One reason is that users would rather have predictable performance than performance problems that can't be (easily) explained. In the particular case of 4 values of directions (东南西北), turning off bind peeking thus not using histograms probably causes the SQLs querying 南,西,北 to use an index, which is correct. So at least the users and DBAs know queries of these three values always run OK and the query of 东 always runs bad. With bind peeking, there's no telling when it's OK when it's not.

Many shops take the approach of writing two queries as beyond_sea mentioned. I think it's a good solution. Otherwise, use higher-than-default-level dynamic sampling. I think Tom Kyte shows an example of it to overcome this dilemma.

Yong Huang



调优真的是一门艺术,需要在各种方面之间权衡.谢谢版主.

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
21
奥运会纪念徽章:赛艇
日期:2008-07-05 23:31:28数据库板块每日发贴之星
日期:2009-01-07 01:01:02数据库板块每日发贴之星
日期:2009-02-03 01:01:02ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:45生肖徽章2007版:狗
日期:2009-03-10 21:36:37生肖徽章2007版:鼠
日期:2009-03-14 08:57:17CTO参与奖
日期:2009-03-23 11:00:182010广州亚运会纪念徽章:空手道
日期:2011-02-18 16:02:23迷宫蛋
日期:2011-07-31 01:30:132009新春纪念徽章
日期:2009-01-04 14:52:28
13#
发表于 2009-2-19 16:31 | 只看该作者
"
Otherwise, use higher-than-default-level dynamic sampling. I think Tom Kyte shows an example of it to overcome this dilemma.
"

这个我还没查到, Yong Huang 能否详细讲讲?

使用道具 举报

回复
论坛徽章:
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#
发表于 2009-2-20 06:53 | 只看该作者
原帖由 owlstudio 于 2009-2-19 02:31 发表
"
Otherwise, use higher-than-default-level dynamic sampling. I think Tom Kyte shows an example of it to overcome this dilemma.
"
这个我还没查到, Yong Huang 能否详细讲讲?


It took me a while to find Tom's article. Now I'm reading it, his use of dynamic sampling is not to solve the problem of unlucky bind peeking; instead it's to solve the wrong cardinality estimate. But I think there's still some relevance here. Let me think about it.

See Q&A "Why the Cardinality Difference?" at
http://www.oracle.com/technology ... -may/o38asktom.html

Also read the link referenced in it:
asktom.oracle.com/tkyte/DynamicSample.html

Yong Huang

使用道具 举报

回复
论坛徽章:
75
生肖徽章:猪
日期:2014-09-05 10:25:05指数菠菜纪念章
日期:2016-10-17 16:12:49生肖徽章:兔
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:鼠
日期:2015-02-05 16:49:02生肖徽章:马
日期:2015-02-05 16:49:02生肖徽章:羊
日期:2015-02-06 08:40:35生肖徽章:羊
日期:2015-02-06 08:40:34股神
日期:2015-01-05 08:27:16菲尼克斯太阳
日期:2014-12-29 13:11:51
15#
发表于 2009-3-2 11:30 | 只看该作者
原帖由 zergduan 于 2008-12-5 12:49 发表
不至于吧,向你说的一共就4个sql能造成4031?你share_pool也太小了...



改为常量后,每次都会做hard parse?在大并发的情况下,这样得不偿失吧。

使用道具 举报

回复
论坛徽章:
58
生肖徽章2007版:马
日期:2009-11-06 23:12:33授权会员
日期:2013-01-10 14:38:592013年新春福章
日期:2013-02-25 14:51:24马自达
日期:2013-08-07 10:54:45红旗
日期:2013-08-09 13:48:48劳斯莱斯
日期:2013-09-12 15:56:37萤石
日期:2013-10-31 08:44:19优秀写手
日期:2013-12-18 09:29:13Jeep
日期:2014-01-14 10:53:432014年新春福章
日期:2014-02-18 16:43:09
16#
发表于 2011-9-18 21:04 | 只看该作者
up

使用道具 举报

回复
论坛徽章:
1
ITPUB十周年纪念徽章
日期:2011-11-01 16:21:15
17#
发表于 2011-9-20 17:19 | 只看该作者
to sharing with my experiment in short.

" In some situations bind peeking can occur when it should not eg: Bind peeking can occur for user binds even if  "_optim_peek_user_binds" is set to FALSE. "
except from Query using Bind Variables is suddenly slow [ID 387394.1]

I tried in 10.2.0.4 and failed to avoid bind variable peeking.

In 11.2.0.2, I failed to simulate adaptive cursor sharing .  (need to drill down further)

but for both version, literal SQL works fine.

使用道具 举报

回复
论坛徽章:
5
2011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:26:292012新春纪念徽章
日期:2012-01-04 11:57:362012新春纪念徽章
日期:2012-02-07 09:59:35秀才
日期:2016-06-23 14:15:06
18#
发表于 2011-9-23 18:31 | 只看该作者
学习了.

使用道具 举报

回复
论坛徽章:
4
授权会员
日期:2005-10-30 17:05:33ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54优秀写手
日期:2013-12-18 09:29:11
19#
发表于 2011-9-27 14:04 | 只看该作者
个人感觉,peeking导致的问题比它解决的问题多。在正确的时间,peeking到正确的变量,何其幸也!

注意在10.2.0.3,关闭_optim_peek_user_binds 也未必管用

(unpublished) Bug:5082178 (fixed in 10.2.0.4 and 11.x).

Details:
In some situations bind peeking can occur when it should not eg: Bind peeking can occur for user binds even if  "_optim_peek_user_binds" is set to FALSE.
This can cause binds to be marked "unsafe" leading to cursors not being shared when they should be.
This fix is notable as plan changes could occur if statements suffering this problem execute in a release with this fix as the CBO will no longer have peeked data to use when determining an execution plan.

使用道具 举报

回复
论坛徽章:
5
2011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:26:292012新春纪念徽章
日期:2012-01-04 11:57:362012新春纪念徽章
日期:2012-02-07 09:59:35秀才
日期:2016-06-23 14:15:06
20#
发表于 2011-10-7 08:14 | 只看该作者
直方图的数据要做 搜集的吧.而且数据量小的时候,也会full scan的

使用道具 举报

回复

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

本版积分规则 发表回复

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