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 1pVVHD-0002ji-S4 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2023 10:26:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pVVHC-0006Bl-I9 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2023 10:26:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pVVHC-0006Bb-7n for pgsql-hackers@lists.postgresql.org; Fri, 24 Feb 2023 10:26:06 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pVVH5-0000tC-HT for pgsql-hackers@lists.postgresql.org; Fri, 24 Feb 2023 10:26:05 +0000 Received: by mail-ed1-x52f.google.com with SMTP id cq23so52665202edb.1 for ; Fri, 24 Feb 2023 02:25:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=UHwh7/bV7Xzmu6f4OV946ByksyQeS2PI0vLDzozjYms=; b=WydyK0laF4aecKuX785XYuSX9abrYQL70sKjNxKWH4Cjvu14V0I3gAmay9QFJee9uj LNfPDnt3D/BWN0NUaFdNVmP2Mv0dEnZVg10BVIGsWaJ2mm057jIoFwkRo4V2euzvvXUY txj8mzB+eknVUpF/fmaWtNG5MRfxihk50QSBzaD0vM2soS5UsZlyRo49qXQMrCJ18TAv 7ToLzKYH8rl6EeGgaUG18DyejHVSXhcLEQiVjWJxaYRJu1C1bWGyspKi+u8X5ei06+cz 4gxrxDhEMAim+erNfLov2dXJz+GLWeRGKn/gTj8lWrmmASyuX+zx6gJvWHxRGJSplNuw SGew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=UHwh7/bV7Xzmu6f4OV946ByksyQeS2PI0vLDzozjYms=; b=NfiyQQ/8ufPTe33RMWaOFMkcRsh7nu9peP3ztoW3h7DsRJLMRbCj+3N2ZMt/gO13sO wzmlBxm575TOYM+Dk0TGe/SXHHdt3WHYxqYTjJPLq6mv+zha4ezw+BT15lOC0X9Q+VpO yq0GEbQd+g8sXaJksnLDqGtv+jE40szpcbp3/Ko+zMJc6RPIPk3SS79HH7ulzb1HO3vA feNCQQwVapUxs89GpKhng3vTzjWhPlVKHLspy/+UzjvEm8WyiARlCUU8PsbeCjRSSpgx cJ9s0ycUlEelCdbN+y2810nV7NxM0x4/Ef6nI2evMZfTbff1X84Z94tvKcnl74shREv0 ahzQ== X-Gm-Message-State: AO0yUKWS8Ep/xzMmjQWVr48SY5xvgepZ0kg4NmR5m4qwk1hHKb6kYQSu qLVzpAoFNe1H4i3XXRC8ruYifmgRHukam0oVqJvHTF7R83/zJpd6hVjgTtc6H0y0CzTelHplvw6 pAByqwvqlJbm/Pzv7lT9m9XtL+7W/zBLLdeFpXIYB3TgUJTcB0qF/e42XcJfrJJdzwOn1WV4UVb ZzXW5alGITakTyyejLY8q1+UlMLts4x4hhd7v6XuR6wnvpygSAoRZf X-Google-Smtp-Source: AK7set92mejrpO6O6zAkmaLeuF6pnsNW7hgQpRBSdVODY7v7F+vneZXJ058nzsz46z+vh90QQwxLyw== X-Received: by 2002:aa7:c0c4:0:b0:4ac:be83:2044 with SMTP id j4-20020aa7c0c4000000b004acbe832044mr14668173edp.3.1677234357748; Fri, 24 Feb 2023 02:25:57 -0800 (PST) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id fp1-20020a1709069e0100b008cda6560404sm6738737ejc.193.2023.02.24.02.25.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Feb 2023 02:25:57 -0800 (PST) Message-ID: Date: Fri, 24 Feb 2023 11:25:55 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: PATCH: Using BRIN indexes for sorted output To: Alvaro Herrera , Matthias van de Meent Cc: Justin Pryzby , Andres Freund , Greg Stark , Zhihong Yu , PostgreSQL Hackers References: <20230224083916.tn4ikos65f4ep2od@alvherre.pgsql> Content-Language: en-US From: Tomas Vondra In-Reply-To: <20230224083916.tn4ikos65f4ep2od@alvherre.pgsql> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 2/24/23 09:39, Alvaro Herrera wrote: > On 2023-Feb-23, Matthias van de Meent wrote: > >>> + for (heapBlk = 0; heapBlk < nblocks; heapBlk += pagesPerRange) >> >> I am not familiar with the frequency of max-sized relations, but this >> would go into an infinite loop for pagesPerRange values >1 for >> max-sized relations due to BlockNumber wraparound. I think there >> should be some additional overflow checks here. > > They are definitely not very common -- BlockNumber wraps around at 32 TB > IIUC. But yeah, I guess it is a possibility, and perhaps we should find > a way to write these loops in a more robust manner. > I guess the easiest fix would be to do the arithmetic in 64 bits. That'd eliminate the overflow. Alternatively, we could do something like prevHeapBlk = 0; for (heapBlk = 0; (heapBlk < nblocks) && (prevHeapBlk <= heapBlk); heapBlk += pagesPerRange) { ... prevHeapBlk = heapBlk; } regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company