0

I have the following statement:

 WITH foos AS (
    select regexp_substr('H50','[^,]+', 1, level) x from dual
    connect by regexp_substr('H50', '[^,]+', 1, level) is not null
), baars AS (
    select regexp_substr('G30','[^,]+', 1, level) x from dual
    connect by regexp_substr('G30', '[^,]+', 1, level) is not null
) 
  select 
  count(*) 
  from VIEW
  where foo in (
    'H50'
    -- select x from foos
  )
  and bar in (
   'G30'
   -- select x from bars
  );

When using the constants G30 and H50 it is really fast. However when I use the subquerys, it is realy slow (~5 seconds). I have no idea why this can be the case. any ideas?

6
  • what you mean use constants and use subquery? Commented Nov 24, 2016 at 14:42
  • 1
    Performance questions should include EXPLAIN ANALYZE and some information about table size, index, current time performance, desire time, etc. Slow is a relative term and we need a real value to compare. Commented Nov 24, 2016 at 14:44
  • Why do you use where foo in ('H50') and not where foo ='H50'? Not sure this has something to do with the performance issue you are facing, but still... (the same for the second condition of course). Commented Nov 24, 2016 at 14:46
  • Because I want to have multiple foos. I want to pass it as string parameter like 'H50,H51,H52,H53' Commented Nov 24, 2016 at 14:47
  • So you want to know why where foo in ('H50') is faster than where foo in (select x from foos)? Check the EXPLAIN PLAN Commented Nov 24, 2016 at 14:50

1 Answer 1

1

For start, the inline views are not being used in the first use-case, as in not being executed at all.

with    t1 (n) as (select 1 from dual union all select n+1 from t where n <= 10)
       ,t2 (n) as (select 1 from dual union all select n+1 from t where n <= 1000000000000)

select  *
from    t1
;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.