Thread: [HACKERS] Partition : Append node over a single SeqScan

[HACKERS] Partition : Append node over a single SeqScan

From
Ashutosh Sharma
Date:
Hi All,

Today while exploring a bit on Range table partitioning, I could see
that even if scan is performed on a single partition, the plan node
has Append node in it. Isn't it a bug?

As per the usage of Append Node, it should only be seen in the
queryplan when scan is performed on multiple tables.

Following are the steps to reproduce the problem.

CREATE TABLE part_tab (c1 int, c2 int) PARTITION BY RANGE (c1);

CREATE TABLE part1 PARTITION OF part_tab FOR VALUES FROM (0) TO (100);

CREATE TABLE part2 PARTITION OF part_tab FOR VALUES FROM (100) TO (200);

postgres=# explain analyze select * from part_tab where c1 > 100;                                              QUERY
PLAN
--------------------------------------------------------------------------------------------------------Append
(cost=0.00..38.25rows=753 width=8) (actual time=0.009..0.009
 
rows=0 loops=1)  ->  Seq Scan on part2  (cost=0.00..38.25 rows=753 width=8) (actual
time=0.009..0.009 rows=0 loops=1)        Filter: (c1 > 100)Planning time: 166698.973 msExecution time: 0.043 ms
(5 rows)

-- 
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com



Re: [HACKERS] Partition : Append node over a single SeqScan

From
Ashutosh Bapat
Date:
On Wed, Jul 5, 2017 at 3:48 PM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
> Hi All,
>
> Today while exploring a bit on Range table partitioning, I could see
> that even if scan is performed on a single partition, the plan node
> has Append node in it. Isn't it a bug?

No. See following comment from create_append_plan()
1045     /*
1046      * XXX ideally, if there's just one child, we'd not bother to
generate an
1047      * Append node but just return the single child.  At the
moment this does
1048      * not work because the varno of the child scan plan won't match the
1049      * parent-rel Vars it'll be asked to emit.
1050      */

--
Best Wishes,
Ashutosh Bapat
EnterpriseDB Corporation
The Postgres Database Company



Re: [HACKERS] Partition : Append node over a single SeqScan

From
Ashutosh Sharma
Date:
Hi,

On Wed, Jul 5, 2017 at 3:58 PM, Ashutosh Bapat
<ashutosh.bapat@enterprisedb.com> wrote:
> On Wed, Jul 5, 2017 at 3:48 PM, Ashutosh Sharma <ashu.coek88@gmail.com> wrote:
>> Hi All,
>>
>> Today while exploring a bit on Range table partitioning, I could see
>> that even if scan is performed on a single partition, the plan node
>> has Append node in it. Isn't it a bug?
>
> No. See following comment from create_append_plan()
> 1045     /*
> 1046      * XXX ideally, if there's just one child, we'd not bother to
> generate an
> 1047      * Append node but just return the single child.  At the
> moment this does
> 1048      * not work because the varno of the child scan plan won't match the
> 1049      * parent-rel Vars it'll be asked to emit.
> 1050      */
>

Thanks for the information.

--
With Regards,
Ashutosh Sharma
EnterpriseDB:http://www.enterprisedb.com