Re: Q: Table scans on set difference

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Q: Table scans on set difference
Дата
Msg-id 20529.1152891383@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Q: Table scans on set difference  (Alban Hertroys <alban@magproductions.nl>)
Список pgsql-general
Alban Hertroys <alban@magproductions.nl> writes:
> G. Ralph Kuntz, MD wrote:
>> explain select file_name from encounter_properties_table where file_name not
>> in (select filename from xfiles);

> What about:
> explain select file_name from encounter_properties_table
> where not exists (
>     select file_name from xfiles where filename = file_name);

If you only need the file name, an EXCEPT would probably work much
better:

select file_name from encounter_properties_table
except
select filename from xfiles;

Another possibility is to abuse the outer join machinery:

select file_name, ... from
    encounter_properties_table l left join xfiles r
      on l.file_name = r.filename
where r.filename is null;

Generally speaking, NOT IN performance is going to suck unless the
sub-select is small enough to fit in a hashtable.  You could consider
increasing work_mem enough that it would fit, but with 500K filenames
needed, that's probably not going to win.

            regards, tom lane

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

Предыдущее
От: Florian Weimer
Дата:
Сообщение: Re: Timestamp vs timestamptz
Следующее
От: Tom Lane
Дата:
Сообщение: Re: apparent wraparound