Cosmetic improvements for faster column addition.

Changed the name of few structure members for the sake of clarity and
removed spurious whitespace.

Reported-by: Amit Kapila
Author: Amit Kapila, based on suggestion by Andrew Dunstan
Reviewed-by: Alvaro Herrera
Discussion: https://postgr.es/m/CAA4eK1K2znsFpC+NQ9A4vxT4uDxADN4RmvHX0L6Y=aHVo9gB4Q@mail.gmail.com
This commit is contained in:
Amit Kapila 2018-06-27 08:16:13 +05:30
parent f49a80c481
commit 8121ab88e7
4 changed files with 26 additions and 28 deletions

View File

@ -100,10 +100,10 @@ getmissingattr(TupleDesc tupleDesc,
attrmiss = tupleDesc->constr->missing + (attnum - 1); attrmiss = tupleDesc->constr->missing + (attnum - 1);
if (attrmiss->ammissingPresent) if (attrmiss->am_present)
{ {
*isnull = false; *isnull = false;
return attrmiss->ammissing; return attrmiss->am_value;
} }
} }
@ -142,9 +142,8 @@ slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
missattnum < lastAttNum; missattnum < lastAttNum;
missattnum++) missattnum++)
{ {
slot->tts_values[missattnum] = attrmiss[missattnum].ammissing; slot->tts_values[missattnum] = attrmiss[missattnum].am_value;
slot->tts_isnull[missattnum] = slot->tts_isnull[missattnum] = !attrmiss[missattnum].am_present;
!attrmiss[missattnum].ammissingPresent;
} }
} }
} }
@ -822,7 +821,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
firstmissingnum < natts; firstmissingnum < natts;
firstmissingnum++) firstmissingnum++)
{ {
if (attrmiss[firstmissingnum].ammissingPresent) if (attrmiss[firstmissingnum].am_present)
break; break;
} }
@ -844,18 +843,18 @@ expand_tuple(HeapTuple *targetHeapTuple,
attnum < natts; attnum < natts;
attnum++) attnum++)
{ {
if (attrmiss[attnum].ammissingPresent) if (attrmiss[attnum].am_present)
{ {
Form_pg_attribute att = TupleDescAttr(tupleDesc, attnum); Form_pg_attribute att = TupleDescAttr(tupleDesc, attnum);
targetDataLen = att_align_datum(targetDataLen, targetDataLen = att_align_datum(targetDataLen,
att->attalign, att->attalign,
att->attlen, att->attlen,
attrmiss[attnum].ammissing); attrmiss[attnum].am_value);
targetDataLen = att_addlength_pointer(targetDataLen, targetDataLen = att_addlength_pointer(targetDataLen,
att->attlen, att->attlen,
attrmiss[attnum].ammissing); attrmiss[attnum].am_value);
} }
else else
{ {
@ -981,14 +980,14 @@ expand_tuple(HeapTuple *targetHeapTuple,
Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum); Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum);
if (attrmiss && attrmiss[attnum].ammissingPresent) if (attrmiss && attrmiss[attnum].am_present)
{ {
fill_val(attr, fill_val(attr,
nullBits ? &nullBits : NULL, nullBits ? &nullBits : NULL,
&bitMask, &bitMask,
&targetData, &targetData,
infoMask, infoMask,
attrmiss[attnum].ammissing, attrmiss[attnum].am_value,
false); false);
} }
else else

View File

@ -185,13 +185,13 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
memcpy(cpy->missing, constr->missing, tupdesc->natts * sizeof(AttrMissing)); memcpy(cpy->missing, constr->missing, tupdesc->natts * sizeof(AttrMissing));
for (i = tupdesc->natts - 1; i >= 0; i--) for (i = tupdesc->natts - 1; i >= 0; i--)
{ {
if (constr->missing[i].ammissingPresent) if (constr->missing[i].am_present)
{ {
Form_pg_attribute attr = TupleDescAttr(tupdesc, i); Form_pg_attribute attr = TupleDescAttr(tupdesc, i);
cpy->missing[i].ammissing = datumCopy(constr->missing[i].ammissing, cpy->missing[i].am_value = datumCopy(constr->missing[i].am_value,
attr->attbyval, attr->attbyval,
attr->attlen); attr->attlen);
} }
} }
} }
@ -337,9 +337,9 @@ FreeTupleDesc(TupleDesc tupdesc)
for (i = tupdesc->natts - 1; i >= 0; i--) for (i = tupdesc->natts - 1; i >= 0; i--)
{ {
if (attrmiss[i].ammissingPresent if (attrmiss[i].am_present
&& !TupleDescAttr(tupdesc, i)->attbyval) && !TupleDescAttr(tupdesc, i)->attbyval)
pfree(DatumGetPointer(attrmiss[i].ammissing)); pfree(DatumGetPointer(attrmiss[i].am_value));
} }
pfree(attrmiss); pfree(attrmiss);
} }
@ -512,13 +512,13 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
AttrMissing *missval1 = constr1->missing + i; AttrMissing *missval1 = constr1->missing + i;
AttrMissing *missval2 = constr2->missing + i; AttrMissing *missval2 = constr2->missing + i;
if (missval1->ammissingPresent != missval2->ammissingPresent) if (missval1->am_present != missval2->am_present)
return false; return false;
if (missval1->ammissingPresent) if (missval1->am_present)
{ {
Form_pg_attribute missatt1 = TupleDescAttr(tupdesc1, i); Form_pg_attribute missatt1 = TupleDescAttr(tupdesc1, i);
if (!datumIsEqual(missval1->ammissing, missval2->ammissing, if (!datumIsEqual(missval1->am_value, missval2->am_value,
missatt1->attbyval, missatt1->attlen)) missatt1->attbyval, missatt1->attlen))
return false; return false;
} }

View File

@ -614,18 +614,18 @@ RelationBuildTupleDesc(Relation relation)
if (attp->attbyval) if (attp->attbyval)
{ {
/* for copy by val just copy the datum direct */ /* for copy by val just copy the datum direct */
attrmiss[attnum - 1].ammissing = missval; attrmiss[attnum - 1].am_value = missval;
} }
else else
{ {
/* otherwise copy in the correct context */ /* otherwise copy in the correct context */
oldcxt = MemoryContextSwitchTo(CacheMemoryContext); oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
attrmiss[attnum - 1].ammissing = datumCopy(missval, attrmiss[attnum - 1].am_value = datumCopy(missval,
attp->attbyval, attp->attbyval,
attp->attlen); attp->attlen);
MemoryContextSwitchTo(oldcxt); MemoryContextSwitchTo(oldcxt);
} }
attrmiss[attnum - 1].ammissingPresent = true; attrmiss[attnum - 1].am_present = true;
} }
} }
need--; need--;

View File

@ -19,11 +19,10 @@
* Structure used to represent value to be used when the attribute is not * Structure used to represent value to be used when the attribute is not
* present at all in a tuple, i.e. when the column was created after the tuple * present at all in a tuple, i.e. when the column was created after the tuple
*/ */
typedef struct attrMissing typedef struct attrMissing
{ {
bool ammissingPresent; /* true if non-NULL missing value exists */ bool am_present; /* true if non-NULL missing value exists */
Datum ammissing; /* value when attribute is missing */ Datum am_value; /* value when attribute is missing */
} AttrMissing; } AttrMissing;
#endif /* TUPDESC_DETAILS_H */ #endif /* TUPDESC_DETAILS_H */