PG11 - Multiple Key Range Partition

From: Rares Salcudean <rares(dot)salcudean(at)takeofflabs(dot)com>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: PG11 - Multiple Key Range Partition
Date: 2019-07-08 09:05:22
Message-ID: CAHp_FN2xwEznH6oyS0hNTuUUZKp5PvegcVv=Co6nBXJ+mC7Y5w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Ádám Maracska 2019-07-08 17:56:58 Re: PostgreSQL 11 can not restart after an unexpected shutdown
Previous Message Prakash Ramakrishnan 2019-07-08 07:57:40 perl issue