• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2785
  • Last Modified:

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)))
1 Solution
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.

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!
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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!

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.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now