Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Oracle build-in UPPER function in WHERE lead to bad performance of SELECT statement?

Our Oracle database application contains a Table called PERSON
This Table contains a column called PERSON_NAME
Also we have an INDEX on this column to speed up SELECT using this column

So when we use following SQL statement performance is fine

SELECT *
FROM PERSON
WHERE 1=1
AND PERSON_NAME = '  Yajli  '
;

But in some business cases
We need to make search by PERSON_NAME is NOT case sensitive

So We try following SQL statement

SELECT *
FROM PERSON
WHERE 1=1
AND UPPER(PERSON_NAME) = UPPER('  YajLi  ')
;

But it lead us to a BAD performance and SELECT query in this case take a lot of time

Any Help How to enhance performance of SELECT on both cases together
* search by PERSON_NAME is NOT case sensitive
* search by PERSON_NAME is case sensitive

like image 247
ahmednabil88 Avatar asked Dec 14 '25 21:12

ahmednabil88


1 Answers

You would have bad relative performance because the original query uses an index on PERSON_NAME. However, when you apply a function, Oracle no longer uses the index.

If this is something that you need to do frequently (as you suggest), then you can create an index on the function:

CREATE INDEX idx_person_upper_personname ON PERSON(UPPER(PERSONNAME));

Then Oracle will use this index when you use the function UPPER(PERSON) in the WHERE clause.

like image 193
Gordon Linoff Avatar answered Dec 16 '25 11:12

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!