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 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.
相关文章
|
6月前
|
SQL IDE Java
Java连接SQL Server数据库的详细操作流程
Java连接SQL Server数据库的详细操作流程
|
3月前
|
关系型数据库 MySQL 网络安全
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
5-10Can't connect to MySQL server on 'sh-cynosl-grp-fcs50xoa.sql.tencentcdb.com' (110)")
|
5月前
|
SQL 存储 监控
SQL Server的并行实施如何优化?
【7月更文挑战第23天】SQL Server的并行实施如何优化?
129 13
|
5月前
|
SQL
解锁 SQL Server 2022的时间序列数据功能
【7月更文挑战第14天】要解锁SQL Server 2022的时间序列数据功能,可使用`generate_series`函数生成整数序列,例如:`SELECT value FROM generate_series(1, 10)。此外,`date_bucket`函数能按指定间隔(如周)对日期时间值分组,这些工具结合窗口函数和其他时间日期函数,能高效处理和分析时间序列数据。更多信息请参考官方文档和技术资料。
|
5月前
|
SQL 存储 网络安全
关系数据库SQLserver 安装 SQL Server
【7月更文挑战第26天】
69 6
|
5月前
|
存储 SQL C++
对比 SQL Server中的VARCHAR(max) 与VARCHAR(n) 数据类型
【7月更文挑战7天】SQL Server 中的 VARCHAR(max) vs VARCHAR(n): - VARCHAR(n) 存储最多 n 个字符(1-8000),适合短文本。 - VARCHAR(max) 可存储约 21 亿个字符,适合大量文本。 - VARCHAR(n) 在处理小数据时性能更好,空间固定。 - VARCHAR(max) 对于大文本更合适,但可能影响性能。 - 选择取决于数据长度预期和业务需求。
448 1
|
5月前
|
SQL Oracle 关系型数据库
MySQL、SQL Server和Oracle数据库安装部署教程
数据库的安装部署教程因不同的数据库管理系统(DBMS)而异,以下将以MySQL、SQL Server和Oracle为例,分别概述其安装部署的基本步骤。请注意,由于软件版本和操作系统的不同,具体步骤可能会有所变化。
367 3
|
4月前
|
SQL 安全 Java
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
驱动程序无法通过使用安全套接字层(SSL)加密与 SQL Server 建立安全连接。错误:“The server selected protocol version TLS10 is not accepted by client
528 0
|
5月前
|
SQL 存储 安全
数据库数据恢复—SQL Server数据库出现逻辑错误的数据恢复案例
SQL Server数据库数据恢复环境: 某品牌服务器存储中有两组raid5磁盘阵列。操作系统层面跑着SQL Server数据库,SQL Server数据库存放在D盘分区中。 SQL Server数据库故障: 存放SQL Server数据库的D盘分区容量不足,管理员在E盘中生成了一个.ndf的文件并且将数据库路径指向E盘继续使用。数据库继续运行一段时间后出现故障并报错,连接失效,SqlServer数据库无法附加查询。管理员多次尝试恢复数据库数据但是没有成功。
|
5月前
|
SQL 存储 关系型数据库
关系型数据库SQL Server学习
【7月更文挑战第4天】
84 2