Commit 8121ab88 authored by Amit Kapila's avatar Amit Kapila

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
parent f49a80c4
...@@ -100,10 +100,10 @@ getmissingattr(TupleDesc tupleDesc, ...@@ -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) ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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
......
...@@ -185,11 +185,11 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc) ...@@ -185,11 +185,11 @@ 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) ...@@ -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) ...@@ -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;
} }
......
...@@ -614,18 +614,18 @@ RelationBuildTupleDesc(Relation relation) ...@@ -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--;
......
...@@ -19,11 +19,10 @@ ...@@ -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 */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment