What is your problem?
You can create derived indexes, they can also be used, but make sure you use the same syntax, i.e. SUBSTR(Fld, 1, 2) and not LEFT(Fld, 2).
The easiest way to avoid such problems is to create an additional view based on your table with an additional column that substrings the original field (with the same syntax as in the index).
When using this view and selecting the additional column the syntax is in either way identical.
According to my experience the query optimizer will rather use an index when there is a view with an appropriate column (this column is used in the query), than hardcoding it in exactly the same way.
------------------------------
Birgitta Hauser
Database and Software Engineer
Selfemployed - Modernization-Education-Consulting on IBM i
Kaufering
+49 170 5269964
------------------------------
Original Message:
Sent: Fri January 26, 2024 12:01 PM
From: Patrick Conner
Subject: building an index based on a substr
What are the thoughts on building an index over a substring of a column?
Example: create index testLib.veh_test_substr_index for system name tstvehsubi on prodLib.vehFile ( substr(lotNbr, 1, 2) as lane );
...just another index?
------------------------------
Patrick Conner
------------------------------
#SQL