我有三個方法來構造我的查詢:什麼查詢將是最快的?
第一招:
select obj from table1 where condition1 and obj in (
select obj from table2 where condition2 and obj in (
select obj from table3 where condition3 and obj in (
...
)))
第二個:
select obj from table1 where condition1
and obj in (select obj from table2 where condition2)
and obj in (select obj from table3 where condition3)
...
第三個:
select table1.obj from table1
inner join table2 on table2.obj = table1.obj and table2.condition='condition2'
inner join table3 on table3.obj = table2.obj and table3.condition='condition3'
...
where table1.condition='condition1'
我的問題如果這些查詢提供相同的結果並且這些查詢同樣優化。
我很確定,前兩個查詢產生相同的輸出,但第二個查詢更快。我不確定第三個查詢。
ADDED
還有另一種選擇:
select table1.obj from table1
inner join table2 on table2.obj = table1.obj
inner join table3 on table3.obj = table2.obj
...
where
table1.condition='condition1' and
table2.condition='condition2' and
table3.condition='condition3'
你是否嘗試過所有3個基準測試? – scunliffe 2010-12-17 14:00:52