У меня есть три способа построения мой запрос:Какой запрос будет самым быстрым?
Первый:
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'
Мои вопросы если эти запросы дают одинаковый результат, и если эти запросы одинаково оптимальны.
Я уверен, что первые два запроса производят один и тот же вывод, но второй запрос выполняется быстрее. Не уверен в третьем запросе.
ДОБАВЛЕНО
Существует также другой вариант:
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