pgsql: Add tid_block() and tid_offset() accessor functions

From: Andres Freund <andres(at)anarazel(dot)de>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Add tid_block() and tid_offset() accessor functions
Date: 2026-04-05 19:29:26
Message-ID: E1w9T9x-0037aL-0g@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Add tid_block() and tid_offset() accessor functions

The two new functions allow to extract the block number and offset from a tid.

There are existing ways to do so (e.g. by doing (ctid::text::point)[0]), but
they are hard to remember and not pretty.

tid_block() returns int8 (bigint) because BlockNumber is uint32, which exceeds
the range of int4. tid_offset() returns int4 (integer) because OffsetNumber is
uint16, which fits safely in int4.

Bumps catversion.

Author: Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>
Discussion: https://postgr.es/m/CAJTYsWUzok2+mvSYkbVUwq_SWWg-GdHqCuYumN82AU97SjwjCA@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/df6949ccf7a6d5160e3068ed843eb46ab7bc2601

Modified Files
--------------
doc/src/sgml/func/allfiles.sgml | 1 +
doc/src/sgml/func/func-tid.sgml | 70 ++++++++++++++++++++++++++++++++
doc/src/sgml/func/func.sgml | 1 +
src/backend/utils/adt/tid.c | 29 +++++++++++++
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 6 +++
src/test/regress/expected/opr_sanity.out | 2 +
src/test/regress/expected/tid.out | 66 ++++++++++++++++++++++++++++++
src/test/regress/sql/tid.sql | 21 ++++++++++
9 files changed, 197 insertions(+), 1 deletion(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Andres Freund 2026-04-05 20:03:33 pgsql: Fixups for a4f774cf1c7
Previous Message Heikki Linnakangas 2026-04-05 18:11:33 pgsql: Check that the tranche name is unique in RequestNamedLWLockTranc