Oracle 매개 변수의 cursorsharing

7028 단어 Oracle
1. Cursorsharing 프로필: 이 매개 변 수 는 Oracle 이 어떤 상황 에서 커서, 즉 SQL 재 활용 을 공유 할 수 있 는 지 알려 주 는 데 사 용 됩 니 다.Cursor_sharing 매개 변 수 는 3 개의 값 을 설정 할 수 있 습 니 다. 1) EXACT: 일반적으로 exact 값 은 Oracle 이 추천 하 는 것 이자 기본 적 인 것 입 니 다. SQL 문 구 는 똑 같 을 때 다시 사용 해 야 합 니 다. 그렇지 않 으 면 하 드 해석 작업 을 다시 수행 할 수 있 습 니 다.2), SIMILAR: similar 는 Oracle 이 특정한 SQL 문장의 서술 어 조건 이 실행 계획 에 영향 을 줄 수 있다 고 생각 할 때 재 분석 되 고 그렇지 않 으 면 SQL 을 다시 사용 합 니 다.3) FORCE: force 는 어떠한 상황 에서 도 SQL 을 무조건 다시 사용 합 니 다.4) 、 오 라 클 12c 버 전 이후 에는 SIMILAR 로 설정 하 는 것 을 권장 하지 않 습 니 다.매 뉴 얼 은 이미 이 인 자 를 폐기 했다.비고: 위 에서 말 한 SQL 재 활용 은 서술 어 조건 이 다른 SQL 문 구 를 말 합 니 다. 실제로 이러한 SQL 은 기본적으로 같은 업무 수행 을 하고 있 습 니 다.2. Cursor 에서sharing 매개 변수 값 이 다 를 때 SQL 에 미 치 는 영향: 2.1 실험 환경 만 들 기: 11G: 기본 표를 만 들 고 데 이 터 를 입력 합 니 다.SYS@orcl> create table test (id number,name varchar2(10));SYS@orcl> insert into test values (1,'aa');SYS@orcl> insert into test values (2,'bb');SYS@orcl> insert into test values (3,'cc');SYS@orcl> commit;
실험 용 표 세 장 만 들 기:SYS@orcl> create table test_exact as select from test;SYS@orcl> create table test_similar as select from test;SYS@orcl> create table test_force as select * from test;
설정 추적traceSYS@orcl> oradebug setmypidSYS@orcl> oradebug tracefile_name
테스트 exact:SYS@orcl> alter session set cursor_sharing=exact;SYS@orcl> alter session set sql_trace=true;SYS@orcl> select * from test_exact where id=1;ID NAME
     1 aa

SYS@orcl> select * from test_exact where id=2;
    ID NAME
     2 bb

SYS@orcl> select * from test_exact where id=3;
    ID NAME
     3 cc

SYS@orcl> alter session set sql_trace=false;
trace 파일 관찰:SYS@orcl> select sql_text from v$sql where sql_text like 'select * from test_ex%';SQL_TEXT
select from test_exact where id=2select from test_exact where id=3select * from test_exact where id=1
[oracle@orcl ~]$ tkprof /u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_2849.trc out.txt aggregate=no
SQL ID: 22cdhbrvt2nmwPlan Hash: 3210958934select *fromtest_exact where id=1call count cpu elapsed disk query current rows
Parse 1 0.00 0.01 2 2 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 2 0.00 0.00 0 4 0 1
total 4 0.00 0.01 2 6 0 1
Misses in library cache during parse: 1 -- 하 드 해석 1 회 Optimizer mode: ALLROWSParsing user id: SYS
SQL ID: f9kq2n9utcww7Plan Hash: 3210958934select *fromtest_exact where id=2call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 1 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 2 0.00 0.00 0 4 0 1
total 4 0.00 0.00 0 5 0 1
Misses in library cache during parse: 1 -- 하 드 해석 1 회 Optimizer mode: ALLROWSParsing user id: SYS
SQL ID: 22cdhbrvt2nmwPlan Hash: 3210958934select *fromtest_exact where id=1call count cpu elapsed disk query current rows
Parse 1 0.00 0.00 0 0 0 0Execute 1 0.00 0.00 0 0 0 0Fetch 2 0.00 0.00 0 4 0 1
parse 동안 라 이브 러 리 캐 시 에 있 는 1 개의 misses: 0 -- 소프트 해석 최적화 모드: ALLROWSParsing user id: SYS 요약: 커서sharing = exact 시 SQL 문장 이 똑 같은 경우 에 만 재 활용 할 수 있 습 니 다.
테스트 SIMILAR:
SYS@orcl> oradebug setmypidSYS@orcl> oradebug tracefile_nameSYS@orcl> alter session set cursor_sharing=similar;SYS@orcl> alter session set sql_trace=true;SYS@orcl> select * from test_similar where id=1;ID NAME
     1 aa

SYS@orcl> select * from test_similar where id=2;ID NAME
     2 bb

SYS@orcl> select from test_similar where id=10;no rows selectedSYS@orcl> select sql_text from v$sql where sql_text like 'select from test_similar where%';SQL_TEXT
select from test_similar where id=:"SYS_B_0"select from test_similar where id=:"SYS_B_0"select * from test_similar where id=:"SYS_B_0"SYS@orcl> alter session set sql_trace=false;
trace 파일 분석: SQL ID: 6wvc0ymwz50uqPlan Hash: 3269012161select * from testsimilar where id=:"SYS_B_0"
call count cpu elapsed disk query current rows
Parse 3 0.00 0.00 1 1 0 0Execute 3 0.00 0.00 1 3 0 0Fetch 5 0.00 0.00 0 11 0 2
total 11 0.00 0.00 2 15 0 2
Misses in library cache during parse: 3 -- 하 드 해석 3 회 실행 Optimizer mode: ALLROWSParsing user id: SYS
SIMILAR 의 경우 CBO 에서 연 결 된 변수의 술어 가 다른 실행 계획 이 있 는 것 을 발견 하면 술어 조건 의 값 이 변 하면 이전 SQL 을 다시 사용 하 는 것 이 아니 라 새로운 하위 커서 가 생 길 수 있 습 니 다.술어 가 다른 실행 계획 이 없 으 면 술어 의 값 을 무시 하고 이전의 SQL 을 다시 사용 합 니 다.
추가 테스트:
SYS@orcl> alter system flush shared_pool;SYS@orcl> alter system flush buffer_cache;SYS@orcl> insert into test_similar values (1,'abc');SYS@orcl> commit;SYS@orcl> create index ind_test_similar on test_similar(id);SYS@orcl> exec dbms_stats.gather_table_stats(user,'test_similar',cascade=>true);SYS@orcl> alter session set cursor_sharing=similar;SYS@orcl> alter session set sql_trace=true;SYS@orcl> select * from test_similar where id=1 and name='aa';ID NAME
     1 aa

SYS@orcl> select * from test_similar where id=1 and name='abc';ID NAME
     1 abc

SYS@orcl> alter session set sql_trace=false;SYS@orcl> select sql_text from v$sql where sql_text like 'select * from test_similar where%';SQL_TEXT
select * from test_similar where id=:"SYS_B_0" and name=:"SYS_B_1
추적 보기: SQL ID: 23gux1agm4fntPlan Hash: 3269012161select * fromtest similar where id =: "SYSB_0" and name=:"SYS_B_1"
call count cpu elapsed disk query current rows
Parse 2 0.00 0.00 0 0 0 0Execute 2 0.00 0.00 0 0 0 0Fetch 4 0.00 0.00 0 9 0 2
total 8 0.00 0.00 0 9 0 2
misses in library cache during parse: 1 -- 하 드 해석 1 회 최적화 모드: ALL ROWSParsing user id: SYS
테스트 FORCE:SYS@orcl> oradebug setmypidSYS@orcl> oradebug tracefile_name/u01/app/oracle/diag/rdbms/orcl/orcl/trace/orcl_ora_4104.trcSYS@orcl> alter session set cursor_sharing=force;SYS@orcl> alter session set sql_trace=true;SYS@orcl> select * from test_force where id=1;ID NAME
     1 aa

SYS@orcl> select * from test_force where id=2;ID NAME
     2 bb

SYS@orcl> select * from test_force where id=1;ID NAME
     1 aa

SYS@orcl> alter session set sql_trace=false;SYS@orcl> select sql_text from v$sql where sql_text like 'select * from test_force where%';SQL_TEXT
select * from test_force where id=:"SYS_B_0"
추적 보기: SQL ID: 5my70999m011jPlan Hash: 1419416768 select * from test force where id =: "SYSB_0"
call count cpu elapsed disk query current rows
Parse 3 0.00 0.00 1 1 0 0Execute 3 0.00 0.00 1 1 0 0Fetch 6 0.00 0.00 0 12 0 3
total 12 0.00 0.00 2 14 0 3
Misses in library cache during parse: 1Optimizer mode: ALL ROWSParsing user id: SYS 요약: force 는 어떠한 상황 에서 도 SQL 을 무조건 재 활용 합 니 다.

좋은 웹페이지 즐겨찾기