Menu
Back to Discussions

Composite indexes: the order matters more than you think

Takeshi Hassan
Takeshi Hassan
·271 views
i recently spent a whole week debugging a critical performance issue that turned out to be a really subtle problem with a composite index in postgresql. we had an index on `(col_a, col_b, col_c)` but our query was filtering on `col_b` and `col_c` without `col_a` in the `where` clause. the optimizer just wasn't using the index effectively. it really reinforced for me that the order of columns in a composite index matters way more than often assumed, especially with multi-column filters and sorts. if your query doesn't match the leading columns of the index, you might as well not have it for certain operations. i wanted to share this reminder: always analyze your query patterns and `explain analyze` outputs when creating composite indexes. it's a small detail that can have huge implications.
0 comments

Comments

Sign in to join the conversation.

Loading comments...