Oracle EXECUTE IMMEDIATE changes explain plan of query.

Posted by Gunny on Stack Overflow See other posts from Stack Overflow or by Gunny
Published on 2010-05-07T16:12:46Z Indexed on 2010/05/07 16:28 UTC
Read the original article Hit count: 337

I have a stored procedure that I am calling using EXECUTE IMMEDIATE. The issue that I am facing is that the explain plan is different when I call the procedure directly vs when I use EXECUTE IMMEDIATE to call the procedure. This is causing the execution time to increase 5x. The main difference between the plans is that when I use execute immediate the optimizer isn't unnesting the subquery (I'm using a NOT EXISTS condition). We are using Rule Based Optimizer here at work.

Example: Fast:

begin
   package.procedure;
end;
/

Slow:

begin
   execute immediate 'begin package.' || proc_name || '; end;';
end;
/

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about explain-plan