no_invalidate选项
May 25th, 2007
昨天说到dbms_stats在分析表的时候遇到的一点问题:dbms_stats替换analyze的问题
今天Yong提出no_invalidate可能可以解决这个问题,我试了一下,确实可行
这个选项是9i才有的,8i里面没有这一选项
- SQL> select first_load_time,last_load_time,loads,INVALIDATIONS,executions from v$sql where
- 2 sql_text='select /* invalidation */ 1 from test where rownum=1';
- FIRST_LOAD_TIME LAST_LOAD_TIME LOADS INVALIDATIONS EXECUTIONS
- ------------------------------ ------------------------------ ---------- ------------- ----------
- 2007-05-24/07:00:40 2007-05-24/07:22:14 6 5 6
- SQL> exec dbms_stats.gather_table_stats(ownname=> null,tabname=>'TEST',cascade=>true,no_invalidate => true);
- PL/SQL procedure successfully completed.
- SQL> select first_load_time,last_load_time,loads,INVALIDATIONS,executions from v$sql where
- 2 sql_text='select /* invalidation */ 1 from test where rownum=1';
- FIRST_LOAD_TIME LAST_LOAD_TIME LOADS INVALIDATIONS EXECUTIONS
- ------------------------------ ------------------------------ ---------- ------------- ----------
- 2007-05-24/07:00:40 2007-05-24/07:22:14 6 5 104
在分析后,SQL语句并没有被invalidate,这样就避免了在分析的过程中因为statistics没有完全更细而产生错误的plan
在分析完后,可以通过一些DDL语句来invalidate sql. 例如grant select on table to dba
9i的文档中提到可能对于一些特定的索引不适用,不过从实验看来Btree索引是没有问题的,有空的时候看看bitmap,reverse,function index这些是否也适用
- no_invalidate:
- Dependent cursors are not invalidated if this parameter is set to TRUE.
- When the 'cascade' argument is specified, this parameter is not relevant with certain types of indexes, as described in "GATHER_INDEX_STATS Procedure".