简体   繁体   English

DBMS_STATS.GATHER_TABLE_STATS如何在Oracle中工作

[英]How DBMS_STATS.GATHER_TABLE_STATS works in oracle

I need clarification on how DBMS_STATS.GATHER_TABLE_STATS works. 我需要澄清DBMS_STATS.GATHER_TABLE_STATS的工作方式。 I have a scenario,were i am creating table and the same table is used in the package creation also.In other words the package compilation is depended on table creation. 我有一个场景,正在创建表,并且在包创建中也使用了相同的表。换句话说,包编译取决于表创建。

Is it mandatory to include DBMS_STATS.GATHER_TABLE_STATS after index creation command in table creation script. 在表创建脚本中的索引创建命令之后是否必须包含DBMS_STATS.GATHER_TABLE_STATS。

In which situation DBMS_STATS.GATHER_TABLE_STATS works,whether it's for package compilation or package execution.Please confirm. DBMS_STATS.GATHER_TABLE_STATS在哪种情况下适用,无论是用于程序包编译还是程序包执行。请确认。

DBMS_STATS provides information to the Oracle optimizer, enabling Oracle to build efficient execution plans for SQL statements. DBMS_STATS向Oracle优化器提供信息,使Oracle能够为SQL语句建立有效的执行计划。 Optimizer statistics are never necessary for compiling objects. 优化器统计信息对于编译对象从不需要。

Gathering statistics is such a complicated subject it can be difficult to even ask the right questions at first. 收集统计信息是如此复杂,一开始甚至很难提出正确的问题。 I'd recommend starting by reading the manual, such as Managing Optimizer Statistics: Basic Topics . 我建议您先阅读该手册,例如《 管理优化工具统计信息:基本主题》

Typically your statistics gathering strategy should look something like this: 通常,您的统计信息收集策略应如下所示:

  1. Gather statistics manually whenever an object's data significantly changes. 每当对象的数据发生重大变化时,请手动收集统计信息。
  2. Use the default autotask to automatically gather statistics for objects that have been slowly changing or were accidentally forgotten. 使用默认的自动任务,可以自动收集那些变化缓慢或意外遗忘的对象的统计信息。

To answer some specific questions, you probably do not want to gather statistics right after creating a table. 要回答一些具体的问题,你可能希望在创建表后立即收集统计信息。 Only gather statistics after changing the data. 仅在更改数据后收集统计信息。 Gathering statistics on an empty table can be dangerous; 在空表上收集统计信息可能很危险; Oracle will think the table has 0 rows until the next time statistics are gathered. Oracle将认为该表具有0行,直到下次收集统计信息为止。 It would be better to have no statistics at all, then Oracle can use dynamic sampling to estimate the statistics. 最好完全没有统计信息,然后Oracle可以使用动态采样来估计统计信息。

(But on the other hand, if the table is created as a SELECT statement and contains a lot of data you may want to gather statistics. Then again, if you're using 12c it might gather statistics automatically when creating a table.) (但是,另一方面,如果该表是作为SELECT语句创建的,并且包含许多数据,则可能要收集统计信息。然后,如果使用的是12c,则它可能会在创建表时自动收集统计信息。)

You also generally do not need to gather statistics after creating an index. 创建索引后,通常也不需要收集统计信息。 Oracle automatically gathers index statistics when an index is created or rebuilt. 创建或重建索引时,Oracle会自动收集索引统计信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Postgresql与Oracle中的dbms_stats.gather_table_stats等效什么? - what is equivalent of Postgresql to dbms_stats.gather_table_stats in Oracle? 有关dbms_stats.gather_table_stats的问题 - Question regarding dbms_stats.gather_table_stats 在Oracle过程中交换分区后的Dbms_Stats.Gather_Table_Stats吗? - Dbms_Stats.Gather_Table_Stats after partition exchange in Oracle procedure? Oracle 19C dbms_stats.gather_table_stats 缓慢并返回无效标识符错误 - Oracle 19C dbms_stats.gather_table_stats Slowness and return invalid identifier error 如何解决存储过程在通过 EXECUTE IMMEDIATE 作为字符串执行时不执行 dbms_stats.gather_table_stats() 的问题 - How to resolve issue of stored proc not executing dbms_stats.gather_table_stats() when executing as it string via EXECUTE IMMEDIATE LAST_ANALYZE null 在 dbms_stats.gather_table_stats 之后 - LAST_ANALYZE null after dbms_stats.gather_table_stats 为什么在 SSB 模式中的表上运行 dbms_stats.gather_table_stats 时会出现 ORA-20000? - Why do I get ORA-20000 when I run dbms_stats.gather_table_stats on a table in SSB Schema? Oracle GATHER_SCHEMA_STATS的工作原理 - How Oracle GATHER_SCHEMA_STATS works 使用dbms_stats.gather_schema_stats [oracle] - Using dbms_stats.gather_schema_stats [oracle] Oracle PLSQL,在 DBMS_STATS.GATHER_SCHEMA_STATS 中选择 - Oracle PLSQL, select in DBMS_STATS.GATHER_SCHEMA_STATS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM