diff --git a/src/backend/access/common/tupdesc.c b/src/backend/access/common/tupdesc.c index 9fec6e3386..4d22c03cab 100644 --- a/src/backend/access/common/tupdesc.c +++ b/src/backend/access/common/tupdesc.c @@ -56,18 +56,10 @@ ResourceOwnerForgetTupleDesc(ResourceOwner owner, TupleDesc tupdesc) ResourceOwnerForget(owner, PointerGetDatum(tupdesc), &tupdesc_resowner_desc); } -/* - * populate_compact_attribute - * Fill in the corresponding CompactAttribute element from the - * Form_pg_attribute for the given attribute number. This must be called - * whenever a change is made to a Form_pg_attribute in the TupleDesc. - */ void -populate_compact_attribute(TupleDesc tupdesc, int attnum) +populate_compact_attribute_internal(Form_pg_attribute src, + CompactAttribute *dst) { - Form_pg_attribute src = TupleDescAttr(tupdesc, attnum); - CompactAttribute *dst = &tupdesc->compact_attrs[attnum]; - memset(dst, 0, sizeof(CompactAttribute)); dst->attcacheoff = -1; @@ -101,6 +93,22 @@ populate_compact_attribute(TupleDesc tupdesc, int attnum) } } +/* + * populate_compact_attribute + * Fill in the corresponding CompactAttribute element from the + * Form_pg_attribute for the given attribute number. This must be called + * whenever a change is made to a Form_pg_attribute in the TupleDesc. + */ +void +populate_compact_attribute(TupleDesc tupdesc, int attnum) +{ + Form_pg_attribute src = TupleDescAttr(tupdesc, attnum); + CompactAttribute *dst = &tupdesc->compact_attrs[attnum]; + + populate_compact_attribute_internal(src, dst); +} + + /* * CreateTemplateTupleDesc * This function allocates an empty tuple descriptor structure. diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h index e61a4affa4..50b977a135 100644 --- a/src/include/access/tupdesc.h +++ b/src/include/access/tupdesc.h @@ -158,6 +158,9 @@ TupleDescAttr(TupleDesc tupdesc, int i) #undef TupleDescAttrAddress +extern void populate_compact_attribute_internal(Form_pg_attribute src, + CompactAttribute *dst); + /* * Accessor for the i'th CompactAttribute element of tupdesc. */ @@ -166,7 +169,8 @@ TupleDescCompactAttr(TupleDesc tupdesc, int i) { CompactAttribute *cattr = &tupdesc->compact_attrs[i]; #ifdef USE_ASSERT_CHECKING - CompactAttribute snapshot; + CompactAttribute tmp; + Form_pg_attribute attr = TupleDescAttr(tupdesc, i); /* * In Assert enabled builds we verify that the CompactAttribute is @@ -174,21 +178,13 @@ TupleDescCompactAttr(TupleDesc tupdesc, int i) * TABLE where code makes changes to the FormData_pg_attribute but forgets * to call populate_compact_attribute. */ + populate_compact_attribute_internal(attr, &tmp); - /* - * Take a snapshot of how the CompactAttribute is now before calling - * populate_compact_attribute to make it up-to-date with the - * FormData_pg_attribute. - */ - memcpy(&snapshot, cattr, sizeof(CompactAttribute)); - - populate_compact_attribute(tupdesc, i); - - /* reset attcacheoff back to what it was */ - cattr->attcacheoff = snapshot.attcacheoff; + /* make the attcacheoff match since it's been reset to -1 again */ + tmp.attcacheoff = cattr->attcacheoff; - /* Ensure the snapshot matches the freshly populated CompactAttribute */ - Assert(memcmp(&snapshot, cattr, sizeof(CompactAttribute)) == 0); + /* Check the freshly populated CompactAttribute matches the TupleDesc's */ + Assert(memcmp(&tmp, cattr, sizeof(CompactAttribute)) == 0); #endif return cattr;