Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SQL in statement very slow any help please

ngac_ukOct 6 2009 — edited Oct 6 2009
Hi guys forgive me if i dont give enough information we dont normally have many problems with slow queries as our data does not usually get to a level that is effected by speed.

I have a query that does a search of a view with approx 30k records. I then use a connect by to find all the relevent records that apply to this scenerio and place the results into an oracle form.

I have hard coded an example ('ACT' and 6089) into this code, but usually the numbers/code will be a parameter thats passed in.

Individually the select itemcode,notes from v_allitems takes approx 0.1 seconds to run
and the IN statement takes approx 0.007 seconds to run.

Together they take over 6 seconds which is a little too slow. So i assume its the IN thats causing me the problem as i am returning over 100 records to search IN. Is there an alternate way other than IN that anyone can think of to achieve the desired result?

Thanks in advance
select ITEMCODE, notes from v_allitems
where ITEMCODE = ( 'ACT'||','||6089) OR ITEMCODE IN
    (SELECT pcchildcode
      ||','
      || pcchild item
       FROM afpc
      CONNECT BY pcparent = prior pcchild
    AND pcparentcode        = prior pcchildcode START
    WITH pcparent           = 6089
    AND pcparentcode        = 'ACT'
  
  UNION ALL
     
     SELECT pcparentcode
      ||','
      || pcparent item
       FROM afpc
      CONNECT BY pcchild = prior pcparent
    AND pcchildcode        = prior pcparentcode START
    WITH pcchild           = 6089
    AND pcchildcode        = 'ACT'
    ) 
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 3 2009
Added on Oct 6 2009
2 comments
334 views