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 <[email protected]> Reported-by: Peter Geoghegan <[email protected]> Discussion: https://postgr.es/m/cah2-wznho4b+6amaj0gz0jxqdsk69mfhe8faqwuy_01y7cv...@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(-)
