Link to home
Start Free TrialLog in
Avatar of Mobilant
Mobilant

asked on

Performance problem with substring in where clause

Hi,

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!


Christian

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)))
ASKER CERTIFIED SOLUTION
Avatar of morphman
morphman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of schwertner
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!
Avatar of Mobilant
Mobilant

ASKER

UUpppsss,

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!
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).
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!

Christian