Lesson 2 of 11 · 22 min
Reading EXPLAIN plans
By the end of this lesson you can read an EXPLAIN plan from the leaves to the root, name what each common node does (Seq Scan, Index Scan, Sort, HashAggregate, Hash Join, Nested Loop), and explain what the cost, rows and width numbers mean.
Put EXPLAIN in front of a query and PostgreSQL returns its plan instead of the result. The query is planned but not run, so EXPLAIN is instant and safe, even for an UPDATE or DELETE.
A plan is a tree. Each line that starts a node names an operation; indented lines starting with -> are its children, which feed it rows. The node at the top produces the final result.
This lesson, its 3 graded exercises and every other Members lesson in SQL Quest come with a Formula Quest membership that includes SQL (Single Quest with SQL selected, Quest Trio including SQL, or Quest Unlimited), or with SQL access from your organization.
Free to everyone: all of SQL Foundations and Retrieving and Filtering Data, the first lesson of every track, the playground, the dataset library and the SQL reference. See free lessons