HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Index on Column with only 3 status?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
columnwithstatusindexonly

Problem

I have a table with millions of rows. This table has a column which we frequently filter(means we use it in WHERE clause frequently), the values are Insert/Update/Ignored. Is it make sense to add index to columns? Someone told me adding index on few values column have no benefit

Solution

Adding index on low cardinality column can make sense for instance in case you need to search for value which is quite rare - say you have column State with possibities of New/Processed and 95% rows set as Processed, and you have to get those New often - then index will help you find them fast. But having it present means optimizer can try to use in bad cases.

Usually it is suggested to not index such column by itself, but use it as part of multicolumn index which can help specific queries (for instance - you want to process those new records from oldest to newest, then you add index on (State, CreatedTime) and query it like "where State = 'New' order by CreatedTime ASC" and this index will let you have those New fast and already ordered.

Context

StackExchange Database Administrators Q#101094, answer score: 4

Revisions (0)

No revisions yet.