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.96) (envelope-from ) id 1w12Y4-002RK2-1p for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2026 13:27:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w12Y3-004ETC-0A for pgsql-hackers@arkaria.postgresql.org; Fri, 13 Mar 2026 13:27:27 +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.96) (envelope-from ) id 1w12Y2-004ET3-2W for pgsql-hackers@lists.postgresql.org; Fri, 13 Mar 2026 13:27:27 +0000 Received: from fhigh-a2-smtp.messagingengine.com ([103.168.172.153]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1w12Y1-00000001wZy-1OgO for pgsql-hackers@postgresql.org; Fri, 13 Mar 2026 13:27:26 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id D89A8140003B; Fri, 13 Mar 2026 09:27:24 -0400 (EDT) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 13 Mar 2026 09:27:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; 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:subject:subject:to:to; s=fm3; t=1773408444; x=1773494844; bh=VBL7hFNZ7/QU8YrCaLK7H91DNEip0Uu5 v9sm/nkbRzY=; b=p15d9Ih74G+JS7KtDfnSmyNnJiIUXJT/o0XHmhvQXpH2mwLH yqdSHjdLlmJCzCo71uv9ZfgjK0rwQQBWCu82R+lChJq3QRckkjl72+aN2Za1rShK 6b1AVKfSPIVJlQoIGtAKrifjhokr4NUgVqFkc8yOmHUPHNItSxRbYNkE1EUspQD2 A3zgTtaTFXn8XN7tpt9bW7M268Gj5awgjTVjF+r9lCcFEb9It4P/2I5c1k/nx3jv ZoeMHW5+GZbm7hA6dTiLHelvTIvQyGf2gV3TiqT3GJEUpGSq4nHXE0AyKzKEeyoy amRpTyEya4n6Q9L1EOSBs3iEFohyHr7YOLe1RQ== 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:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1773408444; x= 1773494844; bh=VBL7hFNZ7/QU8YrCaLK7H91DNEip0Uu5v9sm/nkbRzY=; b=h X+1LkkEjmDAlpV+5oxmvLweZvlRH7MwfD91bk55WowSdtRkm8yz5Fe4ZC5ysUMZP LTbLs/47IacZNmPIh1/YVsKs2/EP0zpW8WxKnAE0g/RaKke7OwzYteEPa+I5zcmD pCYze9rmPZOwtfZBpYCT3ORvtaKIisX45+tWPA8P94Ghrb0OilhPaiRFwnJIAMLk rSclyXyngmDrqdQ16z9vuXa8acCfBE1iA8wqli9rwmxNOY4s8KKZfthx1W/MUShk vZmmqBSfUquIE9fRHuSM7xA7yAbQ0kxopXkPr1LyQ0oz4yzWrXO8zJ1R0FQjQwtI 94lABi+0axVPATuv1TKdg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgddvkeeljeekucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepkfffgggfuffvvehfhfgjtgfgsehtkeertddtvdejnecuhfhrohhmpefrvghtvghr ucfgihhsvghnthhrrghuthcuoehpvghtvghrsegvihhsvghnthhrrghuthdrohhrgheqne cuggftrfgrthhtvghrnhepjefhveehtdetgfffhffhfeefgffghffflefgieeuueekhedv hedvfeehffdvfeeunecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomhepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgpdhnsggprhgtphhtthho peegpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehsrgifrggurgdrmhhshhhkse hgmhgrihhlrdgtohhmpdhrtghpthhtoheprghnughrvghssegrnhgrrhgriigvlhdruggv pdhrtghpthhtoheprgihuhhshhhtihifrghrihdrshhlghdtudesghhmrghilhdrtghomh dprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhr gh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 13 Mar 2026 09:27:23 -0400 (EDT) Message-ID: <8a2e78c3-2f63-455f-80a9-cbd9eebaa245@eisentraut.org> Date: Fri, 13 Mar 2026 14:27:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: tid_blockno() and tid_offset() accessor functions To: Masahiko Sawada , Andres Freund Cc: Ayush Tiwari , pgsql-hackers@postgresql.org References: Content-Language: en-US From: Peter Eisentraut In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12.03.26 17:51, Masahiko Sawada wrote: > On Wed, Mar 11, 2026 at 2:50 PM Andres Freund wrote: >> >> Hi, >> >> On 2026-03-11 14:48:08 -0700, Masahiko Sawada wrote: >>> On Fri, Feb 27, 2026 at 10:59 AM Ayush Tiwari >>> wrote: >>>> >>>> Hi hackers, >>>> >>>> As of now we don't have any built-in way to extract the block and offset components from a TID. When people need to group by page (like for bloat analysis) or filter by specific blocks, they usually end up using the `ctid::text::point` hack: >>>> >>>> SELECT (ctid::text::point)[0]::bigint AS blockno, >>>> (ctid::text::point)[1]::int AS offset >>>> FROM my_table; >>>> >>>> This works, but it's pretty clunky, relies on the text representation, and isn't great if you're trying to parse TIDs outside of SQL. >>>> >>>> The attached patch adds two simple accessor functions: >>>> - `tid_blockno(tid) -> bigint` >>>> - `tid_offset(tid) -> integer` >>> >>> How about adding the subscripting support for tid data type? For >>> example, ctid[0] returns bigint and ctid[1] returns int. >> >> That just seems less readable and harder to find to me. I think it'd also >> make the amount of required code noticeably larger? > > Yeah, using the dedicated functions would be more intuitive than using > magic numbers 1 and 2, and require less code. Also, you can use one-argument functions like field names, like tid.tid_blockno, so it's definitely more intuitive that way.