Solved

Performance problem with substring in where clause

Posted on 2004-10-26
2,753 Views
Last Modified: 2010-08-05
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)))
0
Question by:Mobilant
    7 Comments
     
    LVL 6

    Accepted Solution

    by:
    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.

    0
     
    LVL 47

    Expert Comment

    by: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!
    0
     

    Author Comment

    by:Mobilant
    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!
    0
     
    LVL 6

    Expert Comment

    by:morphman
    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.
    0
     
    LVL 6

    Expert Comment

    by:izblank
    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
    0
     
    LVL 7

    Expert Comment

    by:grim_toaster
    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).
    0
     

    Author Comment

    by:Mobilant
    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
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Course: JavaScript Coding - Massive 12-Part Bundle

    Regardless of your programming skill level, you'll go from basics to advanced concepts in a vast array of JavaScript subjects including Sammy.js, Agility.js, Ember.js, Node.js, jQuery, AJAX, Extjs, AngularJS, Knockout.js, and JSON.

    Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
    I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
    This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
    This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now