PostgreSQL

Скачать в pdf «PostgreSQL»


Usage


To show a query plan for a simple query on a table with a single int4 column and 128 rows:


EXPLAIN SELECT * FROM foo;


NOTICE: QUERY PLAN:


Seq Scan on foo (cost=0.00..2.28 rows=128 width=4)


explain


For the same table with an index to support an equijoin condition on the query, EXPLAIN will show a different plan:


explain select * from foo where i = 4;


NOTICE: QUERY PLAN:


Index Scan using fi on foo (cost=0.00..0.42 rows=1 width=4)


EXPLAIN


And finally, for the same table with an index to support an equijoin condition on the query, EXPLAIN will show the following for a query using an aggregate function:


EXPLAIN SELECT sum(i) FROM foo WHERE i = 4;


NOTICE: QUERY PLAN:


Aggregate (cost=0.42..0.42 rows=1 width=4) -> Index Scan using fi on foo (cost=0.00..0.42 rows=1 width=4)


Note that the specific numbers shown, and even the selected query strategy, may vary between Postgres releases due to planner improvements.


Compatibility


SQL92


There is no EXPLAIN statement defined in SQL92.

D.52 FETCH


Name


FETCH — Gets rows using a cursor


FETCH [ direction ] [ count ] { IN | FROM } cursor


FETCH [ FORWARD | BACKWARD | RELATIVE ] [ { [ # | ALL | NEXT | PRIOR ] } ] { IN | FROM } cursor


Inputs


direction selector defines the fetch direction. It can be one of the following:

Скачать в pdf «PostgreSQL»