Re: Postgres 11: Table Partitioning and Primary Keys - Mailing list pgsql-docs

From David G. Johnston
Subject Re: Postgres 11: Table Partitioning and Primary Keys
Date
Msg-id CAKFQuwZJntbGmdMyY8=Af7-g=-MCu_ZdZU-a9ygub+umcRrjdQ@mail.gmail.com
Whole thread Raw
In response to Re: Postgres 11: Table Partitioning and Primary Keys  (Michael Paquier <michael@paquier.xyz>)
List pgsql-docs
On Mon, Jul 8, 2019 at 11:34 PM Michael Paquier <michael@paquier.xyz> wrote:
On Mon, Jul 08, 2019 at 08:12:18PM -0700, David G. Johnston wrote:
> Reads a bit backward.  How about:
>
> "As uniqueness can only be enforced within an individual partition when
> defining a primary key on a partitioned table all columns present in the
> partition key must also exist in the primary key."

Yes, I was not really inspired on this one.

Looking closely at the code in DefineIndex() (and as Rajkumar has
mentioned upthread for unique constraints) this can happen for primary
keys, unique constraints and exclusion constraints.  So we had better
mention all three of them.  I am not sure that we need to be explicit
about the uniqueness part though, let's say the following:
"When defining a primary key, a unique constraint or an exclusion
constraint on a partitioned table, all the columns present in the
constraint definition must be included in the partition key."


That isn't true, it needs to be reversed at least:

"Table-scoped constraints defined on a partitioned table - primary key, unique, and exclusion - must include the partition key columns because the enforcement of such constraints is performed independently on each partition."

The complaint here is the user puts a PK id column on their partitioned table and wonders why they need the partition key columns to also be in the PK.  The answer is the description provided above - with the reminder (or initial cluing in depending) to the reader that this limitation exists because we do not implement global constraints/indexes but instead the definition on the partitioned table is simply copied to all of its partitions.  For me this seems worthy of recapping at this location (I haven't gone looking for a nice cross-reference link to put there).

David J.

pgsql-docs by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Postgres 11: Table Partitioning and Primary Keys
Next
From: Oleg Bartunov
Date:
Subject: Re: Improvement of GIN figure