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 1pVaYb-00048K-Jz for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2023 16:04:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pVaYa-0000u7-96 for pgsql-hackers@arkaria.postgresql.org; Fri, 24 Feb 2023 16:04:24 +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 1pVaYZ-0000ty-V2 for pgsql-hackers@lists.postgresql.org; Fri, 24 Feb 2023 16:04:23 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pVaYX-0003mr-ID for pgsql-hackers@lists.postgresql.org; Fri, 24 Feb 2023 16:04:22 +0000 Received: by mail-ed1-x532.google.com with SMTP id cy6so51137901edb.5 for ; Fri, 24 Feb 2023 08:04:21 -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:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=y9KqIQns/H0qhPFi8Morf7Tv7QbcebAideqEAIdH2Uk=; b=Xu78a8VQ0kd63uBDga9e6jrBtUEGo90xvp3dXfV2fVOj7j/Yneqc7NyRPsvheIHmJH ooYQ+km2JlgnALUbyZB/62g/JuRSzFnB1AtCgwz9E61quQC+tjsqJiRY0v3lt6CCn5Zz e0vyQACJ6gaZyTI+ma8nIS67ZBSc4CL1gLQw6VvKSTlxo9Aa+5DSePhQBFTAhxre5waq WMELC7L4rqiznQuPibKZtgcQAEADchLo/TAEINOKuzMbyg8Vfe9NRDnXa9LvGhFd6eKT PYvA3LIivBPKantlvLTGZwf2kPMjpuoE1INZiknnyP2C/75vdAw+ehRJIbypeewfWS/6 7jgg== 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:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=y9KqIQns/H0qhPFi8Morf7Tv7QbcebAideqEAIdH2Uk=; b=ICdf+1RfARp3eILANYN1LHnpZWM1c8fF+jaYEdxiKH4yrS7PCRtlPz093wxKH6rncz 6RW4jnM6QFz86rCXZQZQUGvthM5PL1IW/kIP16JmVMjES4pUId1c8PM5oa+MqZNXzdmV ZkkzV+HcwcAvhfwvEtD9t1nw1KHszvEeEVMiIUptXAcMIOE+MJaXtnaCWC78DqPEil+p ZEx9VwT6Jg3VT1sfvpHAdZqHdJbgGZWL7pIwRLqh0xkXAGWRRvL7kc08RHQAXiFxYcyx Vh5Hk/Vu0D/PtQhkcYzoCao2noQXzGPat8ePpSaIfbbeywn5kQ+hb/l0E/dCTExEX1JT EEMw== X-Gm-Message-State: AO0yUKWCRmLpUvveVJAz3p7E+ZjgvoUnoUoImiEf2050wvkc38wbp5c4 ZsQnl/TNV92I3MC+blsbAzhcpoXpIjpIZgLBTqV6bE1QGoBqMzAk4umucFBLn2S2yZD1d9guI0p 2hlr9eyngjADoLyhc+wB0UMZCZKxzqOVm+XJ+FfdWh5mGUKvOulCU8hNPUoL0PW7jzTBxw4m0pf EybJW7YRKqktG1XrxNWFgH9WfO4sKWyOdmEXediaKEFmZwx8xG+iae X-Google-Smtp-Source: AK7set/fFURfTVOSsvRJvDrfLnVM7WnOnPvEsfIjM0H2EIPiW0JVDmqOGY6jIOdk2uXSbN9kAs7kPQ== X-Received: by 2002:a17:906:1999:b0:8b1:347c:85c8 with SMTP id g25-20020a170906199900b008b1347c85c8mr21900279ejd.17.1677254660014; Fri, 24 Feb 2023 08:04:20 -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 u16-20020a1709063b9000b008d7a8083dffsm5978392ejf.222.2023.02.24.08.04.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Feb 2023 08:04:19 -0800 (PST) Message-ID: <5598409b-4ce8-dec2-acee-272e94c4b21b@enterprisedb.com> Date: Fri, 24 Feb 2023 17:04:17 +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 Content-Language: en-US To: Alvaro Herrera Cc: Matthias van de Meent , Justin Pryzby , Andres Freund , Greg Stark , Zhihong Yu , PostgreSQL Hackers References: <20230224151416.waqpi5syn36hun2l@alvherre.pgsql> From: Tomas Vondra In-Reply-To: <20230224151416.waqpi5syn36hun2l@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 16:14, Alvaro Herrera wrote: > 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). > Did anyone even propose doing that? I suspect this is unlikely to be the only place that'd might be broken by that. > ... if pagesPerRange is not a whole divisor of MaxBlockNumber, I think > this will neglect the last range in the table. > Why would it? Let's say BlockNumber is uint8, i.e. 255 max. And there are 10 pages per range. That's 25 "full" ranges, and the last range being just 5 pages. So we get into prevHeapBlk = 240 heapBlk = 250 and we read the last 5 pages. And then we update prevHeapBlk = 250 heapBlk = (250 + 10) % 255 = 5 and we don't do that loop. Or did I get this wrong, somehow? regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company