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 1pVZmH-0001Hh-7F for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2023 15:14:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pVZmF-00015n-NZ for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2023 15:14:27 +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 1pVZmF-00015d-ED for pgsql-hackers@lists.postgresql.org; Fri, 24 Feb 2023 15:14:27 +0000 Received: from new3-smtp.messagingengine.com ([66.111.4.229]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVZmB-0002ej-8T for pgsql-hackers@lists.postgresql.org; Fri, 24 Feb 2023 15:14:27 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailnew.nyi.internal (Postfix) with ESMTP id B473F5802E7; Fri, 24 Feb 2023 10:14:20 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 24 Feb 2023 10:14:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :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=fm1; t=1677251660; x=1677258860; bh=c m/wNG5MrsIrW2ejMqeGo6FRur1htW5cT3QNz/1rSqw=; b=pADTQosLcUDY1KfNz dHzw7qzLtCEpZ1dJ99V+9+bUY9LfGFups/5v8T0M9V0CEZoVIo8M7p6iLerHaDsk NpYgSirGKRn7hN9R7n+++MTLQk5qgKPn+n3StsiyuBQPFnr5OWGT5D5GJCdwYV/A qJXCVaVunHpUZ8eHj4ZLogwLVnV6qN2RMTQbmCt8bNPHyKq1kH5bEPVpritwmaiW le48Bz9OHE1tWpRaQx99QiQzZ+yckzEU0Gif+4RMDg8+xy1pG0yuqqlcVqOJCgKw TlpK3aN/hjdK0yu3TK4IqS5JxisUoQIjOwX+sXAUhzenNyBewFXAGd1HFKNEUGiL tV2wg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrudekfedgieelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkgggtugfgjgesthekredttddtjeenucfhrhhomheptehlvhgr rhhoucfjvghrrhgvrhgruceorghlvhhhvghrrhgvsegrlhhvhhdrnhhoqdhiphdrohhrgh eqnecuggftrfgrthhtvghrnhepvdektdffudfftdffffehfffhjeejhffgieeuueekjeek fffgudffhfduffffueevnecuffhomhgrihhnpegvnhhtvghrphhrihhsvggusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrlhhv hhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhg X-ME-Proxy: Feedback-ID: ia2694551:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 24 Feb 2023 10:14:19 -0500 (EST) Received: by perhan.alvh.no-ip.org (Postfix, from userid 1000) id EC798B3; Fri, 24 Feb 2023 16:14:16 +0100 (CET) Date: Fri, 24 Feb 2023 16:14:16 +0100 From: Alvaro Herrera To: Tomas Vondra Cc: Matthias van de Meent , Justin Pryzby , Andres Freund , Greg Stark , Zhihong Yu , PostgreSQL Hackers Subject: Re: PATCH: Using BRIN indexes for sorted output Message-ID: <20230224151416.waqpi5syn36hun2l@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-Feb-24, Tomas Vondra wrote: > I guess the easiest fix would be to do the arithmetic in 64 bits. That'd > eliminate the overflow. Yeah, that might be easy to set up. We then don't have to worry about it until BlockNumber is enlarged to 64 bits ... but by that time surely we can just grow it again to a 128 bit loop variable. > Alternatively, we could do something like > > prevHeapBlk = 0; > for (heapBlk = 0; (heapBlk < nblocks) && (prevHeapBlk <= heapBlk); > heapBlk += pagesPerRange) > { > ... > prevHeapBlk = heapBlk; > } I think a formulation of this kind has the benefit that it works after BlockNumber is enlarged to 64 bits, and doesn't have to be changed ever again (assuming it is correct). ... if pagesPerRange is not a whole divisor of MaxBlockNumber, I think this will neglect the last range in the table. -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/