pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
PG11 - Multiple Key Range Partition
14+ messages / 4 participants
[nested] [flat]

Commits from this thread:
  2019-07-12 757f1baa8c 30a268ed2e cfde234939  Fix RANGE partition pruning with multiple boolean partition keys
* PG11 - Multiple Key Range Partition
@ 2019-07-08 09:05  Rares Salcudean <rares.salcudean@takeofflabs.com>
  0 siblings, 1 reply; 14+ messages in thread

From: Rares Salcudean @ 2019-07-08 09:05 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

Hello,

Currently, I'm trying to define a table with a range partition of 3 keys
Recent, Deleted and Played At.

There are multiple partitions:

1. scores_2018 (recent - false, deleted - false, played_at in (2018-01-01 /
2019-01-01)
2. scores_2017 (recent - false, deleted - false, played_at in (2017-01-01 /
2018-01-01)
3. scores_recent (recent - *true*, deleted - false, played_at in
(1990-01-01 / 2090-01-01)
4. scores_deleted (recent - false, deleted - *true*, played_at in
(1990-01-01 / 2090-01-01)

When inserting all works fine, but when doing a select statement it does
not correctly query over the correct partition, It searches on all
partitions.

*explain select * from scores where played_at = '2018-03-01'*

[image: Screenshot 2019-07-08 at 12.01.15.png]

*explain select * from scores where recent = true and deleted = false and
played_at = '2018-03-01'*

[image: Screenshot 2019-07-08 at 12.01.55.png]

When using the *recent *key the partition is selected correctly. However,
when using the *deleted* key it does a full search.

*explain select * from scores where deleted = true*

[image: Screenshot 2019-07-08 at 12.03.19.png]

*Note:* If I only create the table with only 2 partition keys *Recent* and
*Played* *at*, all works as expected.

The 3 key range partition is not supported, or is it a bug? Can you please
suggest an alternative?

The main idea is to have multiple partitions, one for each year and an
extra 2, for deleted scores, and recent scores.

Thank you and have a great day!
Rares

Attachments:

Screenshot 2019-07-08 at 12.01.15.png (image/png, 117.1K) download view image
Screenshot 2019-07-08 at 12.01.55.png (image/png, 26.9K) download view image
Screenshot 2019-07-08 at 12.03.19.png (image/png, 86.6K) download view image
^ permalink raw reply [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-08 21:48  David Rowley <david.rowley@2ndquadrant.com>
  parent: Rares Salcudean <rares.salcudean@takeofflabs.com>
  0 siblings, 1 reply; 14+ messages in thread

From: David Rowley @ 2019-07-08 21:48 UTC (permalink / raw)
  To: Rares Salcudean <rares.salcudean@takeofflabs.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Mon, 8 Jul 2019 at 21:17, Rares Salcudean
<rares.salcudean@takeofflabs.com> wrote:
> Currently, I'm trying to define a table with a range partition of 3 keys Recent, Deleted and Played At.
>
> There are multiple partitions:
>
> 1. scores_2018 (recent - false, deleted - false, played_at in (2018-01-01 / 2019-01-01)
> 2. scores_2017 (recent - false, deleted - false, played_at in (2017-01-01 / 2018-01-01)
> 3. scores_recent (recent - true, deleted - false, played_at in (1990-01-01 / 2090-01-01)
> 4. scores_deleted (recent - false, deleted - true, played_at in (1990-01-01 / 2090-01-01)
>
> When inserting all works fine, but when doing a select statement it does not correctly query over the correct partition, It searches on all partitions.
>
> explain select * from scores where played_at = '2018-03-01'

RANGE partitioning pruning works by the planner having knowledge that
your WHERE clause cannot yield rows that are within a partition's
range. Take your scores_2017 partition as an example, the range there
is (false, false, '2017-01-01') to (false, false, '2018-01-01'). The
planner cannot match your WHERE clause to that range since it's
missing any predicate that matches a prefix of the range. This is
similar to how a btree index on (recent, deleted, played_at) couldn't
be used efficiently to give you just rows with played_at on any given
date. You'd need something like: WHERE NOT recent AND NOT deleted AND
played_at = '2018-03-01' for it to know only the scores_2018 partition
can match.

(There was a bug fixed recently that caused some partitions in a range
partitioned table to be pruned accidentally, but you're not
complaining about that.)

You might want to look into sub-partitioning the table, however, see
the note in [1] about that.

[1] https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE-BEST-PRAC...

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-09 06:53  Rares Salcudean <rares.salcudean@takeofflabs.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  0 siblings, 1 reply; 14+ messages in thread

From: Rares Salcudean @ 2019-07-09 06:53 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Hi David,

First of all, thank you for the quick response, I highly appreciate it!

Currently, I'm trying to test out different query patterns to understand
the key constraints and make the planner recognize the RANGE.

The example you suggested:

explain select * from scores where NOT(recent = true) and NOT(deleted =
true) and played_at = '2018-03-02'
explain select * from scores where NOT(recent) and NOT(deleted) and
played_at = '2018-03-02'

Yield the same result:

[image: Screenshot 2019-07-09 at 09.42.46.png]

It does a search over all partitions, mainly because I think the planner
still cannot match the where clause to the range.

I can not find any queries that output the desired results. And for the
moment I like our strategy of having a partition for each year, plus the
extra two (recent and deleted). In terms of Insert / Update / Deleted /
Upsert / etc.. operations all works fine. I populated a DB with around 600
million rows and the partitions are populated correctly + operations except
SELECT are working perfectly.

Furthermore, I am a bit confused about the fact that with 2 key range
partitions (recent and played_at), all works perfectly as expected (event
SELECT).
I saw you recommended sub-partitioning, we are defining each partition as
in the example from the documentation.

I'm not sure what is your timeline, but can you provide an example with 3
key Range (2 booleans and 1 date) partition with a working select statement
on the date?

Thank you very much and have a great day!
Rares



On Tue, Jul 9, 2019 at 12:49 AM David Rowley <david.rowley@2ndquadrant.com>
wrote:

> On Mon, 8 Jul 2019 at 21:17, Rares Salcudean
> <rares.salcudean@takeofflabs.com> wrote:
> > Currently, I'm trying to define a table with a range partition of 3 keys
> Recent, Deleted and Played At.
> >
> > There are multiple partitions:
> >
> > 1. scores_2018 (recent - false, deleted - false, played_at in
> (2018-01-01 / 2019-01-01)
> > 2. scores_2017 (recent - false, deleted - false, played_at in
> (2017-01-01 / 2018-01-01)
> > 3. scores_recent (recent - true, deleted - false, played_at in
> (1990-01-01 / 2090-01-01)
> > 4. scores_deleted (recent - false, deleted - true, played_at in
> (1990-01-01 / 2090-01-01)
> >
> > When inserting all works fine, but when doing a select statement it does
> not correctly query over the correct partition, It searches on all
> partitions.
> >
> > explain select * from scores where played_at = '2018-03-01'
>
> RANGE partitioning pruning works by the planner having knowledge that
> your WHERE clause cannot yield rows that are within a partition's
> range. Take your scores_2017 partition as an example, the range there
> is (false, false, '2017-01-01') to (false, false, '2018-01-01'). The
> planner cannot match your WHERE clause to that range since it's
> missing any predicate that matches a prefix of the range. This is
> similar to how a btree index on (recent, deleted, played_at) couldn't
> be used efficiently to give you just rows with played_at on any given
> date. You'd need something like: WHERE NOT recent AND NOT deleted AND
> played_at = '2018-03-01' for it to know only the scores_2018 partition
> can match.
>
> (There was a bug fixed recently that caused some partitions in a range
> partitioned table to be pruned accidentally, but you're not
> complaining about that.)
>
> You might want to look into sub-partitioning the table, however, see
> the note in [1] about that.
>
> [1]
> https://www.postgresql.org/docs/current/ddl-partitioning.html#DDL-PARTITIONING-DECLARATIVE-BEST-PRAC...
>
> --
>  David Rowley                   http://www.2ndQuadrant.com/
>  PostgreSQL Development, 24x7 Support, Training & Services
>

Attachments:

Screenshot 2019-07-09 at 09.42.46.png (image/png, 250.7K) download view image
^ permalink raw reply [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-09 23:32  David Rowley <david.rowley@2ndquadrant.com>
  parent: Rares Salcudean <rares.salcudean@takeofflabs.com>
  0 siblings, 1 reply; 14+ messages in thread

From: David Rowley @ 2019-07-09 23:32 UTC (permalink / raw)
  To: Rares Salcudean <rares.salcudean@takeofflabs.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Tue, 9 Jul 2019 at 18:53, Rares Salcudean
<rares.salcudean@takeofflabs.com> wrote:
> The example you suggested:
>
> explain select * from scores where NOT(recent = true) and NOT(deleted = true) and played_at = '2018-03-02'
> explain select * from scores where NOT(recent) and NOT(deleted) and played_at = '2018-03-02'
>
> Yield the same result:

Works okay for me with:

create table rangep (a bool, b bool, c date) partition by range (a,b,c);

create table rangep1 partition of rangep for values from (false,
false, '2019-01-01') to (false,false,'2020-01-01');
create table rangep2 partition of rangep for values from (true, true,
'2019-01-01') to (true,true,'2020-01-01');

explain select * from rangep where not a and not b and c = '2019-07-10';
                          QUERY PLAN
--------------------------------------------------------------
 Seq Scan on rangep1  (cost=0.00..40.00 rows=3 width=6)
   Filter: ((NOT a) AND (NOT b) AND (c = '2019-07-10'::date))
(2 rows)

That's on master, but v10 and v11 still prune away rangep2.

It might help if you share which version you're using and a cutdown
version of the schema, just enough to show the issue.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-10 06:39  Rares Salcudean <rares.salcudean@takeofflabs.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  0 siblings, 1 reply; 14+ messages in thread

From: Rares Salcudean @ 2019-07-10 06:39 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Hi David,

I tested out your example and all works fine for me as well. But I live the
main issue lies in the following example:

create table rangep (a bool, b bool, c date) partition by range (a,b,c);

create table rangep1_recent partition of rangep for values from (*true*,false,
'1990-01-01') to (*true*,false,'2090-01-01');
create table rangep1_deleted partition of rangep for values from (false,
*true*, '1990-01-01') to (false,*true*,'2090-01-01');
create table rangep1_2019 partition of rangep for values from (false,false,
'2019-01-01') to (false,false,'2020-01-01');
create table rangep1_2018 partition of rangep for values from (false,false,
'2018-01-01') to (false,false,'2019-01-01');
create table rangep1_2017 partition of rangep for values from (false,false,
'2017-01-01') to (false,false,'2018-01-01');

explain select * from rangep where not a and not b and c = '2019-07-10';

[image: Screenshot 2019-07-10 at 09.32.14.png]

When doing:
explain select * from rangep where a and not b an and c = '2019-07-10';
or simply
explain select * from rangep where a and c = '2019-07-10';

It successfully searches only in the 'recent' partition.
I believe the planner gets confused when we introduce the following two
combinations: (true, false, '1990-01-01') - (true, false, '2090-01-01') and
(false, true, '1990-01-01') - (false, true, '2090-01-01').

My current Postgres version is PostgreSQL 11, 2.2.4. ("PostgreSQL 11.4 on
x86_64-apple-darwin16.7.0, compiled by Apple LLVM version 8.1.0
(clang-802.0.42), 64-bit")

Thank you for the quick response, I’m eager to receive your feedback.

Have a great day!
Rares

On Wed, Jul 10, 2019 at 2:33 AM David Rowley <david.rowley@2ndquadrant.com>
wrote:

> On Tue, 9 Jul 2019 at 18:53, Rares Salcudean
> <rares.salcudean@takeofflabs.com> wrote:
> > The example you suggested:
> >
> > explain select * from scores where NOT(recent = true) and NOT(deleted =
> true) and played_at = '2018-03-02'
> > explain select * from scores where NOT(recent) and NOT(deleted) and
> played_at = '2018-03-02'
> >
> > Yield the same result:
>
> Works okay for me with:
>
> create table rangep (a bool, b bool, c date) partition by range (a,b,c);
>
> create table rangep1 partition of rangep for values from (false,
> false, '2019-01-01') to (false,false,'2020-01-01');
> create table rangep2 partition of rangep for values from (true, true,
> '2019-01-01') to (true,true,'2020-01-01');
>
> explain select * from rangep where not a and not b and c = '2019-07-10';
>                           QUERY PLAN
> --------------------------------------------------------------
>  Seq Scan on rangep1  (cost=0.00..40.00 rows=3 width=6)
>    Filter: ((NOT a) AND (NOT b) AND (c = '2019-07-10'::date))
> (2 rows)
>
> That's on master, but v10 and v11 still prune away rangep2.
>
> It might help if you share which version you're using and a cutdown
> version of the schema, just enough to show the issue.
>
> --
>  David Rowley                   http://www.2ndQuadrant.com/
>  PostgreSQL Development, 24x7 Support, Training & Services
>

Attachments:

Screenshot 2019-07-10 at 09.32.14.png (image/png, 131.9K) download view image
^ permalink raw reply [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-10 08:37  David Rowley <david.rowley@2ndquadrant.com>
  parent: Rares Salcudean <rares.salcudean@takeofflabs.com>
  0 siblings, 1 reply; 14+ messages in thread

From: David Rowley @ 2019-07-10 08:37 UTC (permalink / raw)
  To: Rares Salcudean <rares.salcudean@takeofflabs.com>; +Cc: PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Wed, 10 Jul 2019 at 18:39, Rares Salcudean
<rares.salcudean@takeofflabs.com> wrote:
> I tested out your example and all works fine for me as well. But I live the main issue lies in the following example:
>
> create table rangep (a bool, b bool, c date) partition by range (a,b,c);
>
> create table rangep1_recent partition of rangep for values from (true,false, '1990-01-01') to (true,false,'2090-01-01');
> create table rangep1_deleted partition of rangep for values from (false,true, '1990-01-01') to (false,true,'2090-01-01');
> create table rangep1_2019 partition of rangep for values from (false,false, '2019-01-01') to (false,false,'2020-01-01');
> create table rangep1_2018 partition of rangep for values from (false,false, '2018-01-01') to (false,false,'2019-01-01');
> create table rangep1_2017 partition of rangep for values from (false,false, '2017-01-01') to (false,false,'2018-01-01');
>
> explain select * from rangep where not a and not b and c = '2019-07-10';

Thanks for making the test case. It is a bug.  There's a problem in
match_clause_to_partition_key() where because
match_boolean_partition_clause() returns false for the "NOT b"
condition when comparing to the first partition key this causes the
function to return PARTCLAUSE_UNSUPPORTED which causes the calling
function to not bother trying to match that qual up to any other
partition key. Effectively, for pruning the WHERE clause is just WHERE
NOT a AND c = '2019-07-10', so only the rangep1_recent partition is
pruned.

I'll look into fixing it. Thanks for the report.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-10 09:01  Amit Langote <amitlangote09@gmail.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  0 siblings, 1 reply; 14+ messages in thread

From: Amit Langote @ 2019-07-10 09:01 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: Rares Salcudean <rares.salcudean@takeofflabs.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Wed, Jul 10, 2019 at 5:37 PM David Rowley
<david.rowley@2ndquadrant.com> wrote:
> On Wed, 10 Jul 2019 at 18:39, Rares Salcudean
> <rares.salcudean@takeofflabs.com> wrote:
> > I tested out your example and all works fine for me as well. But I live the main issue lies in the following example:
> >
> > create table rangep (a bool, b bool, c date) partition by range (a,b,c);
> >
> > create table rangep1_recent partition of rangep for values from (true,false, '1990-01-01') to (true,false,'2090-01-01');
> > create table rangep1_deleted partition of rangep for values from (false,true, '1990-01-01') to (false,true,'2090-01-01');
> > create table rangep1_2019 partition of rangep for values from (false,false, '2019-01-01') to (false,false,'2020-01-01');
> > create table rangep1_2018 partition of rangep for values from (false,false, '2018-01-01') to (false,false,'2019-01-01');
> > create table rangep1_2017 partition of rangep for values from (false,false, '2017-01-01') to (false,false,'2018-01-01');
> >
> > explain select * from rangep where not a and not b and c = '2019-07-10';
>
> Thanks for making the test case. It is a bug.  There's a problem in
> match_clause_to_partition_key() where because
> match_boolean_partition_clause() returns false for the "NOT b"
> condition when comparing to the first partition key this causes the
> function to return PARTCLAUSE_UNSUPPORTED which causes the calling
> function to not bother trying to match that qual up to any other
> partition key.

Oops, indeed a bug.  Should've returned PARTCLAUSE_NOMATCH there.

Thanks for taking it up.

Regards,
Amit





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-10 10:06  David Rowley <david.rowley@2ndquadrant.com>
  parent: Amit Langote <amitlangote09@gmail.com>
  0 siblings, 1 reply; 14+ messages in thread

From: David Rowley @ 2019-07-10 10:06 UTC (permalink / raw)
  To: Amit Langote <amitlangote09@gmail.com>; +Cc: Rares Salcudean <rares.salcudean@takeofflabs.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Wed, 10 Jul 2019 at 21:02, Amit Langote <amitlangote09@gmail.com> wrote:
>
> On Wed, Jul 10, 2019 at 5:37 PM David Rowley
> > Thanks for making the test case. It is a bug.  There's a problem in
> > match_clause_to_partition_key() where because
> > match_boolean_partition_clause() returns false for the "NOT b"
> > condition when comparing to the first partition key this causes the
> > function to return PARTCLAUSE_UNSUPPORTED which causes the calling
> > function to not bother trying to match that qual up to any other
> > partition key.
>
> Oops, indeed a bug.  Should've returned PARTCLAUSE_NOMATCH there.

Here's a first draft fix for this, based on master.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

fix_boolean_partition_pruning.patch (application/octet-stream, 7.8K) download diff --git a/src/backend/partitioning/partprune.c b/src/backend/partitioning/partprune.c index 5982af4de1..2c6e97ac16 100644 --- a/src/backend/partitioning/partprune.c +++ b/src/backend/partitioning/partprune.c @@ -194,8 +194,10 @@ static PruneStepResult *perform_pruning_base_step(PartitionPruneContext *context static PruneStepResult *perform_pruning_combine_step(PartitionPruneContext *context, PartitionPruneStepCombine *cstep, PruneStepResult **step_results); -static bool match_boolean_partition_clause(Oid partopfamily, Expr *clause, - Expr *partkey, Expr **outconst); +static PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily, + Expr *clause, + Expr *partkey, + Expr **outconst); static void partkey_datum_from_expr(PartitionPruneContext *context, Expr *expr, int stateidx, Datum *value, bool *isnull); @@ -1623,6 +1625,7 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context, bool *clause_is_not_null, PartClauseInfo **pc, List **clause_steps) { + PartClauseMatchStatus boolmatchstatus; PartitionScheme part_scheme = context->rel->part_scheme; Oid partopfamily = part_scheme->partopfamily[partkeyidx], partcoll = part_scheme->partcollation[partkeyidx]; @@ -1631,7 +1634,10 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context, /* * Recognize specially shaped clauses that match a Boolean partition key. */ - if (match_boolean_partition_clause(partopfamily, clause, partkey, &expr)) + boolmatchstatus = match_boolean_partition_clause(partopfamily, clause, + partkey, &expr); + + if (boolmatchstatus == PARTCLAUSE_MATCH_CLAUSE) { PartClauseInfo *partclause; @@ -2147,7 +2153,8 @@ match_clause_to_partition_key(GeneratePruningStepsContext *context, return PARTCLAUSE_MATCH_NULLNESS; } - return PARTCLAUSE_UNSUPPORTED; + /* return the value from the match_boolean_partition_clause call */ + return boolmatchstatus; } /* @@ -3395,11 +3402,15 @@ perform_pruning_combine_step(PartitionPruneContext *context, /* * match_boolean_partition_clause * - * Sets *outconst to a Const containing true or false value and returns true if - * we're able to match the clause to the partition key as specially-shaped - * Boolean clause. Returns false otherwise with *outconst set to NULL. + * Sets *outconst to a Const containing a true or false value and returns + * PARTCLAUSE_MATCH_CLAUSE if we're able to match the clause to the partition + * key as specially-shaped Boolean clause. Returns PARTCLAUSE_UNSUPPORTED if + * the clause is not a boolean clause or if the boolean clause is unsuitable + * for partition pruning. Returns PARTCLAUSE_NOMATCH if we're unable to match + * the clause up to the partition key. *outconst is set to NULL in the latter + * two cases. */ -static bool +static PartClauseMatchStatus match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, Expr **outconst) { @@ -3408,7 +3419,7 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, *outconst = NULL; if (!IsBooleanOpfamily(partopfamily)) - return false; + return PARTCLAUSE_UNSUPPORTED; if (IsA(clause, BooleanTest)) { @@ -3417,7 +3428,7 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, /* Only IS [NOT] TRUE/FALSE are any good to us */ if (btest->booltesttype == IS_UNKNOWN || btest->booltesttype == IS_NOT_UNKNOWN) - return false; + return PARTCLAUSE_UNSUPPORTED; leftop = btest->arg; if (IsA(leftop, RelabelType)) @@ -3430,7 +3441,7 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, : (Expr *) makeBoolConst(false, false); if (*outconst) - return true; + return PARTCLAUSE_MATCH_CLAUSE; } else { @@ -3450,10 +3461,10 @@ match_boolean_partition_clause(Oid partopfamily, Expr *clause, Expr *partkey, *outconst = (Expr *) makeBoolConst(false, false); if (*outconst) - return true; + return PARTCLAUSE_MATCH_CLAUSE; } - return false; + return PARTCLAUSE_NOMATCH; } /* diff --git a/src/test/regress/expected/partition_prune.out b/src/test/regress/expected/partition_prune.out index 841bd8bc67..604375e787 100644 --- a/src/test/regress/expected/partition_prune.out +++ b/src/test/regress/expected/partition_prune.out @@ -1086,6 +1086,19 @@ explain (costs off) select * from boolpart where a is not unknown; Filter: (a IS NOT UNKNOWN) (7 rows) +create table boolrangep (a bool, b bool, c int) partition by range (a,b,c); +create table boolrangep_tf partition of boolrangep for values from ('true', 'false', 0) to ('true', 'false', 100); +create table boolrangep_ft partition of boolrangep for values from ('false', 'true', 0) to ('false', 'true', 100); +create table boolrangep_ff1 partition of boolrangep for values from ('false', 'false', 0) to ('false', 'false', 50); +create table boolrangep_ff2 partition of boolrangep for values from ('false', 'false', 50) to ('false', 'false', 100); +-- try a more complex boolean case that's been known to trip up pruning in the past +explain (costs off) select * from boolrangep where not a and not b and c = 25; + QUERY PLAN +---------------------------------------------- + Seq Scan on boolrangep_ff1 + Filter: ((NOT a) AND (NOT b) AND (c = 25)) +(2 rows) + -- test scalar-to-array operators create table coercepart (a varchar) partition by list (a); create table coercepart_ab partition of coercepart for values in ('ab'); @@ -1420,7 +1433,7 @@ explain (costs off) select * from rparted_by_int2 where a > 100000000000000; Filter: (a > '100000000000000'::bigint) (2 rows) -drop table lp, coll_pruning, rlp, mc3p, mc2p, boolpart, rp, coll_pruning_multi, like_op_noprune, lparted_by_int2, rparted_by_int2; +drop table lp, coll_pruning, rlp, mc3p, mc2p, boolpart, boolrangep, rp, coll_pruning_multi, like_op_noprune, lparted_by_int2, rparted_by_int2; -- -- Test Partition pruning for HASH partitioning -- diff --git a/src/test/regress/sql/partition_prune.sql b/src/test/regress/sql/partition_prune.sql index 071e28dce8..f8a3cf53db 100644 --- a/src/test/regress/sql/partition_prune.sql +++ b/src/test/regress/sql/partition_prune.sql @@ -159,6 +159,15 @@ explain (costs off) select * from boolpart where a is not true and a is not fals explain (costs off) select * from boolpart where a is unknown; explain (costs off) select * from boolpart where a is not unknown; +create table boolrangep (a bool, b bool, c int) partition by range (a,b,c); +create table boolrangep_tf partition of boolrangep for values from ('true', 'false', 0) to ('true', 'false', 100); +create table boolrangep_ft partition of boolrangep for values from ('false', 'true', 0) to ('false', 'true', 100); +create table boolrangep_ff1 partition of boolrangep for values from ('false', 'false', 0) to ('false', 'false', 50); +create table boolrangep_ff2 partition of boolrangep for values from ('false', 'false', 50) to ('false', 'false', 100); + +-- try a more complex boolean case that's been known to trip up pruning in the past +explain (costs off) select * from boolrangep where not a and not b and c = 25; + -- test scalar-to-array operators create table coercepart (a varchar) partition by list (a); create table coercepart_ab partition of coercepart for values in ('ab'); @@ -264,7 +273,7 @@ create table rparted_by_int2_maxvalue partition of rparted_by_int2 for values fr -- all partitions but rparted_by_int2_maxvalue pruned explain (costs off) select * from rparted_by_int2 where a > 100000000000000; -drop table lp, coll_pruning, rlp, mc3p, mc2p, boolpart, rp, coll_pruning_multi, like_op_noprune, lparted_by_int2, rparted_by_int2; +drop table lp, coll_pruning, rlp, mc3p, mc2p, boolpart, boolrangep, rp, coll_pruning_multi, like_op_noprune, lparted_by_int2, rparted_by_int2; -- -- Test Partition pruning for HASH partitioning
^ permalink raw reply [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-10 11:14  Rares Salcudean <rares.salcudean@takeofflabs.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  0 siblings, 1 reply; 14+ messages in thread

From: Rares Salcudean @ 2019-07-10 11:14 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: Amit Langote <amitlangote09@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

Thank you guys for the quick response.

Which would be the simplest way to "import/apply" this fix locally for me?
Do I have to wait until the new version is released?

By the way, keep it up, awesome work!
Rares

On Wed, Jul 10, 2019 at 1:07 PM David Rowley <david.rowley@2ndquadrant.com>
wrote:

> On Wed, 10 Jul 2019 at 21:02, Amit Langote <amitlangote09@gmail.com>
> wrote:
> >
> > On Wed, Jul 10, 2019 at 5:37 PM David Rowley
> > > Thanks for making the test case. It is a bug.  There's a problem in
> > > match_clause_to_partition_key() where because
> > > match_boolean_partition_clause() returns false for the "NOT b"
> > > condition when comparing to the first partition key this causes the
> > > function to return PARTCLAUSE_UNSUPPORTED which causes the calling
> > > function to not bother trying to match that qual up to any other
> > > partition key.
> >
> > Oops, indeed a bug.  Should've returned PARTCLAUSE_NOMATCH there.
>
> Here's a first draft fix for this, based on master.
>
> --
>  David Rowley                   http://www.2ndQuadrant.com/
>  PostgreSQL Development, 24x7 Support, Training & Services
>

^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-12 03:54  David Rowley <david.rowley@2ndquadrant.com>
  parent: Rares Salcudean <rares.salcudean@takeofflabs.com>
  0 siblings, 2 replies; 14+ messages in thread

From: David Rowley @ 2019-07-12 03:54 UTC (permalink / raw)
  To: Rares Salcudean <rares.salcudean@takeofflabs.com>; +Cc: Amit Langote <amitlangote09@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Wed, 10 Jul 2019 at 23:14, Rares Salcudean
<rares.salcudean@takeofflabs.com> wrote:
> Which would be the simplest way to "import/apply" this fix locally for me? Do I have to wait until the new version is released?

That's really up to you. I'd at least wait for the patch to be
committed though. From then, if you're comfortable patching and
building yourself then you could get the fix sooner. Otherwise, there
should be a release around the end of September.

I'm about to take a more serious look at the patch I posted a few days ago.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-12 04:23  Michael Paquier <michael@paquier.xyz>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  1 sibling, 0 replies; 14+ messages in thread

From: Michael Paquier @ 2019-07-12 04:23 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: Rares Salcudean <rares.salcudean@takeofflabs.com>; Amit Langote <amitlangote09@gmail.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Jul 12, 2019 at 03:54:01PM +1200, David Rowley wrote:
> That's really up to you. I'd at least wait for the patch to be
> committed though. From then, if you're comfortable patching and
> building yourself then you could get the fix sooner. Otherwise, there
> should be a release around the end of September.

The next minor version release is planned for the beginning of
August per the roadmap:
https://www.postgresql.org/developer/roadmap/
So assuming that this gets merged by then, the fix will be released in
a couple of weeks.
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-12 06:53  Amit Langote <amitlangote09@gmail.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  1 sibling, 1 reply; 14+ messages in thread

From: Amit Langote @ 2019-07-12 06:53 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: Rares Salcudean <rares.salcudean@takeofflabs.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Jul 12, 2019 at 12:54 PM David Rowley
<david.rowley@2ndquadrant.com> wrote:
> I'm about to take a more serious look at the patch I posted a few days ago.

I have looked at the patch.  It seems right to make
match_boolean_partition_clause() return PartClauseMatchStatus instead
of bool.  Didn't find anything to complain about.

Thanks,
Amit





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-12 07:14  David Rowley <david.rowley@2ndquadrant.com>
  parent: Amit Langote <amitlangote09@gmail.com>
  0 siblings, 1 reply; 14+ messages in thread

From: David Rowley @ 2019-07-12 07:14 UTC (permalink / raw)
  To: Amit Langote <amitlangote09@gmail.com>; +Cc: Rares Salcudean <rares.salcudean@takeofflabs.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, 12 Jul 2019 at 18:53, Amit Langote <amitlangote09@gmail.com> wrote:
> I have looked at the patch.  It seems right to make
> match_boolean_partition_clause() return PartClauseMatchStatus instead
> of bool.  Didn't find anything to complain about.

Thanks for having a look. I've just pushed roughly that patch with
just some additional comments.

-- 
 David Rowley                   http://www.2ndQuadrant.com/
 PostgreSQL Development, 24x7 Support, Training & Services





^ permalink  raw  reply  [nested|flat] 14+ messages in thread

* Re: PG11 - Multiple Key Range Partition
@ 2019-07-12 08:27  Amit Langote <amitlangote09@gmail.com>
  parent: David Rowley <david.rowley@2ndquadrant.com>
  0 siblings, 0 replies; 14+ messages in thread

From: Amit Langote @ 2019-07-12 08:27 UTC (permalink / raw)
  To: David Rowley <david.rowley@2ndquadrant.com>; +Cc: Rares Salcudean <rares.salcudean@takeofflabs.com>; PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>

On Fri, Jul 12, 2019 at 4:15 PM David Rowley
<david.rowley@2ndquadrant.com> wrote:
> On Fri, 12 Jul 2019 at 18:53, Amit Langote <amitlangote09@gmail.com> wrote:
> > I have looked at the patch.  It seems right to make
> > match_boolean_partition_clause() return PartClauseMatchStatus instead
> > of bool.  Didn't find anything to complain about.
>
> Thanks for having a look. I've just pushed roughly that patch with
> just some additional comments.

Thanks for taking care of this.

Regards,
Amit





^ permalink  raw  reply  [nested|flat] 14+ messages in thread


end of thread, other threads:[~2019-07-12 08:27 UTC | newest]

Thread overview: 14+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-08 09:05 PG11 - Multiple Key Range Partition Rares Salcudean <rares.salcudean@takeofflabs.com>
2019-07-08 21:48 ` David Rowley <david.rowley@2ndquadrant.com>
2019-07-09 06:53   ` Rares Salcudean <rares.salcudean@takeofflabs.com>
2019-07-09 23:32     ` David Rowley <david.rowley@2ndquadrant.com>
2019-07-10 06:39       ` Rares Salcudean <rares.salcudean@takeofflabs.com>
2019-07-10 08:37         ` David Rowley <david.rowley@2ndquadrant.com>
2019-07-10 09:01           ` Amit Langote <amitlangote09@gmail.com>
2019-07-10 10:06             ` David Rowley <david.rowley@2ndquadrant.com>
2019-07-10 11:14               ` Rares Salcudean <rares.salcudean@takeofflabs.com>
2019-07-12 03:54                 ` David Rowley <david.rowley@2ndquadrant.com>
2019-07-12 04:23                   ` Michael Paquier <michael@paquier.xyz>
2019-07-12 06:53                   ` Amit Langote <amitlangote09@gmail.com>
2019-07-12 07:14                     ` David Rowley <david.rowley@2ndquadrant.com>
2019-07-12 08:27                       ` Amit Langote <amitlangote09@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox