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

Another benefit of partial indexes is to limit a unique constraint:

create index users_email on users(email) where status != 'delete'

Be very careful, then, as the optimizer will (usually?) not use the index if the condition is not part if the query.
you can create views for that, then it will be always part of the query.
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.