pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Reduce size of CompactAttribute struct to 8 bytes
Date: Tue, 17 Mar 2026 02:07:28 +0000
Message-ID: <E1w2JqB-0006BR-2q@gemulon.postgresql.org> (raw)

Reduce size of CompactAttribute struct to 8 bytes

Previously, this was 16 bytes.  With the use of some bitflags and by
reducing the attcacheoff field size to a 16-bit type, we can halve the
size of the struct.

It's unlikely that caching the offsets for offsets larger than what will
fit in a 16-bit int will help much as the tuple is very likely to have
some non-fixed-width types anyway, the offsets of which we cannot cache.

Shrinking this down to 8 bytes helps by accessing fewer cachelines when
performing tuple deformation.  The fields used there are all fully
fledged fields, which don't require any bitmasking to extract the value
of.  It also helps to more efficiently calculate the address of a
compact_attrs[] element in TupleDesc as the x86 LEA instruction can work
with 8 byte offsets, which allows the element address to be calculated
from the TupleDesc's address in a single instruction using LEA's
concurrent shift and add.

Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Andres Freund <andres@anarazel.de>
Reviewed-by: Álvaro Herrera <alvherre@kurilemu.de>
Discussion: https://postgr.es/m/CAApHDvodSVBj3ypOYbYUCJX%2BNWL%3DVZs63RNBQ_FxB_F%2B6QXF-A%40mail.gmail.com

Branch
------
master

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

Modified Files
--------------
src/backend/access/common/tupdesc.c | 12 +++++++++++-
src/backend/executor/execTuples.c   | 17 ++++++++++++-----
src/include/access/tupdesc.h        | 16 ++++++++--------
3 files changed, 31 insertions(+), 14 deletions(-)



Message-ID: <E1w2JqB-0006BR-2q@gemulon.postgresql.org>
Permalink:  ../E1w2JqB-0006BR-2q@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w2JqB-0006BR-2q@gemulon.postgresql.org

 · 

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: pgsql-committers@postgresql.org
  Cc: drowley@postgresql.org, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Reduce size of CompactAttribute struct to 8 bytes
  In-Reply-To: <E1w2JqB-0006BR-2q@gemulon.postgresql.org>

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

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