0% found this document useful (0 votes)
46 views

Function Based Index

The document describes creating normal and function-based indexes on the employee table and comparing the performance of queries using each. A normal index on ename did not get used, resulting in a full table scan and query time of 1 minute. A function-based index on lower(ename) was used, resulting in an index range scan and faster query time of 36 seconds. Function-based indexes can help optimize queries better than normal indexes in some cases.

Uploaded by

methukupally
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Function Based Index

The document describes creating normal and function-based indexes on the employee table and comparing the performance of queries using each. A normal index on ename did not get used, resulting in a full table scan and query time of 1 minute. A function-based index on lower(ename) was used, resulting in an index range scan and faster query time of 36 seconds. Function-based indexes can help optimize queries better than normal indexes in some cases.

Uploaded by

methukupally
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

FUNCTION-BASED INDEX

###########################################################################################

SYS>>set time on
17:21:13 SYS>>set timing on
17:21:15 SYS>>conn steve/steve
Connected.
17:21:20 STEVE>>update employee set ename='WILLS'
where empno=(select max(empno) from employee);

1 row updated.

Elapsed: 00:00:34.92

17:23:01 STEVE>>commit;

Commit complete.

17:23:05 STEVE>>create index ind_ename on employee(ename);

Index created.

Elapsed: 00:05:49.63

17:28:58 STEVE>>select index_name,index_type,table_name from user_indexes;

INDEX_NAME INDEX_TYPE TABLE_NAME


------------------------------ --------------------------- --------------------
IND_ENAME NORMAL EMPLOYEE

17:29:15 STEVE>>conn / as sysdba


Connected.
17:29:23 SYS>>alter system flush buffer_cache;

System altered.

17:29:33 SYS>>alter system flush shared_pool;

System altered.

17:29:41 SYS>>conn steve/steve


Connected.
17:30:04 STEVE>>select * from employee where lower(ename)='wills';

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


---------- ---------- --------- ---------- --------- ---------- ---------- ----------
92034659 WILLS CLERK 7782 23-JAN-82 1300 10

###################################
# Elapsed: 00:01:00.18 #
###################################
Execution Plan
----------------------------------------------------------
Plan hash value: 2119105728

------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 6241 | 530K| 155K (1)| 00:31:01 |
|* 1 | TABLE ACCESS FULL| EMPLOYEE | 6241 | 530K| 155K (1)| 00:31:01 |
------------------------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------

1 - filter(LOWER("ENAME")='wills')

Note
-----
- dynamic sampling used for this statement (level=2)

Statistics
----------------------------------------------------------
514 recursive calls
0 db block gets
566393 consistent gets
566353 physical reads
0 redo size
863 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
6 sorts (memory)
0 sorts (disk)
1 rows processed

17:31:52 STEVE>>drop index ind_ename;

Index dropped.

17:32:03 STEVE>>create index fun_ename on employee(lower(ename));

Index created.

Elapsed: 00:05:33.75

17:37:58 STEVE>>conn / as sysdba


Connected.
17:38:03 SYS>>alter system flush buffer_cache;

System altered.

17:38:11 SYS>>alter system flush shared_pool;

System altered.
17:38:20 SYS>>conn steve/steve
Connected.

17:38:36 STEVE>>select * from employee where lower(ename)='wills';

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


---------- ---------- --------- ---------- --------- ---------- ---------- ----------
92034659 WILLS CLERK 7782 23-JAN-82 1300 10

###################################
# Elapsed: 00:00:00.36 #
###################################
Execution Plan
----------------------------------------------------------
Plan hash value: 2852480947

-----------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 715K| 64M| 46240 (1)| 00:09:15 |
| 1 | TABLE ACCESS BY INDEX ROWID| EMPLOYEE | 715K| 64M| 46240 (1)| 00:09:15 |
|* 2 | INDEX RANGE SCAN | FUN_ENAME | 286K| | 14513 (1)| 00:02:55 |
-----------------------------------------------------------------------------------------

Predicate Information (identified by operation id):


---------------------------------------------------

2 - access(LOWER("ENAME")='wills')

Note
-----
- dynamic sampling used for this statement (level=2)

Statistics
----------------------------------------------------------
778 recursive calls
0 db block gets
191 consistent gets
117 physical reads
0 redo size
863 bytes sent via SQL*Net to client
415 bytes received via SQL*Net from client
2 SQL*Net roundtrips to/from client
11 sorts (memory)
0 sorts (disk)
1 rows processed
OBSERVATION : TIME ELAPSED FOR SELECT STATEMENT
ON TABLE HAVING NORMAL INDEX AND
BITMAP INDEX.

NOTE : 1) THOUGH THE COLUMN DEPTNO IS HAVING NORMAL INDEX ON IT,


THE OPIMIZER IS NOT USING THE INDEX AND THE EXECUTION IS
GOING THROUGH FULL TABLE SCAN.

2) BUT WHEN THE SAME COLUMN IS HAVING FUNCTION-BASED INDEX


ON IT,THEN OPTIMIZER IS USING IT IN THE EXECUTION PLAN.

NORMAL INDEX : 00:01:00.18


(BUT FULL TABLE SCAN)

FUNCTION-BASED INDEX : 00:00:00.36

TIP : SPECIAL INDEXES WILL BE MORE EFFECTIVE THAN NORMAL INDEX.

You might also like