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.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7728585/viewspace-686324/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/7728585/viewspace-686324/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值