How to check why identical SQL Statements have high version count

By alejandro.vargas on December 7, 2006 5:37 AM[@more@]

Sometimes we use bind variables, but we see that our statements are not shared, why?

The most common causes are:


Bind Type mismatch

VARIABLE v1 VARCHAR2(60);
VARIABLE v1 VARCHAR2(30);

Language
ALTER SESSION SET NLS_LANGUAGE = 'AMERICAN';
ALTER SESSION SET NLS_LANGUAGE = �GERMAN';

SQL Trace
EXECUTE DBMS_MONITOR.SESSION_TRACE_ENABLE;
ALTER SESSION SET EVENTS '10046 trace name context forever, level 12';

Environmental variables that affect the optimizer
ALTER SESSION SET optimizer_mode = CHOOSE;
ALTER SESSION SET optimizer_mode = FIRST ROWS;

This script check the statements with the top number of versions and check on v$sql_shared_cursor to find the mismatch.

It works on 8i and 9i. v$sql_shared_cursor structure has changed on 10g so needs to be adapted for it.


#!/usr/bin/ksh
# set -x
# chkvercnt
# This script check for high version counts
# Alejandro

. /mysrv/scripts/cshrc/817/.profile
cd /mysrv/scripts/av/freezedb/chkvercnts

ts=`date +%d%m%Y%H%M`
export ts
sid=$1
newsid=`echo $sid | tr '[a-z]' '[A-Z]'`
sqlplus -s sys/$x1@$sid <set pages 100 feed off veri off flush off lines 120
column sql_text for a60

spool $sid.$ts.chkvercnt

prompt * Get the statements with the highests version counts.
prompt

select sql_text,
version_count,
executions,
address
from v$sqlarea where version_count>= (select max(version_count) -5
from v$sqlarea)
order by version_count
/

prompt
prompt * v$sql_shared_cursor - Use the describe to identify the type of mismatch
prompt

describe v$sql_shared_cursor

select *
from v$sql_shared_cursor
where KGLHDPAR =
(select address
from v$sqlarea
where version_count=(select max(version_count)
from v$sqlarea))
/


spool off
exit
eof1
exit
## eof chkvercnt

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

转载于:http://blog.itpub.net/82387/viewspace-1019021/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值