甲骨文:分析 table vs Gather_Table_Stats vs Gather_Schema_Stats

Oracle: Analyze table vs Gather_Table_Stats vs Gather_Schema_Stats

目前在我的数据库中,我在数据库上工作的前任创建了一个工作,每个周末都会收集数据库中所有 table 的列表,并分别为每个 table 在下面执行两个命令的顺序:

ANALYZE TABLE xxTable_Namexx ESTIMATE STATISTICS FOR ALL INDEXED COLUMNS SIZE 75 SAMPLE 100 PERCENT;

EXEC dbms_stats.gather_table_stats(xxSchemaxx,xxTable_Namexx,cascade=>TRUE);

最近有人向我建议:

1.) ANALYZE table 是收集统计数据的旧方法,优化器不再使用它了吗?这个命令的统计数据在整个数据库中是无用的还是在某处使用是真的吗?

2.)不用做这些,每天运行:

dbms_stats.gather_schema_stats(xxSchemaxx,cascade=>true);

如果未指定,size/sample% 是多少??

3.) 在数据库中收集统计数据的一般 practice/frequency 是什么。 (数据每天都在更新、插入、删除)。我还是喜欢每个周末都做。

提前致谢。

是的,ANALYZE现在很少用了:

For the collection of most statistics, use the DBMS_STATS package, which lets you collect statistics in parallel, collect global statistics for partitioned objects, and fine tune your statistics collection in other ways. See Oracle Database PL/SQL Packages and Types Reference for more information on the DBMS_STATS package.

Use the ANALYZE statement (rather than DBMS_STATS) for statistics collection not related to the cost-based optimizer:

  • To use the VALIDATE or LIST CHAINED ROWS clauses

  • To collect information on freelist blocks

如果未指定,size/sample% 是多少??

参数调用estimate_percent:

Percentage of rows to estimate (NULL means compute): The valid range is [0.000001,100]. Use the constant DBMS_STATS.AUTO_SAMPLE_SIZE to have Oracle determine the appropriate sample size for good statistics. This is the default.The default value can be changed using the SET_DATABASE_PREFS Procedure, SET_GLOBAL_PREFS Procedure, SET_SCHEMA_PREFS Procedure and SET_TABLE_PREFS Procedure.

您可以通过函数 DBMS_STATS.get_param('ESTIMATE_PERCENT')DBMS_STATS.GET_PREFS('ESTIMATE_PERCENT')

查询的默认值

默认情况下,Oracle 在安装时创建一个内部调度程序作业,它会在夜间自动收集统计信息。 (称为BSLN_MAINTAIN_STATS_JOB