EXPLAIN(l) EXPLAIN(l)
NAME
EXPLAIN - Shows statement execution details
SYNOPSIS
EXPLAIN [ VERBOSE ] query
INPUTS
VERBOSE
Flag to show detailed query plan.
query Any query.
OUTPUTS
NOTICE: QUERY PLAN:
Explicit query plan from the Postgres backend.
EXPLAIN
Flag sent after query plan is shown.
DESCRIPTION
This command outputs details about the supplied query.
The default output is the computed query cost. The cost
value is only meaningful to the optimizer in comparing
various query plans. VERBOSE displays the full query plan
and cost to your screen, and pretty-prints the plan to the
postmaster log file.
NOTES
There is only sparse documentation on the optimizer's use
of cost information in Postgres. General information on
cost estimation for query optimization can be found in
database textbooks. Refer to the Programmer's Guide in
the chapters on indexes and the genetic query optimizer
for more information.
USAGE
To show a query plan for a simple query on a table with a
single int4 column and 128 rows:
EXPLAIN SELECT * FROM foo;
NOTICE: QUERY PLAN:
Seq Scan on foo (cost=5.22 rows=128 width=4)
EXPLAIN
For the same table with an index to support an equijoin
condition on the query, EXPLAIN will show a different
plan:
EXPLAIN SELECT * FROM foo WHERE i = 4;
NOTICE: QUERY PLAN:
Index Scan using fi on foo (cost=2.05 rows=1 width=4)
EXPLAIN
And finally, for the same table with an index to support
an equijoin condition on the query, EXPLAIN will show the
following for a query using an aggregate function:
EXPLAIN SELECT sum(i) FROM foo WHERE i = 4;
NOTICE: QUERY PLAN:
Aggregate (cost=2.05 rows=1 width=4)
-> Index Scan using fi on foo (cost=2.05 rows=1 width=4)
COMPATIBILITY
SQL92
There is no EXPLAIN statement defined in SQL92.
SQL - Language Statements 15 August 1999 1