UNION ALL has higher cost than inheritance

From: Itagaki Takahiro <itagaki(dot)takahiro(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: UNION ALL has higher cost than inheritance
Date: 2010-10-21 05:02:39
Message-ID: AANLkTi=hjgL=GYPumF2_Kf6DWOFLVE0rQgz-p5VFLFYn@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David E. Wheeler 2010-10-21 05:10:55 Re: Extensions, this time with a patch
Previous Message Alvaro Herrera 2010-10-21 04:58:26 Re: Extensions, this time with a patch