Re: [HACKERS] Runtime Partition Pruning
Beena Emerson <memissemerson@gmail.com>
From: Beena Emerson <memissemerson@gmail.com>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: amul sul <sulamul@gmail.com>, "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>,
Dilip Kumar <dilipbalaut@gmail.com>
Date: 2017-11-29T11:35:31Z
Lists: pgsql-hackers
On Tue, Nov 14, 2017 at 6:27 PM, David Rowley
<david.rowley@2ndquadrant.com> wrote:
> On 14 November 2017 at 19:16, Beena Emerson <memissemerson@gmail.com> wrote:
>> PFA the updated patches.
>
> Hi Beena,
>
> Thanks for working on this. I've had a look at the patch to try to
> understand how it is working. I found it a bit surprising that the
> code assumes it can rely on the order of Append->appendplans matching
> what's needed based on the return value of get_partitions_for_keys().
>
> I tried using the following to break this:
>
>
> drop table if exists ab;
> create table ab (a int not null, b int not null) partition by list(a);
> create table ab_a2 partition of ab for values in(2) partition by list (b);
> create table ab_a2_b1 partition of ab_a2 for values in (1);
> create table ab_a2_b2 partition of ab_a2 for values in (2);
> create table ab_a2_b3 partition of ab_a2 for values in (3);
>
> create table ab_a1 partition of ab for values in(1) partition by list (b);
> create table ab_a1_b1 partition of ab_a1 for values in (1);
> create table ab_a1_b2 partition of ab_a1 for values in (2);
> create table ab_a1_b3 partition of ab_a1 for values in (3);
> create table ab_a3 partition of ab for values in(3) partition by list (b);
> create table ab_a3_b1 partition of ab_a3 for values in (1);
> create table ab_a3_b2 partition of ab_a3 for values in (2);
> create table ab_a3_b3 partition of ab_a3 for values in (3);
>
> prepare ab_q1 (int, int) as select * from ab where a = $1 and b = $2;
>
> explain execute ab_q1 (2,3);
> explain execute ab_q1 (2,3);
> explain execute ab_q1 (2,3);
> explain execute ab_q1 (2,3);
>
> postgres=# explain execute ab_q1 (2,3);
> QUERY PLAN
> ---------------------------------------------------------------
> Append (cost=0.00..43.90 rows=1 width=8)
> -> Seq Scan on ab_a2_b3 (cost=0.00..43.90 rows=1 width=8)
> Filter: ((a = 2) AND (b = 3))
> (3 rows)
>
>
> postgres=# explain execute ab_q1 (2,3);
> QUERY PLAN
> ---------------------------------------------------------------
> Append (cost=0.00..395.10 rows=1 width=8)
> -> Seq Scan on ab_a1_b2 (cost=0.00..43.90 rows=1 width=8)
> <--------- wrong partition
> Filter: ((a = $1) AND (b = $2))
> (3 rows)
>
With the new patch, the output is:
postgres=# explain execute ab_q1 (2,3);
QUERY PLAN
---------------------------------------------------------------
Append (cost=0.00..43.90 rows=1 width=8)
-> Seq Scan on ab_a2_b3 (cost=0.00..43.90 rows=1 width=8)
Filter: ((a = 2) AND (b = 3))
(3 rows)
postgres=# explain execute ab_q1 (2,3);
QUERY PLAN
---------------------------------------------------------------
Append (cost=0.00..395.10 rows=4 width=8)
-> Seq Scan on ab_a2_b3 (cost=0.00..43.90 rows=1 width=8)
Filter: ((a = $1) AND (b = $2))
(3 rows)
--
Beena Emerson
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Commits
-
Initialize ExprStates once in run-time partition pruning
- 1957f8dabf8d 11.0 landed
-
Add bms_prev_member function
- 5c0675215e15 11.0 landed
-
Support partition pruning at execution time
- 499be013de65 11.0 landed
-
Document partprune.c a little better
- 971d7ddbe19a 11.0 landed
-
Fix crash in pg_replication_slot_advance
- 6f1d723b6359 11.0 cited
-
Add parallel-aware hash joins.
- 1804284042e6 11.0 cited
-
Fix typo.
- 487a0c1518af 11.0 cited
-
Allow --with-bonjour to work with non-macOS implementations of Bonjour.
- 9b9cb3c4534d 11.0 cited
-
Mention need for --no-inc-recursive in rsync command
- 2c74e6c1dcc5 11.0 cited