PostgreSQL Statistics: Why queries run slow

Every query starts with a plan, and a slow query is usually the result of a bad one. More often than not, stale statistics are to blame. But how does it really work? PostgreSQL doesn&#x27;t run the query to find out - it estimates the cost. It reads pre-computed data from pg_class and pg_statistic and does the maths to figure out the cheapest path to your data. In ideal scenario, the numbers read…