Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0D3I-0006v6-V4 for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Nov 2022 02:42:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p0D3H-0000RA-Ro for pgsql-hackers@arkaria.postgresql.org; Wed, 30 Nov 2022 02:42:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0D3H-0000R0-IB for pgsql-hackers@lists.postgresql.org; Wed, 30 Nov 2022 02:42:23 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p0D3E-0002Gy-Vr for pgsql-hackers@lists.postgresql.org; Wed, 30 Nov 2022 02:42:22 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1p0D39-004fMM-0G; Tue, 29 Nov 2022 21:42:15 -0500 Date: Tue, 29 Nov 2022 21:42:14 -0500 From: Bruce Momjian To: Tom Lane Cc: Greg Stark , David Zhang , Simon Riggs , Cary Huang , Pgsql Hackers Subject: Re: Patch: Global Unique Index Message-ID: References: <184879c5306.12490ea581628934.7312528450011769010@highgo.ca> <46a0f6fb-1c0b-bbd8-ef3e-366216a89501@highgo.ca> <1239139.1669763636@sss.pgh.pa.us> <1257837.1669774583@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1257837.1669774583@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 https://momjian.us EDB https://enterprisedb.com Embrace your flaws. They make you human, rather than perfect, which you will never be.