Skip to Main Content

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Waldo.

Asked: August 04, 2022 - 8:16 pm UTC

Last updated: August 05, 2022 - 1:18 pm UTC

Version: 0

Viewed 10K+ times! This question is

You Asked

If I have an index, for example, by CD_CLIENT, CD_COMMOD, CD_MERCAD, and there is a query that uses them with TRIM. So:
.......
WHERE
TRIM( CUSTOMER_CD ) = ...
AND TRIM(CD_COMMOD) = ...
AND TRIM(CD_MARKET) = ...


Should I make another index that has the TRIM ?
Or is that enough?

Thank you very much!!

and Chris said...

Should I make another index that has the TRIM ?


Yes!

Applying any function to a column in the WHERE limits the optimizer's ability to use indexes on them.
TRIM is a function
=> This limits the optimizer's ability to use indexes.

That said, a better solution would be to avoid using TRIM() altogether - assuming this is possible.

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.