统计没有使用绑定变量的sql语句(二)
RE
-------------------------------------------------------------------------------- ------------------------ ------------------------
select /*mystatement*/ * from tb_force where id=:"SYS_B_0" 1.30958144015941E19 1.30958144015941E19
--当我们把cursor_sharing设置为force后,发现语句执行计划共用了,并且自动使用绑定变量(此时v$sql视图中只查询到一条与之相关的语句)。
--通过上面的实验,我们发现查找
系统中有哪些语句未使用绑定变量,可根据FORCE_MATCHING_SIGNATURE实现。
--下面我们就通过FORCE_MATCHING_SIGNATURE来查找系统中未使用绑定变量的语句...
select to_char(FORCE_MATCHING_SIGNATURE) as FORCE_MATCHING_SIGNATURE, count(1) as counts
from v$sql
where FORCE_MATCHING_SIGNATURE>0 and FORCE_MATCHING_SIGNATURE <> EXACT_MATCHING_SIGNATURE
group by FORCE_MATCHING_SIGNATURE
having count(1) > &a
order by 2 desc;
--通过上面查询出来的FORCE_MATCHING_SIGNATURE值,来查找sql语句
select t.* from v$sql t where FORCE_MATCHING_SIGNATURE=16456394970215993993;
--延伸:
cursor_sharing有三个可选参数:EXACT、SIMILAR、FORCE。
--语句完全一样,则利用share pool中的语句,反之则重新生成(默认)。
EXACT:Only allows statements with identical text to share the same cursor.
--语句相似,但系统自行判断是否利用share pool中的语句(不推荐,bug很多)。
SIMILAR:Causes statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect either the meaning of the statement or
the degree to which the plan is optimized.
--语句相似,系统强制利用share pool中的语句(不推荐,bug较多)。
FORCE:Forces statements that may differ in some literals, but are otherwise identical, to share a cursor, unless the literals affect the meaning of the statement.