I found an explicit UNION ALL has higher cost than an automatic expansion by inheritance (49 vs. 83 in the example below). Where does the difference come from? Since they have almost same plan trees, should it be the same cost?
=# CREATE TABLE parent (i integer); =# CREATE TABLE child () INHERITS (parent); =# INSERT INTO child SELECT generate_series(1, 1000); =# CREATE INDEX ON child (i); =# ANALYZE; =# EXPLAIN SELECT * FROM parent; QUERY PLAN ---------------------------------------------------------------------------- Result (cost=0.00..49.00 rows=3400 width=4) -> Append (cost=0.00..49.00 rows=3400 width=4) -> Seq Scan on parent (cost=0.00..34.00 rows=2400 width=4) -> Seq Scan on child parent (cost=0.00..15.00 rows=1000 width=4) (4 rows) =# EXPLAIN SELECT * FROM ONLY parent UNION ALL SELECT * FROM child; QUERY PLAN ---------------------------------------------------------------- Append (cost=0.00..83.00 rows=3400 width=4) -> Seq Scan on parent (cost=0.00..34.00 rows=2400 width=4) -> Seq Scan on child (cost=0.00..15.00 rows=1000 width=4) (3 rows) -- Itagaki Takahiro -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers