agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
pgsql: Fix unlikely incremental tuple deform bug with missing attrs
2+ messages / 1 participants
[nested] [flat]

* pgsql: Fix unlikely incremental tuple deform bug with missing attrs
@ 2026-08-06 05:43  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2026-08-06 05:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix unlikely incremental tuple deform bug with missing attrs

The code added in c456e3911 added populate_isnull_array() to bulk
populate the slot's tts_isnull array 8 elements at a time.  When tuples
don't have an exact multiple-of-eight number of attributes, this will
lead to populating the tts_isnull elements for attributes that don't
exist in the tuple.  This is ok as the array is large enough.  However,
if we perform tuple deforming in two passes, and on the first pass
deform *some* of the attributes with slot_getmissingattrs() then later
when we deform the remaining missing attributes, the subsequent call to
populate_isnull_array() would overwrite the tts_isnull values previously
set by slot_getmissingattrs(), and since that function only continues
where it left off, it wouldn't reapply the previously set values and those
would be left as NULLs, as populate_isnull_array() would have set them.

Here, we fix by passing the tuple's natts to slot_getmissingattrs()
rather than the attnum we're deforming from.  This means we apply all
the missing attribute values each deform pass, so slightly more work,
but deforming several missing values in different deform passes is
likely exceedingly rare.  Doing that seems much better than adding
overhead in the happy path to check for this and skip the subsequent call
to populate_isnull_array().

Author: David Rowley <dgrowleyml@gmail.com>
Reported-by: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WznHo4b+6AmAj0GZ0jXqDSK69MfHe8fAQwuY_01y7cVNdw@mail.gmail.com
Backpatch-through: 19

Branch
------
master

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

Modified Files
--------------
src/backend/executor/execTuples.c          | 12 +++++++++++-
src/test/regress/expected/fast_default.out | 15 +++++++++++++++
src/test/regress/sql/fast_default.sql      | 10 ++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* pgsql: Fix unlikely incremental tuple deform bug with missing attrs
@ 2026-08-06 05:43  David Rowley <drowley@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: David Rowley @ 2026-08-06 05:43 UTC (permalink / raw)
  To: pgsql-committers@lists.postgresql.org

Fix unlikely incremental tuple deform bug with missing attrs

The code added in c456e3911 added populate_isnull_array() to bulk
populate the slot's tts_isnull array 8 elements at a time.  When tuples
don't have an exact multiple-of-eight number of attributes, this will
lead to populating the tts_isnull elements for attributes that don't
exist in the tuple.  This is ok as the array is large enough.  However,
if we perform tuple deforming in two passes, and on the first pass
deform *some* of the attributes with slot_getmissingattrs() then later
when we deform the remaining missing attributes, the subsequent call to
populate_isnull_array() would overwrite the tts_isnull values previously
set by slot_getmissingattrs(), and since that function only continues
where it left off, it wouldn't reapply the previously set values and those
would be left as NULLs, as populate_isnull_array() would have set them.

Here, we fix by passing the tuple's natts to slot_getmissingattrs()
rather than the attnum we're deforming from.  This means we apply all
the missing attribute values each deform pass, so slightly more work,
but deforming several missing values in different deform passes is
likely exceedingly rare.  Doing that seems much better than adding
overhead in the happy path to check for this and skip the subsequent call
to populate_isnull_array().

Author: David Rowley <dgrowleyml@gmail.com>
Reported-by: Peter Geoghegan <pg@bowt.ie>
Discussion: https://postgr.es/m/CAH2-WznHo4b+6AmAj0GZ0jXqDSK69MfHe8fAQwuY_01y7cVNdw@mail.gmail.com
Backpatch-through: 19

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/4edd59de527780f536fbbf97d5e117524ded2723

Modified Files
--------------
src/backend/executor/execTuples.c          | 12 +++++++++++-
src/test/regress/expected/fast_default.out | 15 +++++++++++++++
src/test/regress/sql/fast_default.sql      | 10 ++++++++++
3 files changed, 36 insertions(+), 1 deletion(-)



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2026-08-06 05:43 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-08-06 05:43 pgsql: Fix unlikely incremental tuple deform bug with missing attrs David Rowley <drowley@postgresql.org>
2026-08-06 05:43 pgsql: Fix unlikely incremental tuple deform bug with missing attrs David Rowley <drowley@postgresql.org>

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