Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Function based indexes

user10549528Sep 28 2018 — edited Oct 24 2018

Hello gurus,

Please help me understand how function based indexes works?

https://docs.oracle.com/cd/E11882_01/appdev.112/e41502/adfns_indexes.htm#ADFNS257

taking example from oracle docs,

CREATE OR REPLACE FUNCTION initials (

name IN VARCHAR2

) RETURN VARCHAR2

DETERMINISTIC

IS

BEGIN

RETURN('A. J.');

END;

/

Suppose i create the index as

CREATE INDEX func_substr_index ON

EMPLOYEES(SUBSTR(initials(FIRST_NAME),1,4));

First time i use the query as

1. SELECT SUBSTR(initials(FIRST_NAME),1,4) FROM EMPLOYEES WHERE SUBSTR(initials(FIRST_NAME),1,4) = 'A. J.' ;

This will use the index

But if i change the query to

  1.  SELECT initials(SUBSTR(FIRST\_NAME,1,4)) FROM EMPLOYEES WHERE initials(SUBSTR(FIRST\_NAME,1,4))\= 'A. J.' ;
    
     **Will the second query use the function based index ? My question is will the reversal of function expression cause the index to be used or same order in which index is created** **need to used in query .**
    

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

One more example from oracle docs

pastedImage_2.png

Since function based index p recomputes the function value and then indexes those values to the tables

using this query will cause the index idx to be used

1.  SELECT a FROM Fbi\_tab WHERE a+b\*(c-1) \< 100;

but if i change the expression to

  1. SELECT a FROM Fbi_tab WHERE a+b < 100; OR

    SELECT a FROM Fbi_tab WHERE Fx( a,b,c ) < 100; Fx can be UDF or any other expression like (a+b)*c-1

    will the index be used ?

Since function based index precomputes the function values and store it in index values to the tables.

If i use any other function expression other than one created in function based index which evaluates to those values calculated in function based index entries, will oracle will rewrite the query to use the function based index ?

This post has been answered by Solomon Yakobson on Sep 28 2018
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2018
Added on Sep 28 2018
28 comments
1,521 views