format is left as an exercise for the reader.
</para>
<para>
Here is the same plan with cost estimates suppressed:
<programlisting>
EXPLAIN (COSTS FALSE) SELECT * FROM foo WHERE i = 4;
QUERY PLAN
----------------------------
Index Scan using fi on foo
Index Cond: (i = 4)
(2 rows)
</programlisting>
</para>
<para>
Here is an example of a query plan for a query using an aggregate
function:
<programlisting>
EXPLAIN SELECT sum(i) FROM foo WHERE i < 10;
QUERY PLAN
-------------------------------------------------------------------&zwsp;--
Aggregate (cost=23.93..23.93 rows=1 width=4)
-> Index Scan using fi on foo (cost=0.00..23.92 rows=6 width=4)
Index Cond: (i < 10)
(3 rows)
</programlisting>
</para>
<para>
Here is an example of using <command>EXPLAIN EXECUTE</command> to
display the execution plan for a prepared query:
<programlisting>
PREPARE query(int, int) AS SELECT sum(bar) FROM test
WHERE id > $1 AND id < $2
GROUP BY foo;
EXPLAIN ANALYZE EXECUTE query(100, 200);
QUERY PLAN
-------------------------------------------------------------------&zwsp;------------------------------------------------------
HashAggregate (cost=10.77..10.87 rows=10 width=12) (actual time=0.043..0.044 rows=10.00 loops=1)
Group Key: foo
Batches: 1 Memory Usage: 24kB
Buffers: shared hit=4
-> Index Scan using test_pkey on test (cost=0.29..10.27 rows=99 width=8) (actual time=0.009..0.025 rows=99.00 loops=1)
Index Cond: ((id > 100) AND (id < 200))
Index Searches: 1
Buffers: shared hit=4
Planning Time: 0.244 ms
Execution Time: 0.073 ms
(10 rows)
</programlisting>
</para>
<para>
Of course, the specific numbers shown here depend on the actual
contents of the tables involved. Also note that the numbers, and
even the selected query strategy, might vary between
<productname>PostgreSQL</productname> releases due to planner
improvements. In addition, the <command>ANALYZE</command> command
uses random sampling to estimate data statistics; therefore, it is