Re: FK v.s unique indexes

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: FK v.s unique indexes
Дата
Msg-id CAKFQuwatvdZ5xfLVa8h5P9ThaPuoKrUwYG5M2GErh+V7Pq18VA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: FK v.s unique indexes  (Rafal Pietrak <rafal@ztk-rp.eu>)
Ответы Re: FK v.s unique indexes
Список pgsql-general
On Thu, Jul 5, 2018 at 1:45 PM, Rafal Pietrak <rafal@ztk-rp.eu> wrote:
I was thinking, that when "add constraint" cannot choose appropriate
index, may be some explicit help (like ... using <index_name>;) would be
due.

​Basically all the FK trigger does is:

SELECT EXISTS(SELECT 1 FROM pk_table WHERE pk_col1 = val1 AND pk_col2 = val2)

And fails if query returns false.  The planner is still free to use the index or not to execute the query just as if you had written it by hand.  For a small table fully in memory it likely would prefer a sequential scan and it would be perfectly within its rights to do so.

David J.

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

Предыдущее
От: Rafal Pietrak
Дата:
Сообщение: Re: FK v.s unique indexes
Следующее
От: Rafal Pietrak
Дата:
Сообщение: Re: FK v.s unique indexes