1

以下哪个查询更有效,为什么?根据执行计划,它们的总成本相同,但我不确定仅此一项是否是整体性能的良好指标。

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
)
;
4

1 回答 1

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
);
于 2013-07-18T06:05:36.340 回答