| От | PFC |
|---|---|
| Тема | Re: Creating a foreign key |
| Дата | |
| Msg-id | op.uaupyxsecigqcu@apollo13.peufeu.com обсуждение |
| Ответ на | Creating a foreign key ("Campbell, Lance" <lance@uiuc.edu>) |
| Список | pgsql-performance |
> When you create a foreign key to a table is there an index that is
> created on the foreign key automatically?
No, Postgres doesn't do it for you, because if you create (ref_id)
references table.id, you will perhaps create an index on (ref_id, date)
which would then fill the purpose (and other purposes), or perhaps your
table will have 10 rows (but postgres doesnt' know that when you create
it) and having an index would be useless, or your table could have many
rows but only a few distinct referenced values, in which case again the
index would only slow things down.
PG does not presume to know better than yourself what you're gonna do
with your data ;)
UNIQUE and PRIMARY KEY do create UNIQUE INDEXes, of course.
В списке pgsql-performance по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера