Re: optimizing select ... not in (select ...)

Поиск
Список
Период
Сортировка
От Laurent Martelli
Тема Re: optimizing select ... not in (select ...)
Дата
Msg-id 87zo93apeo.fsf@lolo.aopsys
обсуждение исходный текст
Ответ на Re: optimizing select ... not in (select ...)  (Tomas Berndtsson <tomas@nocrew.org>)
Список pgsql-sql
>>>>> "Tomas" == Tomas Berndtsson <tomas@nocrew.org> writes:
 Tomas> Laurent Martelli <laurent@aopsys.com> writes: >> I have this query : >>  >> select distinct on
(Pictures.PictureID)* from Pictures where >> Pictures.PictureID not in (select distinct PictureID from >> Keywords); >>
>> and I find it a bit slow. Does anybody have suggestions to run >> this faster ? (I have indexes on PictureID on both
Picturesand >> Keywords)
 
 Tomas> Try this instead:
 Tomas> select distinct on (Pictures.PictureID) * from Pictures where Tomas> not exists (select distinct PictureID from
Keywordswhere Tomas> Pictures.PictureID=Keywords.PictureID);
 
 Tomas> I've found that it's usually faster, probably because it can Tomas> use indices better.

It is indeed much faster. Thanks to all of you who answered so fast. 

-- 
Laurent Martelli
laurent@aopsys.com              http://www.bearteam.org/~laurent/


В списке pgsql-sql по дате отправления:

Предыдущее
От: Bruce Momjian
Дата:
Сообщение: Re: optimizing select ... not in (select ...)
Следующее
От: "Josh Berkus"
Дата:
Сообщение: Eh?