Unsupported versions: 7.0 / 6.5 / 6.4
This documentation is for an unsupported version of PostgreSQL.
You may want to view the same page for the current version, or one of the other supported versions listed above instead.

EXPLAIN

Name

EXPLAIN — Shows statement execution details
EXPLAIN [ VERBOSE ] query        
  

Inputs

VERBOSE

Flag to show detailed query plan.

query

Any query.

Outputs

NOTICE: QUERY PLAN: 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:

EXPLAIN select * from foo;
NOTICE:  QUERY PLAN:

Seq Scan on foo  (cost=0.00 rows=0 width=4)

EXPLAIN
   

Compatibility

SQL92

There is no EXPLAIN statement defined in SQL92.