Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reducing Parse Calls in Oracle

I am noticing the parse_calls are equal to the number of executions in our Oracle 11g database.

 select parse_calls, executions
 from v$sql order by parse_calls desc;

Running the above query gives the following result.

"PARSE_CALLS" "EXECUTIONS"
   87480        87480
   87475        87476
   87044        87044
   26662        26662
   21870        21870
   21870        21870

As I'm aware this is a major performance drawback. All of these SQL statements are either stored procedures or using bind variables. I'm also reusing the command objects that are calling the stored procedures from C#.

How do I reduce the number of parse calls in this?

Also, is there some method I can distinguish between hard parses and soft parses?

EDIT:

As @DCookie mentioned I ran the following query on the database.

SELECT s2.name, SUM(s1.value)
FROM v$sesstat s1 join v$statname s2 on s1.statistic# = s2.statistic#
WHERE s2.name LIKE '%parse count%'
GROUP BY s2.name
ORDER BY 1,2;

The result is as below

"NAME"                         "SUM(S1.VALUE)"
"parse count (describe)"             0
"parse count (failures)"             29
"parse count (hard)"                 258
"parse count (total)"                11471

So the number of hard parses seem to be very low compared to the number of parses. Thanks to everyone for their responses :)

FINAL UPDATE:

The main issue for the parsing was because we had connection pooling turned off in the connection string. After turning on connection pooling I was able to completely resolve the parsing problem.

like image 520
Chathura W Avatar asked Jun 01 '11 11:06

Chathura W


People also ask

What is parse calls in Oracle?

The Parse Calls Oracle metric is the number of times a parsed representation of a SQL statement has been called-- or reused--for all cursors.

How can we avoid hard parsing in Oracle?

so Oracle will always run the same sql (select * from emp where id = :id) but value of variable will be changed so it will bring an another row(s) for you and also this will prevent hard parsing because Oracle already know this sql.

How can we avoid soft parsing in Oracle?

how you avoid a soft parse varies by language. the query "select * from t where zzz = :BIND" is parsed ONCE per session -- not per execution. In Java -- you would use a prepared/callable statement and prepare it ONCE per session -- not once per execution.

What is parse call?

A parse call has to occur any time a new cursor is created, even if the statement is in the library cache. It is the parse call that checks the library cache. If the statement is found in the library cache, it is a soft parse.


1 Answers

Start with this:

SELECT name, SUM(value)
  FROM v$sesstat s1 join v$statname s2 on s1.statistic# = s2.statistic#
 WHERE s1.name LIKE '%parse count%'
 GROUP BY name
 ORDER BY 1,2;

This will give you the number of hard parses and total parses. The parse_calls values in your query is total parses, hard and soft.

What does your SQL do? Not much cursor processing, mostly single statements? You are getting pretty much a 1-1 ratio of executions to parses, which, if they are soft parses means you are not doing much cursor processing.

EDIT:

Unless you can modify your code to open and hang on to a cursor for each of your SQL statements, and reuse them as much as possible within a session, I don't think you can avoid the parses.

like image 155
DCookie Avatar answered Oct 06 '22 08:10

DCookie