Oracle 表统计信息收集

发布于 2024-07-04 04:12:47 字数 86 浏览 8 评论 0原文

对于 Oracle 版本 9 及更高版本,应何时以及如何执行表统计信息收集? 您将如何收集大型数据库的统计信息,其中统计信息的收集会与“工作时间”发生冲突。

When and how should table stats gathering be performed for Oracle, version 9 and up? How would you go about gathering stats for a large database, where stats gathering would collide with "business hours".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梅窗月明清似水 2024-07-11 04:12:47

我不同意在进行大量删除或插入后您应该始终重建统计信息。 一如既往,这取决于。 在数据仓库情况下,当重新构建物化视图时,您将进行大量删除和插入,但数据的基本结构不会改变。

仅当表的内容发生重大变化时,您才需要重新计算表的统计信息。 这并不一定意味着在大量删除或插入之后,而是当删除、插入或更新实质上改变了可能的执行计划的内容时。

如果您要截断表并重建(这将重置您的统计信息),则通常最好在重建表后截断和恢复统计信息之前存储统计信息,而不是进行昂贵的统计计算。

为了保存当前的统计视图,您可以使用:

dbms_stats.export_table_stats

并在之后恢复它们,您可以使用:(

dbms_stats.import_table_stats

对于模式数据库有相应的过程。)

I don't agree that you should always rebuild your statistics after there have been lots of deletes or inserts. As ever, it depends. In a data warehouse situation, when re-building your materialized views you will be doing lots of deletes and inserts but the base structure of the data will not change.

You only need to re-calculate statistics on a table if there has been a significant change in its content. This does not necessarily mean after lots of deletes or inserts, but rather when deletes, inserts, or updates materially change the content with respect to possible execution plans.

If you are truncating tables and rebuilding (which will reset your statistics), instead of an expensive statistics calculation, you're often better off storing the statistics before truncating and restoring them once you've rebuilt the table.

For saving the current views of statistics you use:

dbms_stats.export_table_stats

and to restore them afterwards you use:

dbms_stats.import_table_stats

(There are corresponding procedures for schema and database.)

维持三分热 2024-07-11 04:12:47

每当数据内容发生较大更改(例如大量删除或插入)时,就应该收集统计信息。 如果表结构发生了变化,您也应该收集统计信息。 建议使用“估计”选项。

如果可能的话,请在非工作时间以自动化流程执行此操作,或者如果您必须在工作时间内执行此操作,请选择对您希望收集统计数据的表的访问权限最少的时间。

Gathering stats should be done whenever there has been large changes to the data content, for example a large number of deletes or inserts. If the table structure has changed you should gather stats also. It is advisable to use the 'ESTIMATE' option.

Do this as an automated process out of business hours if possible, or if you have to do it during business hours then choose a time when there is minimum access to the tables you wish to gather stats for.

长发绾君心 2024-07-11 04:12:47

确保在使用估计值 (sample_percent) 时至少收集到 10%。 低于这个值可能会产生非常值得怀疑的结果。

Make sure when using the estimate (sample_percent) that you gather at least 10 percent. Below that can yield very questionable results.

不及他 2024-07-11 04:12:47

收集时考虑备份当前统计数据 - 这样您就可以比较它们(如果您感兴趣),并且在新统计数据引起问题时可能恢复它们。 请记住,统计信息用于确定执行计划 - 如果您希望执行计划更改,您可能只想收集它们。

Consider backing up current stats when gathering -- that way you can compare them (if you're interested) and possibly restore them if your new stats cause problems. Keep in mind that stats are used to determine execution plans -- you may only want to gather them if you want execution plans to change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文