Loading topic
EXPLAIN shows you that. This chapter covers what EXPLAIN prints, where it fits in the life of a query, and how to use it as your first diagnostic step. Later c6 min readpsql or another client. The examples use PostgreSQL.6 min readEXPLAIN in psql and know that a plan is a tree of nodes. It also assumes you know roughly what an index does. The chapter explains the two numbers after cost= on every plan line, how PostgreSQL computes them, and what they can and can't tell you.6 min readpsql. Here you will learn what the rows= and width= values mean, where they come from, and why a wrong rows= is the most c5 min readEXPLAIN output, and why the planner picks one over another.5 min readcost=startup..total, and have run EXPLAIN ANALYZE before. It covers the nodes that usually sit at the top of a plan: Sort, the aggregate family, and Limit. Their behavior explains many slow queries and many plans that 5 min readEXPLAIN, know what cost and estimated rows mean, and can run SQL in psql or another client. Plain EXPLAIN shows what the planner expects. EXPLAIN ANALYZE shows what happened.6 min readEXPLAIN ANALYZE adds (actual time, actual rows, loops). You should also be comfortable with transactions (BEGIN, COMMIT, ROLLBACK) in psql. The examples use PostgreSQL.6 min readcost, rows and width fields from earlier chapters. It also assumes you can run EXPLAIN (ANALYZE) and read its actual time output. The examples use PostgreSQL.6 min readactual time, rows and loops fields from EXPLAIN ANALYZE. It also assumes you know that PostgreSQL stores tables and indexes in 8 kB pages, called blocks. Timings vary with load and caching. Buffer counts mostly do not, so they are a stead5 min readrows= estimate on each node, and that you have run EXPLAIN ANALYZE in psql. It uses PostgreSQL. It explains where the planner gets its row estimates, so you can tell why an estimate is wrong and which fix to try.5 min readEXPLAIN (ANALYZE, BUFFERS) in PostgreSQL and read a plan as a tree of nodes. It also assumes you know what estimated and actual row counts are. Here you turn a long plan into one answer: which node should I change first?5 min readEXPLAIN and EXPLAIN (ANALYZE, BUFFERS) in PostgreSQL. It also assumes you can read a plan tree and know the scan and join node types. You have already found the node that costs the most. Now you choose a fix.6 min read