Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDJrx-00HT7G-4w for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 08:45:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tDJrv-00BYg5-9x for pgsql-hackers@arkaria.postgresql.org; Tue, 19 Nov 2024 08:45:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDJru-00BYfx-7q for pgsql-hackers@lists.postgresql.org; Tue, 19 Nov 2024 08:45:55 +0000 Received: from fhigh-b4-smtp.messagingengine.com ([202.12.124.155]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tDJrr-002iNL-I3 for pgsql-hackers@lists.postgresql.org; Tue, 19 Nov 2024 08:45:54 +0000 Received: from phl-compute-06.internal (phl-compute-06.phl.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id CC90125401A3; Tue, 19 Nov 2024 03:45:48 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Tue, 19 Nov 2024 03:45:48 -0500 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:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1732005948; x=1732092348; bh=4 /6yRqFP58nNmGw5GfGxMP5eIqJoWi8nSe/IjyBCK/0=; b=Ia5fbixZToZp8E3ZI KMQSjlXs2UJKuPlUXxR411hXoOu069u78UWTLaCsevl311gjWAlQGYS+YkxaMUXh gohgjmdmuJsqhSunL7RYmMnPkLpxMtnIBbf85sQmVYI6q+6HCztXJ+NLMcig3BFK oAMyrtUUHTgA8ZIG7rDOEwIlZg0oauRR/6+onH3iO2ArCAxQHE+jNpDoCosZTJo7 PiPK/jL7L6KZP/Q3BROrfaTpCGbffuQQiBgZOHursYzR4OW/6Cp5Wfxr3cPrTwzo Wd2uE8e7skqNO+90rlyV7pFVwGV0PjL7dgQaFXjAh3iRx7CELVUg/HKiyF2B0prT iVg+Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrfedugdduvdefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeen ucfhrhhomheptehlvhgrrhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhh drnhhoqdhiphdrohhrgheqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffh jeejhffgieeuueekjeekfffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrph hrihhsvggusgdrtghomhenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgr ihhlfhhrohhmpegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhnsggprh gtphhtthhopeefpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopeifihhllhesvgig thhrrghhohhprdgtohhmpdhrtghpthhtohephihvohhnnhgvsegvgihtrhgrhhhophdrtg homhdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehlihhsthhsrdhpohhsthhg rhgvshhqlhdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 19 Nov 2024 03:45:48 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1732005943; bh=1dXnLP/wiT0ykKV4xtuYkMNlP/JF6urTGt13rUrhpu4=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=qSilOsL4fwiNCYCYyDwPG25B/O0gfPj5N4lj096tJPAsvJuMe0R/UqtzC6mB96Ppi 3H04DZOKSfe0zGn6MCthkSIkpUMN/JU0MfnxY8pbumHBohdjIfaeZXZk7i7k3YWzqH TVZsBFIMBNPE8LQKmF1rK9TWXX3kLmvKbmYuhTiqx5XDN1OXvnrcITwRAiJ/RmoAQZ VCKaBjf8KcyqhPMTFGoNLsA/lZtf1gxvnHALKIB6/zftYPnH/z+G3C43b8qlD/tghD cX/C1x89aQj8jEbBzoKQycA16eoeEqc5icrdDCl98ajnS78dyaNKP7MB6zaOOAKFZw dEkK2IzvBnonQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id DAF508C; Tue, 19 Nov 2024 09:45:43 +0100 (CET) Date: Tue, 19 Nov 2024 09:45:43 +0100 From: Alvaro Herrera To: Will Mortensen Cc: PostgreSQL Hackers , Yvonne Chen Subject: Re: README.tuplock and SHARE lock Message-ID: <202411190845.qfykjp5l4ijx@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 2024-Nov-18, Will Mortensen wrote: > README.tuplock says: > > > There is one exception > > here: since infomask space is limited, we do not provide a separate bit > > for SELECT FOR SHARE, so we have to use the extended info in a MultiXact in > > that case. (The other cases, SELECT FOR UPDATE and SELECT FOR KEY SHARE, are > > presumably more commonly used due to being the standards-mandated locking > > mechanism, or heavily used by the RI code, so we want to provide fast paths > > for those.) > > But looking at the explanations of the infomask bits further down (as > updated in commit cdbdc4382743fcfabb3437ea7c4d103adaa01324), as well > as the actual code for locking a not-yet-locked tuple in > compute_new_xmax_infomask(), this doesn't seem to be true. Was this an > oversight? Hmm, yeah, it seems you're correct about this being an oversight -- we don't necessarily use a multixact if all we want to do is to store a FOR SHARE lock. Instead, what we do is mark the tuple with two lock bits, per this bit in src/include/access/htup_details.h: #define HEAP_XMAX_SHR_LOCK (HEAP_XMAX_EXCL_LOCK | HEAP_XMAX_KEYSHR_LOCK) This can be seen in a WAL_DEBUG build, when doing SELECT FOR SHARE of a tuple does this: 2024-11-19 09:39:37.011 CET [65326] LOG: INSERT @ 0/1B92EB0: - Heap/LOCK: xmax: 744, off: 1, infobits: [LOCK_ONLY, EXCL_LOCK, KEYSHR_LOCK], flags: 0x00 Note that the infobits don't include anything about it being MULTI. Contrast that with the case where the same tuple is locked by two transactions simultaneously: 2024-11-19 09:40:45.582 CET [65326] LOG: INSERT @ 0/1B93008: - MultiXact/CREATE_ID: 1 offset 1 nmembers 2: 745 (sh) 746 (sh) 2024-11-19 09:40:45.582 CET [65326] LOG: INSERT @ 0/1B93040: - Heap/LOCK: xmax: 1, off: 1, infobits: [IS_MULTI, LOCK_ONLY, EXCL_LOCK, KEYSHR_LOCK], flags: 0x00 Here we first see the MultiXact being created (with two transactions, both using SHARE mode), then the tuple being locked with IS_MULTI. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ Subversion to GIT: the shortest path to happiness I've ever heard of (Alexey Klyukin)