Anyone who has been around Oracle performance over the years knows the grief that hard parsing SQL queries can cause on highly concurrent applications. The number one reason for hard parsing has been applications that don't use bind variables. Without bind variables queries that would otherwise be shared get recompiled because their text is different and Oracle treats them as different queries. Oracle addressed this issue with a parameter called cursor_sharing. The parameter cursor_sharing has three values
exact - the default
similar - replace literals with bind variables, if a histogram keep literal in place
force - replace literals with bind variables and use existing plan if it exists
Here is what the load looks like going from the default, exact, to the value force on a load of the same query but a query that doesn't use bind variables:
--alter session set cursor_sharing=exact;
--alter session set cursor_sharing=force;
--alter session set cursor_sharing=similar;
declare
l_cursor integer default 0;
stmt varchar2(400);
ret number;
BEGIN
select hparse.nextval into ret from dual;
dbms_random.seed(ret);
FOR i IN 1..1000 LOOP
l_cursor:=dbms_sql.open_cursor;
stmt:='SELECT count(*) FROM t1 where c1 < '||
dbms_random.value()||' and c2 < '||dbms_random.value();
execute immediate stmt into ret;
dbms_sql.close_cursor(l_cursor);
END LOOP;
END;
/
Recent comments
17 weeks 19 hours ago
26 weeks 6 days ago
28 weeks 4 days ago
31 weeks 5 days ago
34 weeks 8 hours ago
43 weeks 4 days ago
45 weeks 22 hours ago
46 weeks 23 hours ago
46 weeks 2 days ago
49 weeks 2 hours ago