Re: tid_blockno() and tid_offset() accessor functions - Mailing list pgsql-hackers

From Andres Freund
Subject Re: tid_blockno() and tid_offset() accessor functions
Date
Msg-id fe2ay3acydk6sd3iwkvol7t3kgswzfsuaz2vdgqornx4hg7ji2@dpwilwuzq7a2
Whole thread
In response to Re: tid_blockno() and tid_offset() accessor functions  (Masahiko Sawada <sawada.mshk@gmail.com>)
Responses Re: tid_blockno() and tid_offset() accessor functions
List pgsql-hackers
Hi,

On 2026-03-11 14:48:08 -0700, Masahiko Sawada wrote:
> On Fri, Feb 27, 2026 at 10:59 AM Ayush Tiwari
> <ayushtiwari.slg01@gmail.com> 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
groupby 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
TIDsoutside 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?

Greetings,

Andres



pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: tid_blockno() and tid_offset() accessor functions
Next
From: Nikolay Samokhvalov
Date:
Subject: Re: [PATCH v1] command_tag_format — protocol-level command tag negotiation via _pq_