我的哪些查询效率更高?

时间:2013-07-18 05:46:10

标签: sql oracle11g

以下哪个查询更有效,为什么?根据执行计划,他们都有相同的总成本,但我不确定这是否是整体表现的良好指标。

1>

SELECT MIN(ROWID), MAX(ROWID)
FROM tab_a
WHERE status = 0
AND EXISTS (
    SELECT 'X'
    FROM tab_b
    WHERE status = 0
    AND number = assembly_number
    AND ROWID >= :min_rowid
    AND ROWID <= :max_rowid
)
;

2 - ;

SELECT MIN(ROWID), MAX(ROWID)
FROM tab_a
WHERE status = 0
AND assembly_number IN (
    SELECT number
    FROM tab_b
    WHERE status = 0
    AND ROWID >= :min_rowid
    AND ROWID <= :max_rowid
)
;

1 个答案:

答案 0 :(得分:0)

如果将assembly_number编入索引,则后续查询会更好。

SELECT MIN(ROWID), MAX(ROWID)
FROM tab_a
WHERE status = 0
AND EXISTS (
    SELECT 'X'
    FROM tab_b
    WHERE status = 0
    AND number = assembly_number
    AND ROWID >= :min_rowid
    AND ROWID <= :max_rowid
);