[英]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: 通常,您的统计信息收集策略应如下所示:
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.