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 1w0jH0-0029x5-39 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 16:52:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w0jGx-00Fuuq-07 for pgsql-hackers@arkaria.postgresql.org; Thu, 12 Mar 2026 16:52:31 +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 1w0jGw-00Fuuh-2P for pgsql-hackers@lists.postgresql.org; Thu, 12 Mar 2026 16:52:31 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w0jGv-00000001nUc-0iTp for pgsql-hackers@postgresql.org; Thu, 12 Mar 2026 16:52:30 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5a131870b72so1496051e87.1 for ; Thu, 12 Mar 2026 09:52:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773334347; cv=none; d=google.com; s=arc-20240605; b=fkGUgK8/BGkxlwWwB7lZir0jiauVyPPKcdOt+xGbJ00nzw8OZhfAxPQSJ0N9SCaOmn LBjPUd3sHuyaBRYNhYOEagFz0K8m9dvmTLGMVA3XlRGXju1JusAEYBf1G27A0x72RAtg SFe+ClyLGbncFMQrr2X6pvTuNuZC4b3wXbYxiYo94xUrQQuURaAXCK9AslDkVCWvPB2p sJmbFVU7b+tyiJd+GNiZzUo4ZzvLVdfMfWbrP34F5l7q7fm9SktJCpWu+jxRdblsx4So L14l12G6S2kaRsHUb8LYj0qxdBToFdp1lhYvLYxzoC4CabgJqhyMHFcrhYrYponpet80 /9Dw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=a0jvMlNPSQKW0ZoSXJkLm0+lbOzTuYo3SXIw3UJ5n9A=; fh=96ezk+RJqQn1B4pUtPH3eDTH2/vpPjX8GucFTvogkX8=; b=ad79UYQl1uWVqOxdSMvkyc8DBnFgBmC6YhRCB/jlEKmq1C5/eWFAAvX8ZpmstwqSCC JlAurVqXaJpSqEbzu7n+AkYPzJ/YxR+CrWlMxC0RiS9N5ZJxk/mf43IcAdrmDE1nKF2s nAeahkPtHTYP5ilC9MAtqLKTpbZgtScOgkV7xQdA8LIuyf4geZp7DaN0af5zMiUom/16 7xKNpW2Hp3/QDe9apTAPSsnbpEsQCRhplh44gRhk+aGwlVmrPLVbNlkHPuGZTJlQ+tP+ adxLL60a8IV9fpNWBfu+vjOkuHXXXelgY0TkApM4FNCaIBTnNbCRMqH2UXTg+lPGBMaA nZ5g==; darn=postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773334347; x=1773939147; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=a0jvMlNPSQKW0ZoSXJkLm0+lbOzTuYo3SXIw3UJ5n9A=; b=F39SW/pftrk9T249vCinWd6kf7n788KUKYCJpwpZSZDz9o6wcMT+jxBwbbXFgWprSC M/kWMKb9v08XPFPOIcnsOyxde8PmLRWVXw6FS32GGuW++6ZpMLHfZyzxki4cH07KhKSj ajJFLSW8V8d5YhtGbsMfBdawLUboX0Oma7wa4nnPouS7aqaQ48axcsYqJCKcHsYJvrUh NiaNFC6uFWB3XbfR4Qi5Juq85Biyp5pRg6DMedP0lezKtqosFpuN8J+rnD3gIRQgzE2C sZcqSiIRdFyFyrk5g2+MCzSfg/Wlm3wwISnaVIJdbel0i2NA2wkRiGNtaPsyDbtCeR1B dR5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773334347; x=1773939147; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=a0jvMlNPSQKW0ZoSXJkLm0+lbOzTuYo3SXIw3UJ5n9A=; b=rYkZvvEW3Q5TIlyWDLgEG+QWyUHG0LnhpuHGUWCGchdqzf0WC/nZ6RZUiOuDW+ldbJ lXh5dW9ExE6ondNs9EfHlqhoGEfa2LZpfyct2UYoBWxIMbNFkB/xeZnuk/ctZep8eOMF pYdBZ+jlRd51y/CkQXTu5rkQtyr98ujS5m2xYxzuDA+LstPsdn19nxYXLk570oh3Ij08 XW46NnqhCKeKNYGPKfUI1/r6vnSMUQHc+Hr+EwCc8rZKZjroC6PstrzYAxNHv8dGhApF ehKhqCAI7ucfI2aXLU4U7r5LAsC+J2o4es+ShKKTIV98QQG0Xj3ipSiEJjChZkxgmd0S AvhQ== X-Forwarded-Encrypted: i=1; AJvYcCXdxYfZ2bRlTtDjAXfWkGIHm3pxc82tTuLAaj/DNLTdYttVJHX/INS8Nq1zrLWKL1ofrd9THqRyRZqG+JdN@postgresql.org X-Gm-Message-State: AOJu0YzL9tEOeKyQ6NDWESGNP6Vpy7NvVHL/TpauIQIOA6WWOTVMWjNm O5BaMD7DwBrdSTd36mdt3zUezy+2XnsZsWZvK3E9zRpTbFGrwhjqpQinoJaZfgIKcw7qRaN1y65 U85YheLb+y6/H0qfy4BI6A/nDYGT2f4I= X-Gm-Gg: ATEYQzwoun0sHfRgy3yMvEkM4mnkvOpCzek1P2dCa7+KVEGCGcChyDh+6NcWh45VNYY EOoZ8HeI2z/Ooqa1MuwEVLGJxO3FtAZytOQqPKlab65mX4KSV5n1DOxa2padL8R4L8uzHBtxkq1 EVgEgu3UO0qK426SRGfr53cNc2R142YqpdxsWH4uQueX5LYTHI85WDGX6MUUavqxO5Ptg4cXR2e NZ4BgRsNvTE2k5xP1MnUIEhR3e3YYGfWLDcdeA8ShDsBfh3yOrU6Xk20qhRUlqj0AcvZtXXPbEn lmH6Kp7e X-Received: by 2002:ac2:51d4:0:b0:5a1:2abf:c699 with SMTP id 2adb3069b0e04-5a162b25e47mr69591e87.29.1773334346957; Thu, 12 Mar 2026 09:52:26 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Masahiko Sawada Date: Thu, 12 Mar 2026 09:51:50 -0700 X-Gm-Features: AaiRm51KRDhPUOi4OnEbQlZPI7yIDSq1j7iUmqLEUnkkWaLeK8uZk310ddglB8E Message-ID: Subject: Re: tid_blockno() and tid_offset() accessor functions To: Andres Freund Cc: Ayush Tiwari , pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Mar 11, 2026 at 2:50=E2=80=AFPM Andres Freund = wrote: > > Hi, > > On 2026-03-11 14:48:08 -0700, Masahiko Sawada wrote: > > On Fri, Feb 27, 2026 at 10:59=E2=80=AFAM Ayush Tiwari > > wrote: > > > > > > Hi hackers, > > > > > > As of now we don't have any built-in way to extract the block and off= set components from a TID. When people need to group by page (like for bloa= t analysis) or filter by specific blocks, they usually end up using the `ct= id::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 als= o > 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. Regards, --=20 Masahiko Sawada Amazon Web Services: https://aws.amazon.com