3

We use the following to refresh statistics for all tables in a given schema:

exec dbms_stats.gather_schema_stats(ownname => 'some_schema', estimate_percent => dbms_stats.auto_sample_size, cascade => true, method_opt => 'FOR ALL COLUMNS SIZE AUTO', degree => 12);

This however, sets row-counts for our materialized views to zero and has the unwanted side effect of causing inefficient query plans for queries against materialized views. We work around this by gathering table stats against the specific mviews after the schema stats have run.

My question is: can I change the parameters to gather_schema_stats in any way that will cause mview row-counts not to be set to zero?

4

1 回答 1

3

你不能告诉GATHER_SCHEMA_STATS排除某些对象。您可以GATHER STALE只收集统计信息过时的对象的统计信息,但完全有可能包括您的物化视图。解决这个问题的几种方法

1) 使用该LOCK_TABLE_STATS过程锁定您的物化视图的统计信息。这将阻止GATHER_SCHEMA_STATS收集有关这些对象的统计信息,直到您调用该UNLOCK_TABLE_STATS过程(大概作为定期刷新物化视图统计信息的过程的一部分)。

2)EXPORT_TABLE_STATS在收集模式统计信息之前使用该过程保存物化视图的统计信息,然后在调用完成RESTORE_TABLE_STATSGATHER_SCHEMA_STATS调用以放回物化视图统计信息。

3)不要使用GATHER_SCHEMA_STATS。调用GATHER_TABLE_STATS一个循环,在其中排除您想要的任何对象。就像是

BEGIN
  FOR x IN (SELECT *
              FROM dba_tables
             WHERE owner = 'SOME_SCHEMA'
               AND table_name NOT IN (<<list of MVs>>))
  LOOP
     dbms_stats.gather_table_stats( x.owner, x.table_name, ... );
  END LOOP;
END;
于 2011-09-17T17:14:03.803 回答