Y
Hacker News
new
|
ask
|
show
|
jobs
by
mjw1007
1968 days ago
Summary: if you have an index on a column which is mostly NULL, consider using a partial index covering only the records where it's non-NULL.
2 comments
latch
1968 days ago
Another benefit of partial indexes is to limit a unique constraint:
create index users_email on users(email) where status != 'delete'
link
SomeHacker44
1968 days ago
Be very careful, then, as the optimizer will (usually?) not use the index if the condition is not part if the query.
link
jackTheMan
1967 days ago
you can create views for that, then it will be always part of the query.
link
cakoose
1967 days ago
That's the part they sold in the title, but there's a bunch of other useful stuff for someone operating Postgres in production, something I'll need to do in a few months.
link
create index users_email on users(email) where status != 'delete'