Result Cache 영역
SQL Query Result 캐시 : SQL 쿼리 결과를 저장
PL/SQL 함수 Result 캐시 : PL/SQL 함수 결과값을 저장
Result Cache는 SGA영역에 존재하므로, 모든 세션에서 공유가능하고, 인스턴스를 재기동하면 초기화되며, 해당 쿼리가 접근하는 오브젝트가 변경될 때 invalid된다. 공유영역에 존재하므로 래치가 필요
구분 | 기본값 | 설명 |
---|---|---|
result_cache_mode | ManualResult 캐시 등록 방식을 결정 | Manual:result_cache 힌트를 명시한 SQL만 등록 Force:no_result_cache 힌트를 명시하지 않은 모든 SQL을 등록 |
result_cache_max_size | N/A | SGA내에서 result_cache가 사용할 메모리 총량을 바이트로 지정. 0으로 설정하면 이 기능이 작동하지 않음 |
result_cache_max_result | 5 | 하나의 SQL 결과집합이 전체 캐시 영역에서 차지할 수 있는 최대 크기를 %로 지정 지정 하지 않을 경우. Memory_target : 0.25% result cache 사용 sga_target : 0.5% result cache 사용 Shared_pool_size : manual 으로 사용시 그 값의 1% 사용 |
result_cache_remote_expiration | 0 | remote객체의 결과를 얼마 동안 보관할 지를 분 단위로 지정 Remote 객체는 result 캐시에 저장하지 않도록 하려면 0으로 설정 |
Result Cache에 Caching 못하는 경우.
지금까지 설명한 기능은 서버 측 Result Cache 기능.
클라이언트 측 Result Cache기능은 오라클 매뉴얼 참조
Sample
init.ora parameters
~~~~~~~~~~~~~~~~~~~
RESULT_CACHE_MAX_SIZE=0 --- to disable the server side cache
CLIENT_RESULT_CACHE_SIZE=65536 --- >=32K to enable the client side cache
SQL> show parameter RESULT_CACHE_MAX_SIZE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
result_cache_max_size big integer 0
SQL> show parameter CLIENT_RESULT_CACHE_SIZE;
NAME TYPE VALUE
------------------------------------ ----------- ------------------------------
client_result_cache_size big integer 64K
SQL>
create table table1 (c1 number, c2 varchar2(30))
result_cache (mode default)
/
create table table2 (c1 number, c2 varchar2(30))
result_cache (mode default)
/
begin
for i in 1..5 loop
insert into table1 values (i,'Table 1 - record '||i);
insert into table2 values (i,'Table 2 - record '||i);
end loop;
commit;
end;
/
Client - connect
CACHE_ID STAT_ID NAME TO_CHAR(VALUE)
---------- ---------- ------------------------------ --------------------------------------------------------------------------------
5 1 Block Size 0
5 2 Block Count Max 0
5 3 Block Count Curre 0
5 4 Hash Bucket Count 0
5 5 Create Count Succ 0
5 6 Create Count Fail 0
5 7 Find Count 0
5 8 Invalidation Coun 0
5 9 Delete Count Inva 0
5 10 Delete Count Vali 0
SQL> select /*+ NO_RESULT_CACHE */ t1.c1, t1.c2, t2.c2 from table1 t1, table2 t2 where t1.c1=t2.c1 order by t1.c1
C1 C2 C2
---------- ------------------------------------------------------------ ------------------------------------------------------------
1 Table 1 - record 1 Table 2 - record 1
2 Table 1 - record 2 Table 2 - record 2
3 Table 1 - record 3 Table 2 - record 3
4 Table 1 - record 4 Table 2 - record 4
5 Table 1 - record 5 Table 2 - record 5
1* select CACHE_ID, STAT_ID ,substr(NAME,1,17) name ,to_char(VALUE) from CLIENT_RESULT_CACHE_STATS$
SQL> /
CACHE_ID STAT_ID NAME TO_CHAR(VALUE)
---------- ---------- ------------------------------ --------------------------------------------------------------------------------
6 1 Block Size 0
6 2 Block Count Max 0
6 3 Block Count Curre 0
6 4 Hash Bucket Count 0
6 5 Create Count Succ 0
6 6 Create Count Fail 0
6 7 Find Count 0
6 8 Invalidation Coun 0
6 9 Delete Count Inva 0
6 10 Delete Count Vali 0
SQL> select t1.c1, t1.c2, t2.c2 from table1 t1, table2 t2 where t1.c1=t2.c1 order by t1.c1;
C1 C2 C2
---------- ------------------------------------------------------------ ------------------------------------------------------------
1 Table 1 - record 1 Table 2 - record 1
2 Table 1 - record 2 Table 2 - record 2
3 Table 1 - record 3 Table 2 - record 3
4 Table 1 - record 4 Table 2 - record 4
5 Table 1 - record 5 Table 2 - record 5
CACHE_ID STAT_ID NAME TO_CHAR(VALUE)
---------- ---------- ------------------------------ --------------------------------------------------------------------------------
6 1 Block Size 256
6 2 Block Count Max 256
6 3 Block Count Curre 128
6 4 Hash Bucket Count 1024
6 5 Create Count Succ 0
6 6 Create Count Fail 0
6 7 Find Count 0
6 8 Invalidation Coun 0
6 9 Delete Count Inva 0
6 10 Delete Count Vali 0
SQL> select /*+ RESULT_CACHE */ t1.c1, t1.c2, t2.c2 from table1 t1, table2 t2 where t1.c1=t2.c1 order by t1.c1;
C1 C2 C2
---------- ------------------------------------------------------------ ------------------------------------------------------------
1 Table 1 - record 1 Table 2 - record 1
2 Table 1 - record 2 Table 2 - record 2
3 Table 1 - record 3 Table 2 - record 3
4 Table 1 - record 4 Table 2 - record 4
5 Table 1 - record 5 Table 2 - record 5
CACHE_ID STAT_ID NAME TO_CHAR(VALUE)
---------- ---------- ------------------------------ --------------------------------------------------------------------------------
7 1 Block Size 256
7 2 Block Count Max 256
7 3 Block Count Curre 128
7 4 Hash Bucket Count 1024
7 5 Create Count Succ 1
7 6 Create Count Fail 0
7 7 Find Count 0
7 8 Invalidation Coun 0
7 9 Delete Count Inva 0
7 10 Delete Count Vali 0
select /*+ RESULT_CACHE */ t1.c1, t1.c2, t2.c2
from
table1 t1, table2 t2 where t1.c1=t2.c1 order by t1.c1
call count cpu elapsed disk query current rows
------- ------ -------- ---------- ---------- ---------- ---------- ----------
Parse 5 0.00 0.00 0 0 0 0
Execute 5 0.00 0.05 0 0 2 0
Fetch 10 0.00 0.00 0 70 0 25
------- ------ -------- ---------- ---------- ---------- ---------- ----------
total 20 0.00 0.06 0 70 2 25
Misses in library cache during parse: 0
Optimizer mode: ALL_ROWS
Parsing user id: 43
Number of plan statistics captured: 1
Rows (1st) Rows (avg) Rows (max) Row Source Operation
---------- ---------- ---------- ---------------------------------------------------
5 5 5 SORT ORDER BY (cr=14 pr=0 pw=0 time=983 us cost=8 size=300 card=5)
5 5 5 HASH JOIN (cr=14 pr=0 pw=0 time=914 us cost=7 size=300 card=5)
5 5 5 TABLE ACCESS FULL TABLE1 (cr=7 pr=0 pw=0 time=134 us cost=3 size=150 card=5)
5 5 5 TABLE ACCESS FULL TABLE2 (cr=7 pr=0 pw=0 time=38 us cost=3 size=150 card=5)
Elapsed times include waiting on following events:
Event waited on Times Max. Wait Total Waited
---------------------------------------- Waited ---------- ------------
reliable message 7 0.02 0.05
SQL*Net message to client 10 0.00 0.00
SQL*Net message from client 10 10.75 33.06
asynch descriptor resize 1 0.00 0.00
TABLE1 RESULT_CACHE MODE | TABLE2 RESULT_CACHE MODE | RESULT_CACHE_MODE | HINT/NO_HINT | CACHE/NO_CACHE |
---|---|---|---|---|
DEFAULT | DEFAULT | MANUAL | NO HINT | NO_CACHE |
DEFAULT | FORCE | MANUAL | NO HINT | NO_CACHE |
FORCE | FORCE | MANUAL | NO HINT | CACHE |
DEFAULT | DEFAULT | FORCE | NO HINT | CACHE |
DEFAULT | FORCE | FORCE | NO HINT | CACHE |
DEFAULT | DEFAULT | MANUAL | RESULT_CACHE HINT | CACHE |
DEFAULT | FORCE | MANUAL | RESULT_CACHE HINT | CACHE |
FORCE | FORCE | MANUAL | NO_RESULT_CACHE HINT | NO_CACHE |
FORCE | FORCE | FORCE | NO_RESULT_CACHE HINT | NO_CACHE |