---
title: "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"
description: "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 neede"
url: "https://hashnode.com/posts/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/6a2da274457244362172f9f5/comment/6a3722c608769ccc8d2b490a"
---

[Discussion](https://hashnode.com/posts/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/6a2da274457244362172f9f5)

Comment [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.](https://hashnode.com/posts/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/6a2da274457244362172f9f5)

[databas](https://hashnode.com/@jkjhiik)

[Jun 20](https://hashnode.com/posts/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/6a2da274457244362172f9f5/comment/6a3722c608769ccc8d2b490a)

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.

[Sharafath Ali](https://hashnode.com/@sharafath)

[Jun 20](https://hashnode.com/posts/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/6a2da274457244362172f9f5/comment/6a3722c608769ccc8d2b490a#reply-6a37250117713937ee285bfd)

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.
