3

我对在 Oracle 10 数据库中看到的东西感到非常困惑。

我有以下查询。

select
t2.duplicate_num
from table1 t1, table2 t2,

( 
   select joincriteria_0 from intable1 it1, intable2 it2 
   where it2.identifier in (4496486,5911382) 
   and it1.joincriteria_0 = it2.joincriteria_0 
   and it1.filter_0 = 1 
) tt

where t1.joincriteria_0 = tt.joincriteria_0
and t2.joincriteria_1 = t1.joincriteria_1
and t2.filter_0 = 3
and t2.filter_1 = 1
and t2.filter_2 not in (48020)

对我来说,这似乎并没有什么特别之处,以下是来自 autotrace 的基线性能数据:

CR_GETS:318

中央处理器:3

行数:33173

现在,如果我将“DISTINCT”关键字添加到查询中(例如“选择不同的 t2.duplicate_num ...”),就会发生这种情况

CR_GETS:152921

中央处理器:205

行数:305

查询计划没有改变,但逻辑 IO 增长了 500 倍。我原以为 CPU 只会上升,而逻辑 IO 基本没有变化。

最终结果是使用 distinct 关键字运行速度慢 10-100 倍的查询。我可以将代码放入应用程序中,这将使结果集在很短的时间内变得不同。这有什么意义?特别是在查询计划没有改变的情况下?

4

1 回答 1

0

这表明某处缺少索引。这也意味着,您的原始查询没有 distinct 子句没有优化。使用“distinct”也无法优化,因此查询计划保持不变。由于全表扫描,未优化查询的性能差异很大。

于 2012-10-01T21:15:18.143 回答