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 1pbmH0-0008Lk-U7 for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Mar 2023 17:47:50 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pbmGz-0006Mb-IC for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Mar 2023 17:47:49 +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 1pbmGz-0006MS-97 for pgsql-hackers@lists.postgresql.org; Mon, 13 Mar 2023 17:47:49 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pbmGv-0001dc-Bv for pgsql-hackers@postgresql.org; Mon, 13 Mar 2023 17:47:48 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 1E506320085B; Mon, 13 Mar 2023 13:47:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute3.internal (MEProxy); Mon, 13 Mar 2023 13:47:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1678729661; x= 1678816061; bh=pOVBN+f4vM9WTEp3rP6JUwA0UsJivLMTfGGyOB+BFoA=; b=N UVUiRlBboMfD5Arr8e5lBsNVZrN2A18/9v9H1qVK0Kw+AF7gd5i/2uCCPvZqfV6J hWvlufijt005O21s5l6pPP/NlvUXGnDJ2U0gb6ALRRnoZb1ik20yabtsnh2hWAHY XE7c9ziZ+w9tCKHfCdVONmPRdsmj6cchgZ2cMu8ifRTocXVLq5mDI87tAN33fI9o HWvmvzikhzpx0WUNPrvn+h5lDzr5n7mQ6u599nulqqHSCqmbLf7LsA1+O8yXkkBO p6q1tjQS3Jaj4P3GSwzayDviGoBmvcjfoKxzDZiOlL5zG3aD1FGmMhwJovlOgcqB rYuveGc4/z9+AiuXdRXYg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvddvgedguddtfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhv rghrohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorh hgqeenucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeej keffgfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtoh hmnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghl vhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 13 Mar 2023 13:47:41 -0400 (EDT) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id 66369A9; Mon, 13 Mar 2023 18:47:38 +0100 (CET) Date: Mon, 13 Mar 2023 18:47:38 +0100 From: Alvaro Herrera To: Dean Rasheed Cc: Alexander Korotkov , pgsql-hackers Subject: Re: Lock mode in ExecMergeMatched() Message-ID: <20230313174738.6gozdobp5gd6xfx7@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2023-Mar-13, Dean Rasheed wrote: > I'm wondering now if it really matters what lock mode we use here. If > the point of calling table_tuple_lock() after a concurrent update is > detected is to prevent more concurrent updates, so that the retry is > guaranteed to succeed, then wouldn't even LockTupleNoKeyExclusive be > sufficient in all cases? After all, that does block concurrent updates > and deletes. The difference in lock mode should be visible relative to concurrent transactions that try to SELECT FOR KEY SHARE the affected row. If you are updating a row but not changing the key-columns, then a KEY SHARE against the same tuple should work concurrently without blocking. If you *are* changing the key columns, then such a lock should be made to wait. DELETE should be exactly equivalent to an update that changes any columns in the "key". After all, the point is that the previous key (as referenced via a FK from another table) is now gone, which happens in both these operations, but does not happen when an update only touches other columns. Two UPDATEs of the same row should always block each other. Note that the code to determine which columns are part of the key is not very careful: IIRC any column part of a unique index is considered part of the key. I don't think this has any implications for the discussion here, but I thought I'd point it out just in case. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/