How to invalidate a SQL statement in the Oracle SQL area so that a new plan is produced when collecting statistics

后端 未结 2 1014
南笙
南笙 2021-01-13 17:18

I have a table and a query (within a PL/SQL packge) accessing that table. Statistics are collected weekly normally.

A large update has been run on the table, result

相关标签:
2条回答
  • 2021-01-13 17:19

    I found out (when researching something else) that what I should have done was to use

    no_invalidate => FALSE
    

    When collecting the statistics by calling gather_table_stats. This would have caused all SQL plans referencing the table to immediately be invalidated.

    The Oracle docs say:

    Does not invalidate the dependent cursors if set to TRUE. The procedure 
    invalidates the dependent cursors immediately if set to FALSE. Use
    DBMS_STATS.AUTO_INVALIDATE. to have Oracle decide when to invalidate dependent
    cursors. This is the default.
    

    The default of AUTO_INVALIDATE seems to cause invalidation of SQL statements within the next 5 hours. This is to stop massive number of hard-parses if you are collecting statistics on lots of objects.

    0 讨论(0)
  • 2021-01-13 17:22

    If you are using 10.2.0.4 or later, you should be able to use the DBMS_SHARED_POOL package to purge a single cursor from the shared pool.

    0 讨论(0)
提交回复
热议问题