Milan Jovanović 9/19/2026

Adding an Index Made This Query Slower

Read Original

Postgres can choose a slower plan after you add an index, because the planner gains another execution path and can misjudge its cost. Here, an index on created_at DESC looked cheap for an ORDER BY ... LIMIT 10 query, but its scan discarded 495,944 rows and the query went from 16.5ms to 241ms. A composite index on (user_id, created_at DESC) fixes it in 0.067ms. By now, we've all seen examples of AI

0 comments
Adding an Index Made This Query Slower

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet