INDEX 관련하여 질문올립니다.
조회하고자하는 테이블은 하나입니다.
옵티마이저는 CBO(ALL_ROWS)입니다.
데이터딕셔너리
[옵티마이저 정보]
------------------------------------ ----------- ------------------------------
optimizer_capture_sql_plan_baselines boolean FALSE
optimizer_dynamic_sampling integer 2
optimizer_features_enable string 11.2.0.3
optimizer_index_caching integer 0
optimizer_index_cost_adj integer 100
optimizer_mode string ALL_ROWS
optimizer_secure_view_merging boolean TRUE
optimizer_use_invisible_indexes boolean FALSE
optimizer_use_pending_statistics boolean FALSE
optimizer_use_sql_plan_baselines boolean TRUE
데이터딕션너리의 모든 칼럼을 조회하니 지저분하네요.
utraedit에 copy해서 보심 잘보이는데ㅜㅜ;;
[테이블 정보]
OWNER |TABLE_NAME |TABLESPACE_NAME |CLUSTER_NAME |IOT_NAME |STATUS | PCT_FREE| PCT_USED| INI_TRANS| MAX_TRANS|INITIAL_EXTENT|NEXT_EXTENT|MIN_EXTENTS|MAX_EXTENTS|PCT_INCREASE| FREELISTS|FREELIST_GROUPS|LOG|B| NUM_ROWS| BLOCKS|EMPTY_BLOCKS| AVG_SPACE| CHAIN_CNT|AVG_ROW_LEN|AVG_SPACE_FREELIST_BLOCKS|NUM_FREELIST_BLOCKS|DEGREE |INSTANCES |CACHE |TABLE_LO|SAMPLE_SIZE|LAST_ANALYZE|PAR|IOT_TYPE |T|S|NES|BUFFER_|FLASH_C|CELL_FL|ROW_MOVE|GLO|USE|DURATION |SKIP_COR|MON|CLUSTER_OWNER |DEPENDEN|COMPRESS|COMPRESS_FOR|DRO|REA|SEG|RESULT_
--------------------|------------------------------|------------------------------|------------------------------|------------------------------|--------|----------|----------|----------|----------|--------------|-----------|-----------|-----------|------------|----------|---------------|---|-|----------|----------|------------|----------|----------|-----------|-------------------------|-------------------|--------------------|--------------------|----------|--------|-----------|------------|---|------------|-|-|---|-------|-------|-------|--------|---|---|---------------|--------|---|------------------------------|--------|--------|------------|---|---|---|-------
OPS$PKTIBG2 |FTIOIR |KTI2_USER | | |VALID | 10| | 1| 255| 163840| 1048576| 1| 2147483645| | | |NO |N| 380680| 19356| 0| 0| 0| 1538| 0| 0| 1 | 1 | N |ENABLED | 38068|23-JUN-13 |NO | |N|N|NO |DEFAULT|DEFAULT|DEFAULT|DISABLED|YES|NO | |DISABLED|YES| |DISABLED|DISABLED| |NO |NO |YES|DEFAULT
[INDEX 정보]
OWNER |INDEX_NAME |INDEX_TYPE |TABLE_OWNER |TABLE_NAME |TABLE|UNIQUENES|COMPRESS|PREFIX_LENGTH|TABLESPACE_NAME | INI_TRANS| MAX_TRANS|INITIAL_EXTENT|NEXT_EXTENT|MIN_EXTENTS|MAX_EXTENTS|PCT_INCREASE|PCT_THRESHOLD|INCLUDE_COLUMN| FREELISTS|FREELIST_GROUPS| PCT_FREE|LOG| BLEVEL|LEAF_BLOCKS|DISTINCT_KEYS|AVG_LEAF_BLOCKS_PER_KEY|AVG_DATA_BLOCKS_PER_KEY|CLUSTERING_FACTOR|STATUS | NUM_ROWS|SAMPLE_SIZE|LAST_ANALYZE|DEGREE |INSTANCES |PAR|T|G|S|BUFFER_|FLASH_C|CELL_FL|USE|DURATION |PCT_DIRECT_ACCESS|ITYP_OWNER |ITYP_NAME |PARAMETERS |GLO|DOMIDX_STATU|DOMIDX|FUNCIDX_|JOI|IOT|DRO|VISIBILIT|DOMIDX_MANAGEM|SEG
--------------------|------------------------------|---------------------------|--------------------|------------------------------|-----|---------|--------|-------------|------------------------------|----------|----------|--------------|-----------|-----------|-----------|------------|-------------|--------------|----------|---------------|----------|---|----------|-----------|-------------|-----------------------|-----------------------|-----------------|--------|----------|-----------|------------|----------------------------------------|----------------------------------------|---|-|-|-|-------|-------|-------|---|---------------|-----------------|------------------------------|------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|------------|------|--------|---|---|---|---------|--------------|---
OPS$PKTIBG2 |IDX_FTIOIR_02 |NORMAL |OPS$PKTIBG2 |FTIOIR |TABLE|NONUNIQUE|DISABLED| |KTI2_IND | 2| 255| 163840| 1048576| 1| 2147483645| | | | | | 10|NO | 1| 710| 53421| 1| 3| 193171|VALID | 376591| 376591|23-JUN-13 |1 |1 |NO |N|N|N|DEFAULT|DEFAULT|DEFAULT|NO | | | | | |YES| | | |NO |NO |NO |VISIBLE | |YES
[INDEX 칼럼정보]
INDEX_OWNER |INDEX_NAME |TABLE_OWNER |TABLE_NAME |COLUMN_NAME |COLUMN_POSITION|COLUMN_LENGTH|CHAR_LENGTH|DESC
--------------------|------------------------------|--------------------|------------------------------|------------------------------|---------------|-------------|-----------|----
OPS$PKTIBG2 |IDX_FTIOIR_02 |OPS$PKTIBG2 |FTIOIR |REMT_PROC_DATE | 1| 8| 8|ASC
OPS$PKTIBG2 |IDX_FTIOIR_02 |OPS$PKTIBG2 |FTIOIR |BRN_NO | 2| 3| 3|ASC
OPS$PKTIBG2 |IDX_FTIOIR_02 |OPS$PKTIBG2 |FTIOIR |INST_NO | 3| 3| 3|ASC
between을 이용하여 아래와 같이 조회한경우 INDEX RANGE SCAN을 합니다.
SQL> SELECT
2 count(*)
3 FROM FTIOIR
4 WHERE REMT_PROC_DATE BETWEEN '20120616' AND '20130715';
Execution Plan
----------------------------------------------------------
Plan hash value: 3219804720
-----------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 9 | 4 (0)| 00:00:01 |
| 1 | SORT AGGREGATE | | 1 | 9 | | |
|* 2 | INDEX RANGE SCAN| IDX_FTIOIR_02 | 520 | 4680 | 4 (0)| 00:00:01 |
-----------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - access("REMT_PROC_DATE">='20120616' AND
"REMT_PROC_DATE"<='20130715')
Statistics
----------------------------------------------------------
0 recursive calls
0 db block gets
5 consistent gets
0 physical reads
0 redo size
527 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
SQL>
그러나 아래와 같이 INDEX 정보외에 필터링 정보를 추가할경우 INDEX를 타지않고
TABLE FULL SCAN을 합니다.
SQL> SELECT
2 count(*)
3 FROM FTIOIR
4 WHERE REMT_PROC_DATE BETWEEN '20120616' AND '20130715'
5 AND REMT_TYPE = 'O';
Elapsed: 00:00:01.17
Execution Plan
----------------------------------------------------------
Plan hash value: 48264840
-----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | 11 | 9236 (4)| 00:02:47 |
| 1 | SORT AGGREGATE | | 1 | 11 | | |
|* 2 | TABLE ACCESS FULL| FTIOIR | 38388 | 412K| 9236 (4)| 00:02:47 |
-----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
2 - filter("REMT_PROC_DATE">='20120616' AND "REMT_TYPE"='O' AND
"REMT_PROC_DATE"<='20130715')
Statistics
----------------------------------------------------------
1 recursive calls
1 db block gets
19616 consistent gets
19611 physical reads
0 redo size
528 bytes sent via SQL*Net to client
520 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
1 rows processed
또 아래 처럼 BETWEEN 조회 내용을 COUNT(*)에서 *로 변경할경우 TABLE full scan을 합니다.
SQL> SELECT
2 *
3 FROM FTIOIR
4 WHERE REMT_PROC_DATE BETWEEN '20120616' AND '20130715';
78976 rows selected.
Elapsed: 00:00:14.74
Execution Plan
----------------------------------------------------------
Plan hash value: 85254115
----------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 76777 | 112M| 9259 (4)| 00:02:47 |
|* 1 | TABLE ACCESS FULL| FTIOIR | 76777 | 112M| 9259 (4)| 00:02:47 |
----------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter("REMT_PROC_DATE">='20120616' AND
"REMT_PROC_DATE"<='20130715')
Statistics
----------------------------------------------------------
213 recursive calls
1 db block gets
24757 consistent gets
19611 physical reads
0 redo size
65754035 bytes sent via SQL*Net to client
58435 bytes received via SQL*Net from client
5267 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
78976 rows processed
아래 2개의 SQL TABLE full scan하는 이유를 알고 싶습니다.
많은 고수님의 조언부탁드립니다. (between이 무조건 index 안 태운다는 내용은 말고 ㅡㅡㅋ) |