Re: partitions vs indexes

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Enrico Thierbach <eno(at)open-lab(dot)org>
Cc: PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: partitions vs indexes
Date: 2019-10-02 20:16:24
Message-ID: CAHOFxGqoB2PryV7P_UUyj159MmEgSYf9ZzOLPwbZ+bceTfp9aQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"I would like to convert a table with a primary key into a partitioned
setup by a column which is not part of the primary key"

That isn't possible. The partition key must be contained by the primary
key. That is, the primary key could be site_id, id and you can create hash
partition on id or site_id but not created_on.

You could drop primary key and foreign keys and implement them via trigger
functions as described in this blog series, but it seems questionable-
https://www.depesz.com/2018/10/31/foreign-key-to-partitioned-table-part-2/

I do not assume the restriction would be dropped in future releases. I
don't know that scanning all the partitions to figure out whether the
primary key is violated would be advisable. Which is what the trigger
functions described in the blog post has to do, right?

It might be noteworthy that partitioning with more than 10-100 partitions
is MUCH faster in PG12 than PG11 (up to 4-8 thousand partitions) from
testing shared by those working on that code.

>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Aleš Zelený 2019-10-02 20:19:03 Wall shiping replica failed to recover database with error: invalid contrecord length 1956 at FED/38FFE208
Previous Message Enrico Thierbach 2019-10-02 20:11:07 Re: partitions vs indexes