Oracle database 11.1.0.7 and EBS Applications 11.5.10.
I have a poorly performing custom view, which includes Oracle EBS base view APPS.RA_CUSTOMER_TRX. This base view is against base table RA_CUSTOMER_TRX_ALL as shown below.
FROM RA_CUSTOMER_TRX_ALL
WHERE NVL (
ORG_ID,
NVL (
TO_NUMBER (
DECODE (SUBSTRB (USERENV ('CLIENT_INFO'), 1, 1),
' ', NULL,
SUBSTRB (USERENV ('CLIENT_INFO'), 1, 10))),
-99)) =
NVL (
TO_NUMBER (
DECODE (SUBSTRB (USERENV ('CLIENT_INFO'), 1, 1),
' ', NULL,
SUBSTRB (USERENV ('CLIENT_INFO'), 1, 10))),
-99);
When I run the Oracle Tuning Advisor from Toad against the sql of my custom view, it tells me
1- Restructure SQL finding (see plan 1 in explain plans section)
----------------------------------------------------------------
The predicate NVL("RA_CUSTOMER_TRX_ALL"."ORG_ID",NVL(TO_NUMBER(DECODE(SUBSTRB
(USERENV('CLIENT_INFO'),1,1),' ',NULL,SUBSTRB(USERENV('CLIENT_INFO'),1,10))),
(-99)))=NVL(TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1),'
',NULL,SUBSTRB(USERENV('CLIENT_INFO'),1,10))),(-99)) used at line ID 53 of
the execution plan contains an expression on indexed column "ORG_ID". This
expression prevents the optimizer from efficiently using indices on table
"AR"."RA_CUSTOMER_TRX_ALL".
Recommendation
--------------
- Rewrite the predicate into an equivalent form to take advantage of
indices. Alternatively, create a function-based index on the expression.
Rationale
---------
The optimizer is unable to use an index if the predicate is an inequality
condition or if there is an expression or an implicit data type conversion
on the indexed column.
So my options are either 1) to rewrite the custom view to go against the base table instead of the base view, or 2) create a function-based index. I tried creating the function-based index, but it tells me "only pure functions can be indexed."
I would like to solve this by creating the index because I believe other similar views are out there that will benefit from this. My DBA skills are not high enough for this, so hoping someone has come across this before and can advise.
Thank you.