v$sql_shared_cursor中的BIND_MISMATCH

转自网络
The advantage of bind variables is that they allow the sharing of cursors in the library cache
and that way avoid hard parses and the overhead associated with them. The following example,
which is an excerpt of the output generated by the script. bind_variables.sql, shows three
INSERT statements that, thanks to bind variables, share the same cursor in the library cache:
SQL> variable n NUMBER
SQL> variable v VARCHAR2(32)
SQL> execute :n := 1; :v := ;
SQL> INSERT INTO t (n, v) VALUES (:n, :v);
SQL> execute :n := 2; :v := ;
SQL> INSERT INTO t (n, v) VALUES (:n, :v);
SQL> execute :n := 3; :v := ;
SQL> INSERT INTO t (n, v) VALUES (:n, :v);
 
SQL> SELECT sql_id, child_number, executions
2 FROM v$sql
3 WHERE sql_text = ;
SQL_ID CHILD_NUMBER EXECUTIONS
------------- ------------ ----------
6cvmu7dwnvxwj 0 3
There are, however, situations where several child cursors are created even with bind variables.
The following example shows such a case. Notice that the INSERT statement is the same
as in the previous example. Only the maximum size of the VARCHAR2 variable has changed (from
32 to 33).
SQL> variable v VARCHAR2(33)
SQL> execute :n := 4; :v := ;
SQL> INSERT INTO t (n, v) VALUES (:n, :v);
SQL> SELECT sql_id, child_number, executions
2 FROM v$sql
3 WHERE sql_text = ;
SQL_ID CHILD_NUMBER EXECUTIONS
------------- ------------ ----------
6cvmu7dwnvxwj 0 3
6cvmu7dwnvxwj 1 1
The  child cursor (1) is created because the execution environment between the first
three INSERT statements and the fourth has changed. The mismatch, as can be confirmed by
querying the view v$sql_shared_cursor, is because of the bind variables.
SQL> SELECT child_number, bind_mismatch
2 FROM v$sql_shared_cursor
3 WHERE sql_id = ;
CHILD_NUMBER BIND_MISMATCH
------------ -------------
0 N
1 Y
What happens is that the database engine applies the bind variable graduation. The aim of
 feature is to minimize the number of child cursors by graduating bind variables (which
vary in size) into four groups depending on their size. The first group contains the bind variables
with up to 32 bytes, the second contains the bind variables between 33 and 128 bytes,
the third contains the bind variables between 129 and 2,000 bytes, and the last contains the
bind variables of more than 2,000 bytes. Bind variables of datatype NUMBER are graduated
to their maximum length, which is 22 bytes. As the following example shows, the view
v$sql_bind_metadata displays the maximum size of a group. Notice how the value 128 is used,
even  the variable of child cursor 1 was defined as 33.
 
SQL> SELECT s.child_number, m.position, m.max_length,
2 decode(m.datatype,1,,2,,m.datatype) AS datatype
3 FROM v$sql s, v$sql_bind_metadata m
4 WHERE s.sql_id =
5 AND s.child_address = m.address
6 ORDER BY 1, 2;
CHILD_NUMBER POSITION MAX_LENGTH DATATYPE
------------ ---------- ---------- ----------------------------------------
0 1 22 NUMBER
0 2 32 VARCHAR2
1 1 22 NUMBER
1 2 128 VARCHAR2
It goes without saying that each time a  child cursor is created, an execution plan is
generated. Whether   execution plan is equal to the one used by another child cursor
also depends on the value of the bind variables. This is described in the next section.
时间: 2024-07-30 16:00:53

v$sql_shared_cursor中的BIND_MISMATCH的相关文章

故障分析:一则library cache lock问题处理

编辑手记:library cache lock 大家都并不陌生,在MOS上对该阻塞的一般成因描述为:一般可以理解的是alter table或者alter package/procedure会以X模式持有library cache lock,造成阻塞(444560.1).但针对具体问题仍要具体分析,今天分享一则因SQL绑定变量出现空值,导致大量子游标产生并引发library cache lock 的故障,供大家参考借鉴. 请故障现象及影响某数据库为Oracle 11.2.0.3.9 RAC Lin

High Version Count(高版本游标)数目过多诊断的方法

High Version Count(高版本游标)数目过多诊断的方法  什么是high version cursor(高版本游标)? 对于一个特定的游标有多少个版本就属于高版本游标是没有明确定义的.对于不同的系统有不同的数量界定.然而在awr报告中对于一个父游标超过20个子游标个数时就会被报告出来 然而当一个游标的版本数据达到成百上千,那么这些绝对是高版本游标.所以要检查这些sql有高版本的原因要尽量使用这些sql能够被共享. 什么是共享sql? 首先要记住的是所有sql语句都是式共享的.当一个

Oracle: 变量绑定

Parent-Child cursor (父子游标) 父游标:只要SQL语句文本相同,它们就对应 同一个parent cursor. 子游标:在某些情况下,虽然SQL语句的文本相同,但是因为其它 因素不同(这些因素可以在视图V$SQL_SHARED_CURSOR中查看),导致产生不同的child cursor.(重新生成child cursor,也就意味着一次硬解析) cursor_sharing 对 于是否使用绑定变量这个问题,最好是交给应用程序决定,在数据库层面是很难正确判断. (这也是为什

一个执行计划异常变更引发的Oracle性能诊断优化

最近有一个OLTP应用使用的Oracle数据库突然出现性能问题,DBA发现有一些delete语句执行时间骤长,消耗大量系统资源,导致应用响应时间变长积Q.   辅助信息: 应用已经很久未做过更新上线了. 据开发人员反馈,从之前的应用日志看,未出现处理时间逐步变长的现象. 这是一套RAC+DG的环境,11g的版本. 这次突然出现大量执行时间超长的SQL语句,是一条删除语句,delete from table where key1=:1 and key2=:2 and ...(省略此案例不会用到的其

Oracle收集统计信息之NO_INVALIDATE参数

Oracle收集统计信息之NO_INVALIDATE参数 Oracle统计量对于CBO执行是至关重要的.RBO是建立在数据结构的基础上的,DDL结构.约束会将SQL语句分为不同的成本结构等级.而CBO是在数据结构的基础上,加入数据表细粒度信息,将成本结构细化为成本cost值. 相对于数据表的DDL结构,统计量反映了当下数据表数据分布情况,可变性更强.我们经常遇到这样的场景,数据导入操作之后,原有一个运行良好的作业突然效率低下.当我们手工收集一下统计量之后,作业效率提升.这种现象也就是反映了统计量

一个执行计划异常变更的案例 - 外传之rolling invalidation

刚做完一次网络切换支持,得空写一篇,其实今儿取了巧,这篇文章是之前写过的,碰巧又是这次"执行计划异常变更"案例涉及的一个知识点,所以再次翻出来. 之前的几篇文章: <一个执行计划异常变更的案例 - 前传> <一个执行计划异常变更的案例 - 外传之绑定变量窥探> <一个执行计划异常变更的案例 - 外传之查看绑定变量值的几种方法> 做性能测试,有一条SQL,使用了绑定变量,查看V$SQLAREA发现version_count是2, 查看V$SQL,发现有

rolling invalidation对子游标产生的影响

这两天做性能测试碰见一个问题,比较有意思. 一条SQL,使用了绑定变量,查看V$SQLAREA发现version_count是2, 查看V$SQL,发现有两条记录,分别对应了0和1两个child cursor: 再查看这两个child cursor对应的执行计划: child cursor:0 -----------------------------------------------------------------------------------------------------

关于在ASP.NET 中进行调试的方法(转载自itpeople),不过我个人对第三招不以为然,有了v

用过ASP的人对它的调试应该是记忆深刻的.在整片整片的代码中找到那几个出错的地方,难度可想而知.现在微软推出了ASP的更新换代产品ASP.Net.对于ASP.Net的好处,我想很多网站都已经介绍了差不多的,不过对于ASP.Net的调试讲得就不是很多了.所以,我就以我的一点个人经验写了这一篇文章.由于,我也是接触ASP.Net不久,错漏之处在所难免,还请大家多多指正.好了,言归正传. 第一招:配置Config.web     一般,当我们写好的网页运行出错了,ASP.Net就会在页面上告诉我们程序

windows server 2012 中的Hyper V

问题描述 windows server 2012 中的Hyper V windows server 2012 中的Hyper V,断电时虚拟机无故启动不了.怎么解决呢? 解决方案 这个不好说,虚拟机相当于一个独立的计算机,任何软件故障都可能导致无法启动. 重新做一个虚拟机,不安装别的软件看看是否正常. 解决方案二: 问题是没有安装任何软件,是做域控用的.很多时候,断电或者按开机键开机就会无故启动不了.有域账号在,重装严重呀.谢谢你的回答. 解决方案三: 断点可能造成系统损坏了.需要repaire