2. •SQl code is
Loading into loaded into
shared pool RAM for
parsing
•Checks for
Syntax Parse syntax errors
Parsing of SQL
•Checks for
table/columns
query in
Semantic Parse
Oracle
names and
access
Query •Transfroms
complex SQL
Transformation to simpler
•Creates and
Optimization execution plan
•This Builds
Create executable file
executable with native file
calls
3. Concept
• Look at the first step, a soft parse does not require a
shared pool reload and associated RAM memory
allocation, while a hard parse requires all this.
• Excessive Hard Parsing can occur when
– Shared pool size is too small
– (or) Query has non-reusable SQL statements without host
variable
• This is a common scenario in many OLTP systems,
where lot of small queries are being hit to the DB.
• In order to do soft parsing rather then hard , bind
variables must be used in our SQL statments
4. Hard Parsed SQL
• declare
type t_cur is ref cursor;
cur t_cur;
begin
for j in 1..10000
loop
open cur for
'SELECT b FROM xxx WHERE a = ' || to_char(j);
close cur;
- do some processing with "b"
end loop;
end;
/
• Parse time: 5.89s
Execute time: 2.62s
TOTAL elapsed time: 8.51s
5. Soft Parsed SQL
• declare
type t_cur is ref cursor;
cur t_cur;
begin
for j in 1..10000
loop
open cur for
'SELECT b FROM xxx WHERE a = :a' using j;
close cur;
- do some processing with "b"
end loop;
end;
/
• Parse time: 0.01s
Execute time: 2.58s
TOTAL elapsed time: 2.59s (30% of the time!)