Oracle FAQ Your Portal to the Oracle Knowledge Grid

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Query on Number of Parses and Executions(for Selects from Views)

RE: Query on Number of Parses and Executions(for Selects from Views)

From: <>
Date: Tue, 6 Apr 2004 15:45:04 +0530
Message-ID: <10898BE7CA96D611988B000802255AAF05CE0B9C@fmgrt>

Hi Cary,

Thank your highlighting the same. I agree with you on calling a parse = once and reusing the parsed cursor is the best approach. But the = mentioned select statement in my case is a ref cursor and not a dynamic = statement.

        I am wondering why a cursor like this should call a parse every time?. = Additional information here is that the cursor is defined in a function = (say function A) within a package and this function is called repeatedly = for various values of col1,col2,col3 from another procedure (Procedure = B) within the same package.

The pseudo code of the routine would be like

   package B is

    type cur_type is ref cursor;

    cx_curtype cur_type;

        Procedure B(some params)

	    for I in <some other cursor>

	       call function A(col1,col2);

	   end loop;

           end procedureB;

	function A(col1, col2)

	    if <some condition>  -- This condition would be true for all the =
calls in this run and hence only this cursor would be opened

                       open cursor cx_curtype=20
	                 for select <column_name list>,rowid
	                 from <view>
                              where col1=3D:b1 and col2 =3D:b2 and =
                               order by col5;

                        open cursor cx_curtype=20
	                 for select <column_name list>,rowid
	                 from <view>
                              where col1=3D:b1 and col3=3D'N'
                              order by col5;
 	      end if;

           end function A;
     end package;

Since the same SQL statement is executed, I would expect it to reuse the = parsed statement but in this case it doesn't. Is this a expected = behavior with ref cursors?

Thanks again

Best Regards

Sriram Kumar
-----Original Message-----
From: =
[] On Behalf Of Cary Millsap
Sent: Tuesday, April 06, 2004 12:24 PM
Subject: RE: Query on Number of Parses and Executions(for Selects from = Views)


How many parse *calls* get made is determined entirely by the application. The application is simply telling the database to parse the same statement 2,079 times. The Oracle kernel is smart enough to know that only the first requires a "hard parse," but once the app tells the db to execute a parse call, the db counts it as a parse call. ...And it costs a lot of end-user response time to process all these parse calls: lots of CPU and lots of network latency that shows up as time spent in "SQL*Net message from client" timed events.

To fix the problem, pull the parse call outside of whatever loop it's in within the application source code. If it's PL/SQL, then use the DBMS_SQL package to extract the parse call from the loop so that you have this:

  /* good */

...And NOT this:

  /* bad */
    execute immediate ...

Cary Millsap
Hotsos Enterprises, Ltd.
* Nullius in verba *

Upcoming events:

- Performance Diagnosis 101: 4/6 Seattle, 5/7 Dallas, 5/18 New Jersey
- SQL Optimization 101: 4/19 Denver, 5/3 Boston, 5/24 San Diego
- Hotsos Symposium 2005: March 6-10 Dallas
- Visit for schedule details...

-----Original Message-----
[] On Behalf Of
Sent: Tuesday, April 06, 2004 1:23 AM
Subject: Query on Number of Parses and Executions(for Selects from Views)

Hi Guru's

    I have a query like this
  select <column_name list>,rowid
  from <view>
  where col1=3D:b1 and col2 =3D:b2 and col3=3D'N'   order by col5

  1. This SQL is executed from PL/SQL and the query static in nature =20
  2. Oracle version is
  3. This query would be executed say 2000 times for various values of col1,col2
  4. I traced the session and tkprof output shows that number of parses and executes are 2079.=20 =20 call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ----------
    Parse 2079 216.92 233.07 0 0 0 0 Execute 2079 0.33 0.43 0 0 0 0 Fetch 5297 1.54 2.71 233 11929 0 3218 ------- ------ -------- ---------- ---------- ---------- ----------
    total 9455 218.79 236.21 233 11929 0 3218 =20 =20 I expected that this statement to be parsed once and executed 2079 times. why is it getting parsed 2079 times?. =20 Also, =20 Misses in library cache during parse: 1 =20 which means that the statement was not found in the library cache only once... =20 My initial guess was that the optimizer was rewriting the query but checked query_rewrite_enabled=3Dfalse...The optimizer mode is = RULE...would not be able to change the optimizer_mode for now =20 Would be great if you could throw some light on this please. =20 Best Regards

Sriram Kumar=20

This message contains privileged and confidential information and is = intended only for the individual named.If you are not the intended = recipient you should not disseminate,distribute,store,print, copy or = deliver this message.Please notify the sender immediately by e-mail if = you have received this e-mail by mistake and delete this e-mail from = your system.E-mail transmission cannot be guaranteed to be secure or = error-free as information could be =
intercepted,corrupted,lost,destroyed,arrive late or incomplete or = contain viruses.The sender therefore does not accept liability for any = errors or omissions in the contents of this message which arise as a = result of e-mail transmission. If verification is required please = request a hard-copy version.

Please see the official ORACLE-L FAQ:

To unsubscribe send email to: put 'unsubscribe' in the subject line.
Archives are at
FAQ is at
Received on Tue Apr 06 2004 - 05:08:45 CDT

Original text of this message