123
返回列表 发新帖
楼主: ylsired

绑定变量与PEEKING --CBO 的痛 ?

[复制链接]
论坛徽章:
2
授权会员
日期:2005-10-30 17:05:33会员2006贡献徽章
日期:2006-04-17 13:46:34
21#
发表于 2005-12-27 22:59 | 只看该作者
bind peeking 和histograms感觉互相制约。。
        
如果没用绑定变量,分析了列的histograms后就能得到更加精确的执行计划。
用了绑定变量就如biti所说,就看Peek得到的变量的值了。
              
不知道10g是否有改进?

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
17
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:442010新春纪念徽章
日期:2010-03-01 11:20:05
22#
发表于 2005-12-28 09:25 | 只看该作者

Re: 绑定变量与PEEKING --CBO 的痛 ?

最初由 ylsired 发布
[B]最近在9i 做SQL TUNNING,经常发现EXPLAIN PLAN的执行计划与语句实际执行的计划(v$sql_plan中查询)不同,原因就是语句中多处使用了绑定变量,特别是对于日期范围查询,单证范围查询等用了 > ,< 操作符的条件,cbo往往无法选择到真正最佳的执行计划;而不使用绑定变量,就没有此问题,真是苦恼啊。
大家对此类问题又没有什么好的避免措施? [/B]


找个折衷的办法,查询结果老是变化很大的,不用绑定变量、不然就用绑定。

使用道具 举报

回复
论坛徽章:
1
23#
发表于 2005-12-28 09:41 | 只看该作者
我认同楼上的看法,对于查询参数比较确定,就是说where条件的值相对比较固定的话,用常量来替代绑定将产生更加少的soft parse.否则反之。

我记得这个好像也是tom建议的!

使用道具 举报

回复
论坛徽章:
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#
发表于 2005-12-28 10:43 | 只看该作者
Follow-up to rwq_ and liuyi8903's two messages. It sounds like a good idea to not use bind variables if the bind values change significantly. The benefit comes from not only plan stability as you described, but possibly also bind length graduation. When the bind value length changes across a bind threshold, a different cursor version is created. For instance, first you bind 'short string' and later you bind 'a string longer than 32 chars...'. A new row is shown in v$sql for the same sql address and v$sqlarea.version_count increments, and v$sql_shared_cursor.bind_mismatch shows 'Y'. I.e., the first cursor is not shared. But the plan is probably still the same.

On the other hand, this benefit is much smaller. Would you not use bind variables simply because run-time bind values change length wildly? I have to think about an answer.

If what I write is not clear, let me know and I'll clarify.

Yong Huang

使用道具 举报

回复
招聘 : 数据库管理员
论坛徽章:
17
会员2007贡献徽章
日期:2007-09-26 18:42:10ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:442010新春纪念徽章
日期:2010-03-01 11:20:05
25#
发表于 2005-12-28 10:57 | 只看该作者
最初由 Yong Huang 发布
[B]Follow-up to rwq_ and liuyi8903's two messages. It sounds like a good idea to not use bind variables if the bind values change significantly. The benefit comes from not only plan stability as you described, but possibly also bind length graduation. When the bind value length changes across a bind threshold, a different cursor version is created. For instance, first you bind 'short string' and later you bind 'a string longer than 32 chars...'. A new row is shown in v$sql for the same sql address and v$sqlarea.version_count increments, and v$sql_shared_cursor.bind_mismatch shows 'Y'. I.e., the first cursor is not shared. But the plan is probably still the same.

On the other hand, this benefit is much smaller. Would you not use bind variables simply because run-time bind values change length wildly? I have to think about an answer.

If what I write is not clear, let me know and I'll clarify.

Yong Huang [/B]


也许你所说的情况是可能存在的,我们在很多情况下只能解决大部分的问题,而不能解决所有的问题。

使用道具 举报

回复
论坛徽章:
86
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20咸鸭蛋
日期:2012-05-08 10:27:19版主8段
日期:2012-05-15 15:24:112013年新春福章
日期:2013-02-25 14:51:24
26#
发表于 2005-12-28 11:03 | 只看该作者
最初由 Yong Huang 发布
[B]Follow-up to rwq_ and liuyi8903's two messages. It sounds like a good idea to not use bind variables if the bind values change significantly. The benefit comes from not only plan stability as you described, but possibly also bind length graduation. When the bind value length changes across a bind threshold, a different cursor version is created. For instance, first you bind 'short string' and later you bind 'a string longer than 32 chars...'. A new row is shown in v$sql for the same sql address and v$sqlarea.version_count increments, and v$sql_shared_cursor.bind_mismatch shows 'Y'. I.e., the first cursor is not shared. But the plan is probably still the same.

On the other hand, this benefit is much smaller. Would you not use bind variables simply because run-time bind values change length wildly? I have to think about an answer.

If what I write is not clear, let me know and I'll clarify.

Yong Huang [/B]


如果只是考虑到变量长度的原因,但是变量的值本身还是很多的话,还是使用 bind  var为好的。毕竟,oracle在给变量定义长度的时候的区间还是很少的,具体是哪几个我不清楚,可能就是比如

32/64/128/256/1024/2048/4000   这样的少数值了。这样长度变化带来的不同的hard  parse毕竟还是少数。

使用道具 举报

回复

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

本版积分规则 发表回复

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