/*
Bind Value
:B1 KR <-- Case1
:B1 NULL <-- Case2
*/
SQL> SELECT *
FROM T1
WHERE C3 LIKE :B1||'%';
Case1> 인덱스 경유(X)
SQL> SELECT 1
FROM DUAL
WHERE INDEX_FILD LIKE '%DD%';
Case2> 인덱스 경유(O)
SQL> SELECT 1
FROM DUAL
WHERE INDEX_FILD LIKE 'DD%';
Case3> 인덱스 경유(X)
SQL> SELECT 1
FROM DUAL
WHERE INDEX_FILD LIKE '%DD';
SQL> SELECT *
FROM NULL_T
WHERE C3 LIKE :B1 || '%';
Call Count CPU Time Elapsed Time Disk Query Current Rows
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Parse 1 0.000 0.000 0 0 0 0
Execute 1 0.000 0.007 0 73 0 0
Fetch 2 0.000 0.001 2 6 0 3
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Total 4 0.000 0.008 2 79 0 3
Misses in library cache during parse: 1
Optimizer goal: ALL_ROWS
Parsing user: APPS (ID=44)
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
3 TABLE ACCESS BY INDEX ROWID NULL_T (cr=6 pr=2 pw=0 time=739 us cost=31 size=1386 card=33)
3 INDEX RANGE SCAN NULL_T_IDX_03 (cr=3 pr=2 pw=0 time=719 us cost=2 size=0 card=33)(Object ID 127363930)
- NULL_T_IDX_03 인덱스 경유
SQL> SELECT *
FROM NULL_T
WHERE C3 LIKE :B1 ||'%';
Call Count CPU Time Elapsed Time Disk Query Current Rows
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Parse 1 0.010 0.011 0 73 0 0
Execute 1 0.000 0.000 0 0 0 0
Fetch 9001 0.030 0.265 369 9429 0 90000
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Total 9003 0.040 0.276 369 9502 0 90000
Misses in library cache during parse: 1
Optimizer goal: ALL_ROWS
Parsing user: APPS (ID=44)
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
90000 TABLE ACCESS FULL NULL_T (cr=9429 pr=369 pw=0 time=47205 us cost=122 size=3885462 card=92511)
-- FULL Table Scan(전체 Rows 가져 옴)
-- Join시 Drivig으로 잡히게 되면 심각한 성능 부하
-- :B1 IS NULL
SQL> SELECT *
FROM (SELECT *
FROM NULL_T
WHERE C3 = NVL(:B1,C3));
Call Count CPU Time Elapsed Time Disk Query Current Rows
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Parse 1 0.000 0.000 0 0 0 0
Execute 1 0.000 0.022 0 219 0 0
Fetch 9001 0.010 0.239 0 9429 0 90000
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Total 9003 0.010 0.261 0 9648 0 90000
Misses in library cache during parse: 0
Misses in library cache during execute: 1
Optimizer goal: ALL_ROWS
Parsing user: APPS (ID=44)
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
90000 CONCATENATION (cr=9429 pr=0 pw=0 time=91791 us)
90000 FILTER (cr=9429 pr=0 pw=0 time=63108 us)
90000 TABLE ACCESS FULL NULL_T (cr=9429 pr=0 pw=0 time=29691 us cost=120 size=3885462 card=92511)
0 FILTER (cr=0 pr=0 pw=0 time=4 us)
0 TABLE ACCESS BY INDEX ROWID NULL_T (cr=0 pr=0 pw=0 time=0 us cost=118 size=43176 card=1028)
0 INDEX RANGE SCAN NULL_T_IDX_03 (cr=0 pr=0 pw=0 time=0 us cost=1 size=0 card=141)(Object ID 127363930)
-- 옵티마이져는 두개의 실행계획으로 풀게 된다.(C3 IS NOT NULL, C3 = :B1)
-- :B1 IS NULL
SQL> SELECT *
FROM NULL_T
WHERE C3 = DECODE(:B1, NULL, C3, :B1);
Call Count CPU Time Elapsed Time Disk Query Current Rows
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Parse 1 0.000 0.000 0 0 0 0
Execute 1 0.010 0.017 0 219 0 0
Fetch 9001 0.030 0.272 265 9429 0 90000
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Total 9003 0.040 0.289 265 9648 0 90000
Misses in library cache during parse: 1
Optimizer goal: ALL_ROWS
Parsing user: APPS (ID=44)
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
90000 CONCATENATION (cr=9429 pr=265 pw=0 time=88368 us)
90000 FILTER (cr=9429 pr=265 pw=0 time=60199 us)
90000 TABLE ACCESS FULL NULL_T (cr=9429 pr=265 pw=0 time=29599 us cost=120 size=3885462 card=92511)
0 FILTER (cr=0 pr=0 pw=0 time=4 us)
0 TABLE ACCESS BY INDEX ROWID NULL_T (cr=0 pr=0 pw=0 time=0 us cost=118 size=43176 card=1028)
0 INDEX RANGE SCAN NULL_T_IDX_03 (cr=0 pr=0 pw=0 time=0 us cost=1 size=0 card=141)(Object ID 127363930)
-- 옵티마이져는 두개의 실행계획으로 풀게 된다.(C3 IS NOT NULL, C3 = :B1)
예제>
SQL> SELECT *
FROM NULL_T
WHERE C3 IS NULL;
Call Count CPU Time Elapsed Time Disk Query Current Rows
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Parse 1 0.010 0.010 0 73 2 0
Execute 1 0.000 0.000 0 0 0 0
Fetch 1001 0.010 0.063 194 1435 0 10000
------- ------ -------- ------------ ---------- ---------- ---------- ----------
Total 1003 0.020 0.073 194 1508 2 10000
Misses in library cache during parse: 1
Optimizer goal: ALL_ROWS
Parsing user: APPS (ID=44)
Rows Row Source Operation
------- ---------------------------------------------------
0 STATEMENT
10000 TABLE ACCESS FULL NULL_T (cr=1435 pr=194 pw=0 time=192850 us cost=121 size=432138 card=10289)
교재참조