oracle literal 传参数,a-better-way-to-find-literal-sqls-in-oracle-10g/

Not sure if it is news, but here we go …

I was recently looking at hard parsing SQLstatements overtaking one of my systems and needed to find literal SQLs that caused the problem.

The traditional way to look for literal SQLs in ORACLE(at least as it was for me) is to search for statements that are exactly the same in the first N symbols, something like:

SELECT substr(sql_text, 1, 80), COUNT(1)

FROM v$sql

GROUP BY substr(sql_text, 1, 80)

HAVING COUNT(1) > 10

ORDER BY 2

/

As you can see, this search is not very precise – i.e. what value of N should you choose to be certain that you found ALL“duplicated” SQLs that are only different in literals ?

It turns out that ORACLE 10g introduced a couple of new columns in v$sql view (as well as some related views) that can help pinpoint literal SQLs more precisely. The two new columns are: force_matching_signature andexact_matching_signature.

The same value in exact_matching_signature column marks SQLs that ORACLEconsiders the same after making some cosmetic adjustments to it (removing white space, uppercasing all keywords etc). As the name implies, this is what happens when parameter cursor_sharing is set to EXACT.

Consequently, the same value in force_matching_signature (excluding 0) marks SQLs that ORACLEwill consider the same when it replaces all literals with binds (that is, if cursor_sharing=FORCE).

Obviously, if we have multiple SQLs that produce the same force_matching_signature we have a strong case for literal laden SQLthat needs to undergo our further scrutiny. Of course, we need to remember to filter out SQLs where force_matching_signature = exact_matching_signature as these do NOThave any literals (however, if we have many of those – this can become interesting as well – why do we have many versions of the same “non literal” SQL ?)

Anyway, here is a slightly better version of literal SQLfinder in ORACLE 10g:

SELECT force_matching_signature, COUNT(1)

FROM v$sql

WHERE force_matching_signature > 0

AND force_matching_signature <> exact_matching_signature

GROUP BY force_matching_signature

HAVING COUNT(1) > 10

ORDER BY 2

/

Special thanks to Rostyslav Polishchuck who pointed me originally in this direction.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值