# Using Explain in Postgres

DevFeed: [Using Explain in Postgres](<https://devfeed.tech/articles/using-explain-in-postgres-28221.md>)

Original publisher: [Read original article](<http://fuzzyblog.io/blog/postgres/2020/04/17/using-explain-in-postgres.html>)

Author: Fuzzygroup

Published: 2020-04-17T00:00:00Z

Content type: tutorial

Language: en

Sources: [Scott Johnson](<https://devfeed.tech/sources/scott-johnson.md>)

Topics: [Database](<https://devfeed.tech/topics/database.md>), [Terminal](<https://devfeed.tech/topics/terminal.md>), [Query (disambiguation)](<https://devfeed.tech/topics/query.md>), [MySQL](<https://devfeed.tech/topics/mysql.md>)

Tags: [mysql](<https://devfeed.tech/tags/mysql.md>), [postgres](<https://devfeed.tech/tags/postgres.md>), [sql](<https://devfeed.tech/tags/sql.md>), [terminal](<https://devfeed.tech/tags/terminal.md>)

## AI overview

A practical account of using PostgreSQL EXPLAIN to analyze query plans. The example shows a sequential scan and then adds an index, reducing the scanned rows from 3736 to 36.

## Source excerpt

I've been a MySQL user professionally since 1999 when I abandoned the land of Windows NT server side development due to quality abomination that was Microsoft Site Server - "sh t, fsck, censored, censored, censored -- if Microsoft's quality is this bad, I may as well not pay for software." I can remember that moment with the crystal clear clarity of: a fog of comic book cursing that surrounded me as I worked in my attic garret like office a sense of my life will never be the same again (Open Source to me has had the same type of impact on my life as meeting women that I have loved and having children and discovering Ruby) Ah yes but I digress with the lack of clarity of someone who has slept 8 hours in the past 72 but ... Anyway - MySQL - I've been using explain to analyze queries in MySQL for decades i.e. explain SELECT foo FROM bars WHERE expression a = b And, as of late, I've been using Postgres for many, many projects including CovidNearMe and my professional day job at the ADL and I've been thinking that explain doesn't work because my database client has, for the first time in my life been graphical, Postico, not a raw terminal and I was never able to make explain work in Postico. Note: I just stinking tried this again and Postico has made a liar out of me. Sigh. Honest - explain didn't work like yesterday when I created this blog post. Sigh. Sleep deprivation impacts on cognition; perhaps I should not be driving a motor vehicle today ... So the other day when I need to analyze a query and Google told met hat EXPLAIN was actually a thing, I got out the console and did this: psql -U sjohnson -d covid_morbidity1_development psql (11.5) Type "help" for help. covid_morbidity1_development=# EXPLAIN select max(date_created_at) from locations; QUERY PLAN ---------------------------------------------------------------------- Aggregate (cost=3736.90..3736.91 rows=1 width=4) -> Seq Scan on locations (cost=0.00..3525.32 rows=84632 width=4) (2 rows) Now I don't use Postgres en