Re: Patch: Global Unique Index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Greg Stark <stark(at)mit(dot)edu>, David Zhang <david(dot)zhang(at)highgo(dot)ca>, Simon Riggs <simon(dot)riggs(at)enterprisedb(dot)com>, Cary Huang <cary(dot)huang(at)highgo(dot)ca>, Pgsql Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Patch: Global Unique Index
Date: 2022-11-30 02:16:23
Message-ID: 1257837.1669774583@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian <bruce(at)momjian(dot)us> writes:
> On Tue, Nov 29, 2022 at 06:13:56PM -0500, Tom Lane wrote:
>> ... not to mention creating a high probability of deadlocks between
>> concurrent insertions to different partitions. If they each
>> ex-lock their own partition's index before starting to look into
>> other partitions' indexes, it seems like a certainty that such
>> cases would fail. The rule of thumb about locking multiple objects
>> is that all comers had better do it in the same order, and this
>> isn't doing that.

> I am not sure why they would need to exclusive lock anything more than
> the unique index entry they are adding, just like UPDATE does.

Assuming that you are inserting into index X, and you've checked
index Y to find that it has no conflicts, what prevents another
backend from inserting a conflict into index Y just after you look?
AIUI the idea is to prevent that by continuing to hold an exclusive
lock on the whole index Y until you've completed the insertion.
Perhaps there's a better way to do that, but it's not what was
described.

I actually think that that problem should be soluble with a
slightly different approach. The thing that feels insoluble
is that you can't do this without acquiring sufficient locks
to prevent addition of new partitions while the insertion is
in progress. That will be expensive in itself, and it will
turn ATTACH PARTITION into a performance disaster.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Chris Travers 2022-11-30 02:36:44 Re: Add 64-bit XIDs into PostgreSQL 15
Previous Message Bruce Momjian 2022-11-30 01:59:49 Re: Patch: Global Unique Index