summaryrefslogtreecommitdiff
path: root/doc/src/sgml/ref/explain.sgml
diff options
context:
space:
mode:
Diffstat (limited to 'doc/src/sgml/ref/explain.sgml')
-rw-r--r--doc/src/sgml/ref/explain.sgml56
1 files changed, 49 insertions, 7 deletions
diff --git a/doc/src/sgml/ref/explain.sgml b/doc/src/sgml/ref/explain.sgml
index 7f57112570..cc73bcf7ff 100644
--- a/doc/src/sgml/ref/explain.sgml
+++ b/doc/src/sgml/ref/explain.sgml
@@ -1,6 +1,11 @@
+<!--
+$Header: /cvsroot/pgsql/doc/src/sgml/ref/explain.sgml,v 1.8 1999/07/22 15:09:12 thomas Exp $
+Postgres documentation
+-->
+
<refentry id="SQL-EXPLAIN">
<refmeta>
- <refentrytitle>
+ <refentrytitle id="SQL-EXPLAIN-TITLE">
EXPLAIN
</refentrytitle>
<refmiscinfo>SQL - Language Statements</refmiscinfo>
@@ -16,7 +21,7 @@
<refsynopsisdiv>
<refsynopsisdivinfo>
- <date>1998-09-01</date>
+ <date>1999-07-20</date>
</refsynopsisdivinfo>
<synopsis>
EXPLAIN [ VERBOSE ] <replaceable class="PARAMETER">query</replaceable>
@@ -95,6 +100,7 @@ EXPLAIN
<title>
Description
</title>
+
<para>
This command outputs details about the supplied query.
The default output is the computed query cost.
@@ -127,16 +133,54 @@ EXPLAIN
<title>
Usage
</title>
+
+ <para>
+ To show a query plan for a simple query on a table with a single
+ <type>int4</type> column and 128 rows:
+
+ <programlisting>
+EXPLAIN SELECT * FROM foo;
+ <computeroutput>
+NOTICE: QUERY PLAN:
+
+Seq Scan on foo (cost=5.22 rows=128 width=4)
+
+EXPLAIN
+ </computeroutput>
+ </programlisting>
+ </para>
+
<para>
- To show a query plan for a simple query:
+ For the same table with an index to support an
+ <firstterm>equijoin</firstterm> condition on the query,
+ <command>EXPLAIN</command> will show a different plan:
<programlisting>
-EXPLAIN select * from foo;
+EXPLAIN SELECT * FROM foo WHERE i = 4;
+ <computeroutput>
NOTICE: QUERY PLAN:
-Seq Scan on foo (cost=0.00 rows=0 width=4)
+Index Scan using fi on foo (cost=2.05 rows=1 width=4)
EXPLAIN
+ </computeroutput>
+ </programlisting>
+ </para>
+
+ <para>
+ And finally, for the same table with an index to support an
+ <firstterm>equijoin</firstterm> condition on the query,
+ <command>EXPLAIN</command> will show the following for a query
+ using an aggregate function:
+
+ <programlisting>
+EXPLAIN SELECT sum(i) FROM foo WHERE i = 4;
+ <computeroutput>
+NOTICE: QUERY PLAN:
+
+Aggregate (cost=2.05 rows=1 width=4)
+ -> Index Scan using fi on foo (cost=2.05 rows=1 width=4)
+ </computeroutput>
</programlisting>
</para>
</refsect1>
@@ -145,8 +189,6 @@ EXPLAIN
<title>
Compatibility
</title>
- <para>
- </para>
<refsect2 id="R2-SQL-EXPLAIN-4">
<refsect2info>