Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/ref/explain.sgml`
b092eb3c3d8c1ddcb0977e8ffdaf275f51489283ee75d60f0000000100000896
 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 &lt; 10;

                             QUERY PLAN
-------------------------------------------------------------------&zwsp;--
 Aggregate  (cost=23.93..23.93 rows=1 width=4)
   -&gt;  Index Scan using fi on foo  (cost=0.00..23.92 rows=6 width=4)
         Index Cond: (i &lt; 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 &gt; $1 AND id &lt; $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
   -&gt;  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 &gt; 100) AND (id &lt; 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

Title: More EXPLAIN Command Examples: Cost Suppression, Aggregates, and Prepared Queries
Summary
This section provides further examples of using the EXPLAIN command. It demonstrates how to suppress cost estimates in the output, how EXPLAIN works with queries involving aggregate functions, and how to use EXPLAIN EXECUTE to display the execution plan for prepared queries with specified parameters. The output includes cost estimates, row counts, and timing information. It also notes that the specific values may depend on the data and PostgreSQL version.