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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Tips - Function-based indexes

User_1871May 15 2022 — edited May 16 2022

I'm a novice trying to learn about function-based indexes. Any tips?
For example:
In the query that uses the FBI, make sure you have a IS NOT NULL where clause:
"The optimizer can only use an index (in place of a table) if it knows that the index entries are one-for-one with the table. Because it does not know if the expression may return a NULL (which are NOT stored in the index). It cannot make that direct swap unless you inform the optimizer."
"Hence SELECT ROOT FROM TST_AGG will not have the chance to use the index, but SELECT ROOT FROM TST_AGG WHERE ROOT IS NOT NULL should be able to."
Function Based Index not improving query performance
The function should also handle nulls. For example, if null values get passed into the function (such as a null X or Y), then the function should handle that by returning null — so that the function doesn't error-out. If that happens though, and the function does return nulls, then I think that means the query won't use the index; it'll do a full table scan instead. Unless, as mentioned in #1 above, the query's where clause has a IS NOT NULL .
Any functions used in the index must be defined as deterministic.
If you change the semantics of a DETERMINISTIC function and recompile it, then you must manually rebuild any dependent function-based indexes and materialized views. Otherwise, they report results for the prior version of the function.
Disadvantages of Function-Based Indexes
Edit: A SQL hint might be an option -- to force Oracle to use the FBI:
/*+ INDEX (parcels shape_idx) */
Set a SQL hint to instruct the Oracle optimizer in choosing an execution plan.
Related: Function-based spatial indexes

Comments

Hi,

don't have HSQLDB for testing, but typing HSQLDB TopLink into a Google search brought up many messages of people that got this combination working.

I suggest to post this question on the TopLink forum here on OTN

Frank
1 - 1

Post Details

Added on May 15 2022
5 comments
589 views