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 1ozlgU-0004vC-Qa for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Nov 2022 21:29:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ozlgT-0004KO-Dd for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Nov 2022 21:29:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozlgT-0004KF-4B for pgsql-hackers@lists.postgresql.org; Mon, 28 Nov 2022 21:29:01 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ozlgQ-0003Vk-KG for pgsql-hackers@lists.postgresql.org; Mon, 28 Nov 2022 21:29:00 +0000 Received: from bruce by momjian.us with local (Exim 4.94.2) (envelope-from ) id 1ozlgN-00GApc-4e; Mon, 28 Nov 2022 16:28:55 -0500 Date: Mon, 28 Nov 2022 16:28:55 -0500 From: Bruce Momjian To: David Zhang Cc: 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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <46a0f6fb-1c0b-bbd8-ef3e-366216a89501@highgo.ca> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Nov 25, 2022 at 05:03:06PM -0800, David Zhang wrote: > Hi Bruce, > > Thank you for helping review the patches in such detail. > > On 2022-11-25 9:48 a.m., Bruce Momjian wrote: > > Looking at the patch, I am unclear how the the patch prevents concurrent > duplicate value insertion during the partitioned index checking. I am > actually not sure how that can be done without locking all indexes or > inserting placeholder entries in all indexes. (Yeah, that sounds bad, > unless I am missing something.) > > For the uniqueness check cross all partitions, we tried to follow the > implementation of uniqueness check on a single partition, and added a loop to > check uniqueness on other partitions after the index tuple has been inserted to > current index partition but before this index tuple has been made visible. The > uniqueness check will wait `XactLockTableWait` if there is a valid transaction > in process, and performs the uniqueness check again after the in-process > transaction finished. I can't see why this wouldn't work, but I also can't think of any cases where we do this in our code already, so it will need careful consideration. We kind of do this for UPDATE and unique key conflicts, but only for a single index entry. where we peek and sleep on pending changes, but not across indexes. > I am not quite sure if this is a proper way to deal with a deadlock in this > case. It would be so grateful if someone could help provide some cases/methods > to verify this cross all partitions uniqueness. I assume you are using our existing deadlock detection code, and just sleeping in various indexes and expecting deadlock detection to happen. -- Bruce Momjian https://momjian.us EDB https://enterprisedb.com Embrace your flaws. They make you human, rather than perfect, which you will never be.