Oracle 매개 변수의 cursorsharing
7028 단어 Oracle
실험 용 표 세 장 만 들 기: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 을 무조건 재 활용 합 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Oracle 생성 향후 3일간의 전체 시점 (단계 상세)수요: X 좌표축 시간은 모두 정시 시간으로 앞으로 3일 동안의 예측을 보여준다(x 축은 앞으로 3일 동안의 정시 시간을 보여준다), 3시간마다 한 눈금, 가로 좌표는 모두 24개의 눈금을 보여준다 1단계: 현재 시...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.