SQL> create table t as\\
2 select 'Y' processed_flag, a.\* from all_objects a;
테이블이 생성되었습니다.
경 과: 00:00:03.57
SQL> set timing on
SQL> set timing off
SQL> create or replace view v
2 as
3 select t.*,
4 case when processed_flag = 'N' then 'N'
5 else NULL
6 end processed_flag_indexed
7 from t;
뷰가 생성되었습니다.
SQL> create index t_idx on
2 t( case when processed_flag = 'N' then 'N'
3 else NULL
4 end );
인덱스가 생성되었습니다.
SQL> \-- Before updating data 'N' in 100 rows
SQL> select name,del_lf_rows,lf_rows,lf_blks from index_stats;*
NAME DEL_LF_ROWS LF_ROWS LF_BLKS*
\-----------------------------\- \----------\- \---------\- \---------\-*
T_IDX 0 0 1*
SQL> update t set processed_flag='N' where rownum <= 100;
100 행이 갱신되었습니다.
SQL> commit;
커밋이 완료되었습니다.
SQL> analyze index t_idx validate structure;
인덱스가 분석되었습니다.
SQL> \-\- After updating data 'N' in 100 rows*
SQL> select name,del_lf_rows,lf_rows,lf_blks from index_stats;*
NAME DEL_LF_ROWS LF_ROWS LF_BLKS*
\-----------------------------\- \----------\- \---------\- \---------\-*
T_IDX 0 100 1*
SQL> update t set processed_flag='Y' where rownum <= 2;
2 행이 갱신되었습니다.
SQL> commit;
커밋이 완료되었습니다.
SQL> analyze index t_idx validate structure;
인덱스가 분석되었습니다.
SQL> select name,del_lf_rows,lf_rows,lf_blks from index_stats;
NAME DEL_LF_ROWS LF_ROWS LF_BLKS
\-----------------------------\- \----------\- \---------\- \---------\-
T_IDX *2* 100 1
SQL> create table project
2 (project_ID number primary key,
3 teamid number,
4 job varchar2(100),
5 status varchar2(20) check (status in ('ACTIVE', 'INACTIVE'))
6 );
Table created.
SQL> create UNIQUE index
2 job_unique_in_teamid on project
3 ( case when status = 'ACTIVE' then teamid else null end,
4 case when status = 'ACTIVE' then job else null end
5 )
6 /
Index created.
SQL> insert into project(project_id,teamid,job,status)
2 values( 1, 10, 'a', 'ACTIVE' );
1 row created.
SQL> insert into project(project_id,teamid,job,status)
2 values( 2, 10, 'a', 'ACTIVE' );
insert into project(project_id,teamid,job,status)
ERROR at line 1:
ORA-00001: unique constraint (OPS$TKYTE.JOB_UNIQUE_IN_TEAMID) violated
SQL> create table source as select * from dba_source;
테이블이 생성되었습니다.
SQL> select text from source where rownum < 10;
TEXT
\---------------------------------------------------------------------------------------------------\-
package STANDARD AUTHID CURRENT_USER is \-\- careful on this line; SED edit occurs\!
/*********\* Types and subtypes, do not reorder \**********/
type BOOLEAN is (FALSE, TRUE);
type DATE is DATE_BASE;
type NUMBER is NUMBER_BASE;
subtype FLOAT is NUMBER; \-\- NUMBER(126)
9 개의 행이 선택되었습니다.
SQL> select * from source where upper(text) like '%SUBTYPE%';
195 개의 행이 선택되었습니다.
경 과: 00:00:01.98
Execution Plan
\---------------------------------------------------------\-
Plan hash value: 1389487928
\---------------------------------------------------------------------------\-
\| Id \| Operation \| Name \| Rows \| Bytes \| Cost (%CPU)\| Time \|
\---------------------------------------------------------------------------\-
\| 0 \| SELECT STATEMENT \| \| 198 \| 397K\| 1401 (3)\| 00:00:17 \|
\|* 1 \| TABLE ACCESS FULL\| SOURCE \| 198 \| 397K\| 1401 (3)\| 00:00:17 \|
\---------------------------------------------------------------------------\-
Predicate Information (identified by operation id):
\--------------------------------------------------\-
1 - filter(UPPER("TEXT") LIKE '%SUBTYPE%')
Note
\----\-
- dynamic sampling used for this statement
Statistics
\---------------------------------------------------------\-
0 recursive calls
0 db block gets
6272 consistent gets
5096 physical reads
0 redo size
13677 bytes sent via SQL*Net to client
532 bytes received via SQL*Net from client
14 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
195 rows processed
SQL> create index source_idx on source(text) indextype is stxsys.context;
인덱스가 생성되었습니다.
SQL> select * from source where contains(text,'subtype')>0;
187 개의 행이 선택되었습니다.
경 과: 00:00:00.03
Execution Plan
\---------------------------------------------------------\-
Plan hash value: 1106849809
\-----------------------------------------------------------------------------------------\-
\| Id \| Operation \| Name \| Rows \| Bytes \| Cost (%CPU)\| Time \|
\-----------------------------------------------------------------------------------------\-
\| 0 \| SELECT STATEMENT \| \| 160 \| 323K\| 43 (0)\| 00:00:01 \|
\| 1 \| TABLE ACCESS BY INDEX ROWID\| SOURCE \| 160 \| 323K\| 43 (0)\| 00:00:01 \|
\|* 2 \| DOMAIN INDEX \| SOURCE_IDX \| \| \| 4 (0)\| 00:00:01 \|
\-----------------------------------------------------------------------------------------\-
Predicate Information (identified by operation id):
\--------------------------------------------------\-
2 - access("CTXSYS"."CONTAINS"("TEXT",'subtype')>0)
Note
\----\-
- dynamic sampling used for this statement
Statistics
\---------------------------------------------------------\-
138 recursive calls
0 db block gets
539 consistent gets
6 physical reads
0 redo size
13257 bytes sent via SQL*Net to client
532 bytes received via SQL*Net from client
14 SQL*Net roundtrips to/from client
0 sorts (memory)
0 sorts (disk)
187 rows processed
- 강좌 URL : http://www.gurubee.net/lecture/3569
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.