Hacker News new | ask | show | jobs
by navium 3092 days ago
"There’s no need to manually create indexes on columns already declared unique; doing so would just duplicate the automatically-created index." Is the last part real? Makes me feel like forking postgesql just to save the world from accidental duplicate expensive indexes.
2 comments

An index is usually the most efficient way to check for uniqueness, so most databases do in fact handle this constraint with an index. Some of them will also automatically reuse this index if you manually try to create one for the same column.
Yes, in PG at least an index is created, otherwise the unique check would become prohibitive.
I think the question is more on whether a duplicate index would be created instead of having the unique constraint and primary key designation on the same column share an index