Performance problem with substring in where clause


i have a problem with the following SQL that results in a extremly slow view.

The DB is a Oracle 8.17. Thanks for any help!


select inpfha.objektid, inpfha.strassenid, inpfha.hausnr, inpfha.zusatz, jvafha.LOCATIONS_KEY, jvafha.ENE_HAUSUNTERNR from MB_INP_ANSCHLUSS_FHA inpfha, IDP_EXTERN_STRASSENTEIL strasse, MB_JVA_ANSCHLUSS_FHA jvafha
where inpfha.strassenid = strasse.strnr and jvafha.ENE_STRASSEID = strasse.KEY_STRASSE and inpfha.hausnr = jvafha.ENE_hausnr and
((inpfha.zusatz is null and substr(jvafha.ENE_HAUSUNTERNR,0,1) = ' ') or inpfha.zusatz = substr(jvafha.ENE_HAUSUNTERNR,0,length(inpfha.zusatz)))
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

2 functional indexes may help here.

1. on substr(jvafha.ENE_HAUSUNTERNR,0,1)
2. on substr(jvafha.ENE_HAUSUNTERNR,0,length(inpfha.zusatz))

otherwise you will be seeing a full table-scan for this query.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Yes, thats right! You have to see if the substring you are searching for is permanently placed in the string itself. If the substring is not parametrized you can easily create function based index (es) on the tables.
Of course everything is balanced. If there are many indexes, the insert, update, delete DML statements will run slowly, but selects will run faster and vice versa.

Viel Glueck und Erfolg!
MobilantAuthor Commented:

unluckily it is a Oracle 8.05 on the test server and a 8.17 on the production server. The functional index works on the 8.17 but on the old version. Any suggestions?

morphman you´ll get points!
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Yes, upgrade the test server. tell your bosses that 8.0.5 is not a supported database anymore, and that you cant do things in test that will speed things up in live!!

in 8.0.5 you cannot speed up your query. All I would suggest is performing a USE_HASH optimiser hint on both tables if there are many rows in each table.
There's something wrong about this query even if you ignore the string comparison stuff.  For one thing, there is no literals or parameters involved in the WHERE clause, so it is bound to be a table scan on at least one table

Could you provide the following:
-number of rows for each table
-available indexes for each table
One potential performance improvement you can get is to change the line:
and  ((inpfha.zusatz is null and substr(jvafha.ENE_HAUSUNTERNR,0,1) = ' ') or

To instead be
and  ((inpfha.zusatz is null and jvafha.ENE_HAUSUNTERNR LIKE ' %') or

This will also avoid the need for the function based index on this column (you could create a standard index if appropriate).
MobilantAuthor Commented:
By the way the admin sets up a new Oracle 9i  ;-)
Then i will use the functional indices.
Damn, that i can´t split the points. I learned a lot of you guys!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.