DEV Community

Cover image for PostgreSQL: Don't Rush to Index BOOLEAN Columns
Anton Dolganin
Anton Dolganin

Posted on

PostgreSQL: Don't Rush to Index BOOLEAN Columns

It might feel natural to index is_active — but in PostgreSQL, it often does more harm than good.

Why?

BOOLEAN has only three values: true, false, NULL.

If values are evenly distributed (e.g. 50/50), the B-tree index is inefficient. The planner will usually pick a sequential scan instead of using the index.

Index helps when:

  • One value is rare (e.g. 1% are false)
  • Queries target only rare values

Better option: use a partial index

CREATE INDEX idx_inactive ON users (id) WHERE is_active = false;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)