Re: Patch: Global Unique Index

Bruce Momjian <bruce@momjian.us>

From: Bruce Momjian <bruce@momjian.us>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Greg Stark <stark@mit.edu>, David Zhang <david.zhang@highgo.ca>, Simon Riggs <simon.riggs@enterprisedb.com>, Cary Huang <cary.huang@highgo.ca>, Pgsql Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2022-11-30T02:42:14Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Apply a better fix to mdunlinkfork().

On Tue, Nov 29, 2022 at 09:16:23PM -0500, Tom Lane wrote:
> 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.

As I understood it, you insert into index X and then scan all other
indexes to look for a conflict --- if you find one, you abort with a
unique index conflict.  Other index changes do the same.

So, for example, one session inserts into index X and then scans all
other indexes.  During the index scan, another session inserts into
index Y, but its scan sees the index X addition and gets a uniqueness
conflict error.

> 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.

Yes, that would require index locks.

-- 
  Bruce Momjian  <bruce@momjian.us>        https://momjian.us
  EDB                                      https://enterprisedb.com

Embrace your flaws.  They make you human, rather than perfect,
which you will never be.