Você está na página 1de 2

What is a CURSOR in short?

source - Christian Antognini - Shareable cursors ================================================= - A cursor is a handle to a "private SQL area" which is associated with a "publi c SQL area". - The private SQL area contains session specific information like a. bind variable value b. query execution state information - The shared SQL area contains : a. parse tree and execution plan of the associated SQL statement. b. it is stored in the library cache. Note: Private SQL area reside in the UGA. Source - Optimizerblog ======================= What is Adaptive Cursor Sharing in short? - In short it is "Feedback based Optimization". - Before ACS, one SQL statment after being parsed which will have a CURSOR corre sponding to the parsed SQL statement can have only one execution statement. So a bind variable value change ,influencing the plan So, BIND variable peeking by Oracle determines the plan and subsequent values of the BIND variable will never considered for influencing the plan again. - With ACS, one SQL statement is allowed to have multiple execution plans based on a "FEEDBACK BASED OPTIMIZATION". For example: - SQL runs for the first time with a bind variable - this makes the SQL statem ent bind sensitive [ but not bind aware] - Next time the SQL runs and it records the buffer gets and other statistics a nd sees that if the stats show a degradation , it makes a record of the bind variable and records that this execution was n ot optimal for the particular bind variable value. Note that at this point too, the SQL is bind sensitive but not bind awar e. - When the SQL runs again with the same bind variable that gave a degraded per formance Oracle will parse the statement with that bind variable and the optimal plan for the SQL with that bind variable value. Now that the SQL executed by considering the value of the bind variable , the SQL will be recorded as "bind variable sensitive" as well as "bind variabl e aware". - Another execution with the bind variable value as the first statement will e xecute with the first execution plan. Now, the SQL will have 3 child cursors , 1 bind-sensitive , not bind aware [ index range scan] 2 bind-sensitive , bind aware for f ull table scan 3 bind-sensitive , bind aware for i ndex range scan - The child cursor which was generated when the statement was not bind aware w ill be left with "is_sharable" - 'N' and will be aged out of the library cache. This Feedback System for Adaptive Cursor Sharing also introduces a possibility o f a large number of cursors at times which gets reduced with time. - A new value for a bind variable gets used. - Oracle tries to use a cursor which it might think best fits with the selectiv ity of the value in the bind variable.

ed ut

If oracle does not seem to find one , it will create a new cursor. If plan is same as the one that already exists , the two cursors will be merg [ so both bind variable values will be tagged to the same cursor ] One of the cursors will be marked non-shareable and will eventually be aged o of library cache.

Hence with ACS - cursor_sharing should be "FORCED".