본문 바로가기

ORACLE

Not in과 not exist, outter join, SQL의 hit ratio보기

Select ... from Emp where dept_no not in (select dept_no from dept where

dept_cat='a');


보다는 아래와 같이 변경


case 1


select ...

from emp a, dept b

where a.dept_no = b.dept_no(+)

and b.dept_no is null

and b.dept_cat(+) = 'a'



case 2


select ...

from emp e

where not exits (select '1' from dept d

where d.dept_no = e.dept_no

and d.dept_cat='a');




case1보다는 case2가 좀 더 나은 결과를 보여준다고 한다 -_-


(확인 안 해봄..--;)


SQL의 hit Ratio 확인

select executions,disk_reads,buffer_gets

round((buffer_gets-disk_reads) / buffer_gets,2) hit_ratio,

round(disk_reads/executions,2) reads_per_run,

sql_text

from v$sqlarea

where executions > 0

and buffer_gets > 0

and (buffer_gets - disk_reads) / buffer_gets < 0.80

order by 4 desc;



권장치 90%


미만일 경우 버퍼캐쉬의 크기가 너무 적거나 또는 지나치게 많은 I/O를 유발하는 어플리케이션이 존재한다는 것이다.



trace뜨기..

1.init.ora에 지정

sql_trace = true

time_statistics = true 에 파라메터 추가 후 데이터베이스를 다시 startup



2.session단위

SQL>Alter session set sql_trace=true;

SQL>SQL실행

SQL>exit


이렇게 하면 user_dump_dest 디렉토리에 트레이스 파일이 생성된다.

user_dump_dest가 어디인지 확인방법

SQL>select value from v$parameter where name='user_dump_dest';


##Trace파일 변환##

ora_xxxx.trc파일

해당 user에 plan_table이 없으면 utlxplan.sql을 실행하여 table을 만든다


tkprof ora_xxx.trc resutl.out sort=fchqry,fchcu explain=scott/tiger print=20