Menu

Post image 1
Post image 2
1 / 2
0

Indexing every WHERE column is not PostgreSQL optimization

DEV Community·bertrand HARTWIG·21 days ago
#LZc1ljvk
Reading 0:00
15s threshold
Cover image for Indexing every WHERE column is not PostgreSQL optimization

bertrand HARTWIG

One PostgreSQL indexing mistake I see often:

“The query filters on A, B and C, so let’s create an index on A, B, C.”

That may work, but it may also be the wrong index.

For composite B-tree indexes, PostgreSQL cares about predicate type, column order, selectivity, table size, and the actual execution plan.

In this post, I explain why equality predicates usually belong before range predicates, why n_distinct from statistics matters, and why a theoretically good index is useless if the planner never uses it.

I also show how pgAssistant turns this into an automated index recommendation workflow using EXPLAIN ANALYZE and planner statistics.

Full write-up:
https://beh74.github.io/pgassistant-blog/post/query_advisor/

Read More