Skip to Main Content
  • Questions
  • Do I need to flush shared pool to use new stats

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Gary.

Asked: June 18, 2008 - 5:53 pm UTC

Last updated: February 21, 2009 - 8:44 pm UTC

Version: 10.2.0

Viewed 1000+ times

You Asked

Hi Tom,
After collecting new statistics of tables/indexes, do I need to flush shared pool so that when the same SQLs re-run, Oracle parses them according to the new stats, and produces new optimal plans? I didn't find the answer from Oracle manuals.

Thanks.

and Tom said...

http://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_stats.htm#i1036461

the invalidate parameter in DBMS_STATS controls this

if set to "false", the plans will not be invalidated - they will age out normally at some point and then use the new statistics.

if set to "true", all dependent plans are flushed and will be reparsed

in current releases, if set to the default DBMS_STATS.AUTO_INVALIDATE, then we'll invalidate the dependent cursors over time - so as to not hit the shared pool really really hard all at once - over the course of a short period of time, the dependent cursors will invalidate themselves - not all at once.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Stan Kharab, February 19, 2009 - 11:52 pm UTC

Hi Tom

Can you please elaborate more regarding algorithm behind AUTO_INVALIDATE. You mentioned that "over the course of a SHORT period of time, all dependent cursors will invalidate themselves but not all at once".
Is there any parameters that influence when/what will be invalidated? Do size of shared_pool , number of objects/cursors, type of stats gathered, or anything else play any role in calculation to what/when will be invalidated?

Thanks
Stan
Tom Kyte
February 21, 2009 - 8:44 pm UTC

it is undocumented, it can and will and probably already has changed over time, it is automated, it is self tuning based on how the Oracle kernel developers feel it should be.

Basically you can either

a) invalidate everything right here, right now, right away and suffer the resulting hard parse storm

b) invalidate things casually, more gently, over time...


It is important to know that (b) is the default in current releases however, because it does change what you should expect to see after a dbms_stats run - you won't see the hard parse storm you used to see, and that might be confusing as we are "used" to seeing dependent sql going invalid and re-hard parsing right away. Some people *rely* on that (eg: they gathered stats in order to flush that sql from the shared pool and now it doesn't..)

A small correction

volkerk, October 01, 2009 - 8:56 pm UTC

Thanks for stumping me at this useful parameter, Tom.
Although the parameter is actually called "no_invalidate", and to force immediate re-parsing due to the changed stats when queries on the object are next executed you have to set it to FALSE (in other words, invalidate=TRUE, but that parameter does not exist).

great help

A reader, December 17, 2010 - 11:59 am UTC

thanks so much for this post, i thought i was going crazy after we upgraded to 11g, now i understand!

More to Explore

DBMS_STATS

More on PL/SQL routine DBMS_STATS here