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 1phEZq-0001OT-Im for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Mar 2023 19:01: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 1phEZp-0005WO-Df for pgsql-hackers@arkaria.postgresql.org; Tue, 28 Mar 2023 19:01: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 1phEZp-0005WF-4N for pgsql-hackers@lists.postgresql.org; Tue, 28 Mar 2023 19:01:49 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1phEZi-0001sP-VJ for pgsql-hackers@postgresql.org; Tue, 28 Mar 2023 19:01:48 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.west.internal (Postfix) with ESMTP id 418633200912; Tue, 28 Mar 2023 15:01:40 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute3.internal (MEProxy); Tue, 28 Mar 2023 15:01:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:sender:subject:subject:to:to; s=fm2; t= 1680030099; x=1680116499; bh=UR8sZB+p5seVpOUfK3hlw90YBZwSs21mDjS tRRvmbzs=; b=Ub3pqTN3hs9WrSOJZEBWtYQCy16c07N51jUcO8QMGUKU0N0YD3w 5oLkbZZj+khbXd1T1eDQHMXs6YkrX3De11IYAOrRg8+CStQfxZIPfRCXN+8yEapj es1hqTo/pfNaz0NVFX7xSwcio9NduNLrbAGmlL3PA615EfVGF3im2XPg5TFUT693 n5O74XfEk2+NVQYjUk7Ju5TxVEy3hMKwLuBiG3dORz6m4Ivkizs3uur4qQe6QA/O +truROVv54yi8et+ZmvFy6BkKH+M5Jb9BJMfmC9lSDNH/5fUKcnC2sTmpGD20Chb q5bpr9+o4vRcIZ3QpNKaGLZsrCuEYD7C65A== 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 :references: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= 1680030099; x=1680116499; bh=UR8sZB+p5seVpOUfK3hlw90YBZwSs21mDjS tRRvmbzs=; b=u9uvN+jWgQUO/7txPe9vnMdCifVYT7hFcWrczCHF8DCPRRDbIV/ oYfZgkS0TG2Dxu5RXArJO1sBG5Al8MBS6SEOW2H91KHYd2m4FYjdcfDD7FbekEFH 1tZx+SMnJn7yQtCFwRayzIfRXeTY97zFiZwGG9ahdbl2bCIoJ/ClKE+ivbd/mduW GLFAAdfP5fLHrRUI2dGoG5rMpZg+cNJrw8krz13NPjtOVl1Ci9eSxl4rBa1V6HiK rSzX6kR/xtnCt+unRxgUYB6qgUbqvoFENtgW0XXUV1BCQMvLwPLAFXr0Zg6g7G/O ujH+Av+KcBiox6Sc6GaUeNmq4jkQyZTdHDA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehgedgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvvefukfhfgggtugfgjgesthekredttddtjeenucfhrhhomheptehn ughrvghsucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecugg ftrfgrthhtvghrnhephfeitefgleevtedtffejvedujeekjedugfdtveffjeelvddtfeek gefgjefhgfegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homheprghnughrvghssegrnhgrrhgriigvlhdruggv X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 28 Mar 2023 15:01:39 -0400 (EDT) Date: Tue, 28 Mar 2023 12:01:38 -0700 From: Andres Freund To: Peter Geoghegan Cc: pgsql-hackers@postgresql.org, Robert Haas , Heikki Linnakangas Subject: Re: Why mark empty pages all visible? Message-ID: <20230328190138.rlb4xwi5qfvcvf66@awork3.anarazel.de> References: <20230328014806.3vjochayt2bu3hr3@awork3.anarazel.de> <20230328043216.qg7zrotxbapzy7oa@awork3.anarazel.de> 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 Hi, On 2023-03-27 21:51:09 -0700, Peter Geoghegan wrote: > On Mon, Mar 27, 2023 at 9:32 PM Andres Freund wrote: > > > You haven't said anything about the leading cause of marking empty > > > pages all-frozen, by far: lazy_vacuum_heap_page(). Should it also stop > > > marking empty pages all-frozen? > > > > It's not obvious that it should - but it's not as clear a case as the > > ConditionalLockBufferForCleanup() -> lazy_scan_new_or_empty() one. In the > > latter, we know > > a) that we don't have to do any work to be able to advance the horizon > > b) we know that somebody else has the page pinned > > > > What's the point in marking it all-visible at that point? In quite likely be > > from RelationGetBufferForTuple() having extended the relation and then briefly > > needed to release the lock (to acquire the lock on otherBuffer or in > > GetVisibilityMapPins()). > > I think that there is significant value in avoiding special cases, on > general principle. If we stopped doing this in > lazy_scan_new_or_empty() we'd be inventing a new thing that cleanup > locks are supposed to protect against. Maybe something like that would > make sense, but if so then make that argument, and make it explicitly > represented in the code. I will probably make that argument - so far I was just trying to understand the intent of the current code. There aren't really comments explaining why we want to mark currently-pinned empty/new pages all-visible and enter them into the FSM. Historically we did *not* enter currently pinned empty/new pages into the FSM / VM. Afaics that's new as of 44fa84881fff. The reason I'm looking at this is that there's a lot of complexity at the bottom of RelationGetBufferForTuple(), related to needing to release the lock on the newly extended page and then needing to recheck whether there still is free space on the page. And that it's not complicated enough (c.f. INSERT_FROZEN doing visibilitymap_pin() with the page locked). As far as I can tell, if we went back to not entering new/empty pages into either VM or FSM, we could rely on the page not getting filled while just pinning, not locking it. > > I don't follow. In the ConditionalLockBufferForCleanup() -> > > lazy_scan_new_or_empty() case we are dealing with an new or empty > > page. Whereas lazy_vacuum_heap_page() deals with a page that definitely > > has dead tuples on it. How are those two cases comparable? > > It doesn't have dead tuples anymore, though. > > ISTM that there is an issue here with the definition of an empty page. > You're concerned about PageIsEmpty() pages. And not just any PageIsEmpty() page, ones that are currently pinned. I also do wonder whether the different behaviour of PageIsEmpty() and PageIsNew() pages makes sense. The justification for not marking PageIsNew() pages as all-visible holds just as true for empty pages. There's just as much free space there. Greetings, Andres Freund