oracle 10g 和 9i 之间巨大的查询执行时间差异
我正在运行以下查询:
SELECT * FROM all_tab_cols c
LEFT JOIN all_varrays v ON c.owner = v.owner
AND c.table_name = v.parent_table_name
AND c.column_name = v.parent_table_column
在 10g 服务器上,这需要大约 2 秒,在 9i 上,这需要 819 秒(13 分钟)!到底是什么导致了如此巨大的性能差异,我该如何解决它?
I'm running the following query:
SELECT * FROM all_tab_cols c
LEFT JOIN all_varrays v ON c.owner = v.owner
AND c.table_name = v.parent_table_name
AND c.column_name = v.parent_table_column
On a 10g server this takes ~2s, on 9i this takes 819s (13 mins)! What on earth is causing this huge performance difference, and how can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
事实证明,默认情况下,9i 没有系统表的统计信息,而 10g+ 有。这就是导致性能差异的原因 - Oracle 不知道应该如何正确地连接它。
It turns out that, by default, 9i doesn't have statistics on the system tables, whereas 10g+ does. This is what's causing the performance difference - Oracle doesn't know how it should be joining it correctly.
造成这种差异的一种可能的解释是数据字典统计数据。在 10g Oracle 中引入了 DBMS_STATS.GATHER_DICTIONARY_STATS() 过程,它根据 SYS 和 SYSTEM 模式(以及其他一些模式)收集统计信息。对数据字典进行统计可以改进针对数据库视图的某些查询的执行计划。
即使您运行 DBMS_STATS.GATHER_DATABASE_STATS(),它仍然会收集数据字典的统计信息,除非您显式地将
gather_sys
参数设置为false
。您可以使用以下查询检查针对 10g 数据库运行了哪些统计信息收集操作:
One potential explanation for the disparity is data dictionary stats. In 10g Oracle introduced the DBMS_STATS.GATHER_DICTIONARY_STATS() procedure, which gathers stats against the SYS and SYSTEM schemas (and some others). Having statistics on the data dictionary could result in an improved execution plan for some queries against database views.
Even if you run DBMS_STATS.GATHER_DATABASE_STATS() it still gathers stats for the data dictionary, unless you explicitly set the
gather_sys
parameter tofalse
.You can check what statistics gather operations have been run against the 10g database with this query: