Re: BUG #16714: INSERT ON CONFLICT DO UPDATE fails to infer constraint if it's not at top-level partition - Mailing list pgsql-bugs

From David G. Johnston
Subject Re: BUG #16714: INSERT ON CONFLICT DO UPDATE fails to infer constraint if it's not at top-level partition
Date
Msg-id CAKFQuwYLtjoPh6Crrr1b2e92NSWJDLPE1W08C63u3JU9RBjooA@mail.gmail.com
Whole thread Raw
In response to Re: BUG #16714: INSERT ON CONFLICT DO UPDATE fails to infer constraint if it's not at top-level partition  (Andy S <gatekeeper.mail@gmail.com>)
List pgsql-bugs
On Fri, Nov 13, 2020 at 11:40 AM Andy S <gatekeeper.mail@gmail.com> wrote:
That's then either a docs bug.
[...] 
Also:
> The partitioning substitutes for leading columns of indexes, reducing index size and making it more likely that the heavily-used parts of the indexes fit in memory.
That is exactly what this partitioning scheme is made for. Yet ridiculous constraint matching punishes for benefiting from partitioning.

Please don't top-post.  The convention here is to inline or bottom-post.

I agree that the overview statement quoted should be qualified.  The existing behavior is that the table listed in the insert is the table upon which the ON CONFLICT arbiter constraint must exist [1].  This effectively negates the benefit of leveraging the partitioning scheme as a form of uniqueness enforcement in lieu of indexed columns.  IIUC, the additional partition constraint is still useful for select queries so its creation still has merit and leverages that particular benefit of partitioning.  But today, you cannot fully benefit from that dynamic if you wish to leverage ON CONFLICT during data insertion.  An improvement there isn't something that could be back-patched.

David J.

[1] From the INSERT documentation: "All table_name unique indexes that, without regard to order, contain exactly the conflict_target-specified columns/expressions are inferred (chosen) as arbiter indexes."

pgsql-bugs by date:

Previous
From: Andres Freund
Date:
Subject: Re: BUG #16714: INSERT ON CONFLICT DO UPDATE fails to infer constraint if it's not at top-level partition
Next
From: "David G. Johnston"
Date:
Subject: Re: BUG #16714: INSERT ON CONFLICT DO UPDATE fails to infer constraint if it's not at top-level partition