DEV Community

Discussion on: Database Indexes, please be careful when using it!

Collapse
 
darkain profile image
Vincent Milum Jr

If you have low cardinality of your data, in PostgreSQL, you can use a partial index instead.

In your example, you have 2 items on one side, and 998 on the other. This is the perfect scenario for a partial index. This has the ability to store an index for the 2 items, while ignoring the other 998 rows. So instead of creating 1000 index entries, only 2 are created, keeping storage usage minimal, AND still retaining the performance benefits!

postgresql.org/docs/current/indexe...

Collapse
 
frasnym profile image
Frastyawan Nym

Thanks for the addition Vincent!

I didn't know before that we could create conditions on index