public inbox for [email protected]  
help / color / mirror / Atom feed
From: Masahiko Sawada <[email protected]>
To: Andres Freund <[email protected]>
Cc: Ayush Tiwari <[email protected]>
Cc: [email protected]
Subject: Re: tid_blockno() and tid_offset() accessor functions
Date: Thu, 12 Mar 2026 09:51:50 -0700
Message-ID: <CAD21AoC48MQ4W5vU1ZPaXXtFPtiacEREN_XXrn3SRRku5cighg@mail.gmail.com> (raw)
In-Reply-To: <fe2ay3acydk6sd3iwkvol7t3kgswzfsuaz2vdgqornx4hg7ji2@dpwilwuzq7a2>
References: <CAJTYsWUzok2+mvSYkbVUwq_SWWg-GdHqCuYumN82AU97SjwjCA@mail.gmail.com>
	<CAD21AoBdgM+4X=Wg0T==C9ahenm2nUb=q5AxxeEb_JVoKOzbgw@mail.gmail.com>
	<fe2ay3acydk6sd3iwkvol7t3kgswzfsuaz2vdgqornx4hg7ji2@dpwilwuzq7a2>

On Wed, Mar 11, 2026 at 2:50 PM Andres Freund <[email protected]> wrote:
>
> Hi,
>
> On 2026-03-11 14:48:08 -0700, Masahiko Sawada wrote:
> > On Fri, Feb 27, 2026 at 10:59 AM Ayush Tiwari
> > <[email protected]> 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.

Regards,

-- 
Masahiko Sawada
Amazon Web Services: https://aws.amazon.com





view thread (18+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: tid_blockno() and tid_offset() accessor functions
  In-Reply-To: <CAD21AoC48MQ4W5vU1ZPaXXtFPtiacEREN_XXrn3SRRku5cighg@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox