11<!--
2- $Header: /cvsroot/pgsql/doc/src/sgml/ref/explain.sgml,v 1.8 1999/07/22 15:09:12 thomas Exp $
2+ $Header: /cvsroot/pgsql/doc/src/sgml/ref/explain.sgml,v 1.9 2000/02/15 23:37:49 tgl Exp $
33Postgres documentation
44-->
55
@@ -15,7 +15,7 @@ Postgres documentation
1515 EXPLAIN
1616 </refname>
1717 <refpurpose>
18- Shows statement executiondetails
18+ Shows statement executionplan
1919 </refpurpose>
2020 </refnamediv>
2121
@@ -102,12 +102,32 @@ EXPLAIN
102102 </title>
103103
104104 <para>
105- This command outputs details about the supplied query.
106- The default output is the computed query cost.
107- The cost value is only meaningful to the optimizer in comparing
108- various query plans.
109- VERBOSE displays the full query plan and cost to your screen,
110- and pretty-prints the plan to the postmaster log file.
105+ This command displays the execution plan that the Postgres planner
106+ generates for the supplied query. The execution plan shows how
107+ the table(s) referenced by the query will be scanned --- by plain
108+ sequential scan, index scan etc --- and if multiple tables are
109+ referenced, what join algorithms will be used to bring together
110+ the required tuples from each input table.
111+ </para>
112+
113+ <para>
114+ The most critical part of the display is the estimated query execution
115+ cost, which is the planner's guess at how long it will take to run the
116+ query (measured in units of disk page fetches). Actually two numbers
117+ are shown: the startup time before the first tuple can be returned, and
118+ the total time to return all the tuples. For most queries the total time
119+ is what matters, but in contexts such as an EXISTS sub-query the planner
120+ will choose the smallest startup time instead of the smallest total time
121+ (since the executor will stop after getting one tuple, anyway).
122+ Also, if you limit the number of tuples to return with a LIMIT clause,
123+ the planner makes an appropriate interpolation between the endpoint
124+ costs to estimate which plan is really the cheapest.
125+ </para>
126+
127+ <para>
128+ The VERBOSE option emits the full internal representation of the plan tree,
129+ rather than just a summary (and sends it to the postmaster log file, too).
130+ Usually this option is only useful for debugging Postgres.
111131 </para>
112132
113133 <refsect2 id="R2-SQL-EXPLAIN-3">
@@ -143,7 +163,7 @@ EXPLAIN SELECT * FROM foo;
143163 <computeroutput>
144164NOTICE: QUERY PLAN:
145165
146- Seq Scan on foo (cost=5.22 rows=128 width=4)
166+ Seq Scan on foo (cost=0.00..2.28 rows=128 width=4)
147167
148168EXPLAIN
149169 </computeroutput>
@@ -160,7 +180,7 @@ EXPLAIN SELECT * FROM foo WHERE i = 4;
160180 <computeroutput>
161181NOTICE: QUERY PLAN:
162182
163- Index Scan using fi on foo (cost=2.05 rows=1 width=4)
183+ Index Scan using fi on foo (cost=0.00..0.42 rows=1 width=4)
164184
165185EXPLAIN
166186 </computeroutput>
@@ -178,11 +198,16 @@ EXPLAIN SELECT sum(i) FROM foo WHERE i = 4;
178198 <computeroutput>
179199NOTICE: QUERY PLAN:
180200
181- Aggregate (cost=2.05 rows=1 width=4)
182- -> Index Scan using fi on foo (cost=2.05 rows=1 width=4)
201+ Aggregate (cost=0.42..0.42 rows=1 width=4)
202+ -> Index Scan using fi on foo (cost=0.00..0.42 rows=1 width=4)
183203 </computeroutput>
184204 </programlisting>
185205 </para>
206+
207+ <para>
208+ Note that the specific numbers shown, and even the selected query
209+ strategy, may vary between Postgres releases due to planner improvements.
210+ </para>
186211 </refsect1>
187212
188213 <refsect1 id="R1-SQL-EXPLAIN-3">