Result

Sometimes, a node just needs to return a result computed by a statement:

EXPLAIN ANALYZE SELECT 1;
QUERY PLAN 
----------
Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.003..0.005 rows=1 loops=1)
Total runtime: 0.038 ms

Result nodes are basically quick pass through nodes when individual values are being operated on, instead of sets of rows. They can be used to collapse and therefore optimize sections of a WHERE clause that can be computed once:

EXPLAIN ANALYZE SELECT * FROM customers WHERE customerid=(SELECT min(customerid) FROM customers)+1;
QUERY PLAN                                                         
----------
Index Scan using customers_pkey on customers  (cost=0.06..8.33 rows=1 width=268) (actual time=0.085..0.088 rows=1 loops=1)
    Index Cond: (customerid = ($1 + 1))
    InitPlan ...

Get PostgreSQL 10 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.