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 1rffP7-001TIc-9m for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Feb 2024 12:20:49 +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 1rffP5-003Tnw-HB for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Feb 2024 12:20:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rffP4-003Tno-Ly for pgsql-hackers@lists.postgresql.org; Thu, 29 Feb 2024 12:20:47 +0000 Received: from wfhigh6-smtp.messagingengine.com ([64.147.123.157]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rffP1-0027wy-5K for pgsql-hackers@postgresql.org; Thu, 29 Feb 2024 12:20:45 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.west.internal (Postfix) with ESMTP id 1358A18000CF; Thu, 29 Feb 2024 07:20:41 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Thu, 29 Feb 2024 07:20:42 -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-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1709209241; x= 1709295641; bh=lVKr/ERZCJ+M5hupxu5Xw+YhKmH5YiaALbY0+Xakp3M=; b=d IVJ2MtyysSS7Ybqh2n9H4v1N+tnTE5Y7wOBzYLxOosAyVtTHswKkCEpSoyQuLCVP s20uMnpttlCiaPpauKHC2U/eX/aIrdZ1bBNsz5yyfzDMmIkzUjK2XVNrhpI61Jfk RWSMABSriczpYYc/EcXiy8ASIrZqZKKyZV8vSI5YAbBj0fAjWboy2K+qCAZIN72C lzZCOtyDPWqYODPcG4hLRIlgxMHVggd8K6VGItU7mAwkE34CufVCk8ImC4GRYZ8N dEP9boBvJfievmxaJi+k5nssl/BneQ1ReZLFqwpq42pAC07bA7i9bc5ekPoE03ip aE7g9ogP2PljEYSHm5CUg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrgeelgdefkecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpeffhffvvefukfggtggugfgjsehtkeertddttdejnecuhfhrohhmpeetlhhvrghr ohcujfgvrhhrvghrrgcuoegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgqe enucggtffrrghtthgvrhhnpedvkedtffduffdtffffheffhfejjefhgfeiueeukeejkeff gfdufffhudffffeuveenucffohhmrghinhepvghnthgvrhhprhhishgvuggsrdgtohhmne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprghlvhhh vghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 29 Feb 2024 07:20:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alvh.no-ip.org; s=schmee; t=1709209239; bh=r9Gs4WQ9IcDIo4fnBwhAiYcOPkgWIrCM4SZkpFcp3As=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=nN9wIxP3jMZYGRNH2T26Vf0Gg2dgOfTTE/30NiUapI8vplVpeOFmrCmRzw4SoY7Sn dtOyPj83FhE6vvfq5Y4CIIBnNAj8YXhA+V1vnVeQt4OfKVCD6e0GAd1YztX5wE2Vto YB7Nr6YBloZlOQYzHUYttlMZeRvTWcBT5yZCGh1j6VFIHberTy4XcUJTFhO7Z420eO tkwyKs7LeYFNRf0oTJ3Dm0Fz5BUTEYm1dHJEJkOFzHgm8P9ROrhDDpIzOjxVxo8euA db7pwlioegCTVoPVGl4YtrmTJ3LxpYpgXcX6E5l4FLz60X1xEsGBRmv/52pFAQ4X9Y 3YNG0103i5adQ== Received: by schmee.alvh.no-ip.org (Postfix, from userid 1000) id 4151ED40; Thu, 29 Feb 2024 13:20:39 +0100 (CET) Date: Thu, 29 Feb 2024 13:20:39 +0100 From: Alvaro Herrera To: Tomas Vondra Cc: Alexander Lakhin , Soumyadeep Chakraborty , Matthias van de Meent , pgsql-hackers , Ashwin Agrawal Subject: Re: brininsert optimization opportunity Message-ID: <202402291220.gmjxa5wohzsh@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-Feb-13, Tomas Vondra wrote: > One thing that is not very clear to me is that I don't think there's a > very good way to determine which places need the cleanup call. Because > it depends on (a) what kind of index is used and (b) what happens in the > code called earlier (which may easily do arbitrary stuff). Which means > we have to call the cleanup whenever the code *might* have done inserts > into the index. Maybe it's not such an issue in practice, though. I think it's not an issue, or rather that we should not try to guess. Instead make it a simple rule: if aminsert is called, then aminsertcleanup must be called afterwards, period. > On 1/8/24 16:51, Alvaro Herrera wrote: > > So I think we should do 0001 and perhaps some further tweaks to the > > original brininsert optimization commit: I think the aminsertcleanup > > callback should receive the indexRelation as first argument; and also I > > think it's not index_insert_cleanup() job to worry about whether > > ii_AmCache is NULL or not, but instead the callback should be invoked > > always, and then it's aminsertcleanup job to do nothing if ii_AmCache is > > NULL. [...] > I don't quite see why we should invoke the callback with ii_AmCache=NULL > though. If there's nothing cached, why bother? It just means all cleanup > callbacks have to do this NULL check on their own. Guessing that aminsertcleanup is not needed when ii_AmCache is NULL seems like a leaky abstraction. I propose to have only the AM know whether the cleanup call is important or not, without index_insert_cleanup assuming that it's related to ii_AmCache. Somebody could decide to have something completely different during insert cleanup, which is not in ii_AmCache. > I wonder if there's a nice way to check this in assert-enabled builds? > Could we tweak nbtree (or index AM in general) to check that all places > that called aminsert also called aminsertcleanup? > > For example, I was thinking we might add a flag to IndexInfo (separate > from the ii_AmCache), tracking if aminsert() was called, and Then later > check the aminsertcleanup() got called too. The problem however is > there's no obviously convenient place for this check, because IndexInfo > is not freed explicitly ... I agree it would be nice to have a way to verify, but it doesn't seem 100% essential. After all, it's not very common to add new calls to aminsert. -- Álvaro Herrera 48°01'N 7°57'E — https://www.EnterpriseDB.com/