UNION ALL has higher cost than inheritance - Mailing list pgsql-hackers

From Itagaki Takahiro
Subject UNION ALL has higher cost than inheritance
Date
Msg-id AANLkTi=hjgL=GYPumF2_Kf6DWOFLVE0rQgz-p5VFLFYn@mail.gmail.com
Whole thread Raw
Responses Re: UNION ALL has higher cost than inheritance
List pgsql-hackers
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
Scanon 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


pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Extensions, this time with a patch
Next
From: "David E. Wheeler"
Date:
Subject: Re: Extensions, this time with a patch