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

后端 未结 2 1016
南笙
南笙 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.

提交回复
热议问题