Comment by databas on "My PostgreSQL query went from 57ms to 1.4ms on a 1 million + row table. I didn't change the query. Here's what I did." | Hashnode
did u check if the planner just cached the plan after an analyze run. its wierd how often that happens untill u realize the statistics were just stale and needed a quick refresh.
nice point. I actually ran "ANALYZE users;" and executed the query multiple times before taking the before/after samples. Initially the timings were a bit higher and varied, but after refreshing statistics and running the query a few times, they stabilized around the numbers I used. The earlier variance may have been due to stale PostgreSQL statistics and cache warming effects.