I am curious as to whether
CREATE INDEX idx ON tbl (columns);
vs.
CREATE UNIQUE INDEX idx ON tbl (columns);
has a significant algorithmic performance benefit in PostgreSQL or MySQL implementations when scanning the indexed column(s), or whether the UNIQUE
keyword simply introduces a unique constraint alongside the index.
I imagine it is probably fair to say that there is a marginal benefit insofar as indexes are likely to be internally implemented as some sort of hash1-like structure, and collision handling by definition result in something other than O(1) performance. Given this premise, it is likely that if a large percentage of values are identical than the structure degenerates into something linear.
So, for purposes of my question, assume that the distribution of values is relatively discrete and uniform.
Thanks in advance!
1 Which is a matter of pure speculation for me, as I am not familiar with RDBM internals.