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,
attrmiss = tupleDesc->constr->missing + (attnum - 1);
if (attrmiss->ammissingPresent)
if (attrmiss->am_present)
{
*isnull = false;
return attrmiss->ammissing;
return attrmiss->am_value;
}
}
......@@ -142,9 +142,8 @@ slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
missattnum < lastAttNum;
missattnum++)
{
slot->tts_values[missattnum] = attrmiss[missattnum].ammissing;
slot->tts_isnull[missattnum] =
!attrmiss[missattnum].ammissingPresent;
slot->tts_values[missattnum] = attrmiss[missattnum].am_value;
slot->tts_isnull[missattnum] = !attrmiss[missattnum].am_present;
}
}
}
......@@ -822,7 +821,7 @@ expand_tuple(HeapTuple *targetHeapTuple,
firstmissingnum < natts;
firstmissingnum++)
{
if (attrmiss[firstmissingnum].ammissingPresent)
if (attrmiss[firstmissingnum].am_present)
break;
}
......@@ -844,18 +843,18 @@ expand_tuple(HeapTuple *targetHeapTuple,
attnum < natts;
attnum++)
{
if (attrmiss[attnum].ammissingPresent)
if (attrmiss[attnum].am_present)
{
Form_pg_attribute att = TupleDescAttr(tupleDesc, attnum);
targetDataLen = att_align_datum(targetDataLen,
att->attalign,
att->attlen,
attrmiss[attnum].ammissing);
attrmiss[attnum].am_value);
targetDataLen = att_addlength_pointer(targetDataLen,
att->attlen,
attrmiss[attnum].ammissing);
attrmiss[attnum].am_value);
}
else
{
......@@ -981,14 +980,14 @@ expand_tuple(HeapTuple *targetHeapTuple,
Form_pg_attribute attr = TupleDescAttr(tupleDesc, attnum);
if (attrmiss && attrmiss[attnum].ammissingPresent)
if (attrmiss && attrmiss[attnum].am_present)
{
fill_val(attr,
nullBits ? &nullBits : NULL,
&bitMask,
&targetData,
infoMask,
attrmiss[attnum].ammissing,
attrmiss[attnum].am_value,
false);
}
else
......
......@@ -185,11 +185,11 @@ CreateTupleDescCopyConstr(TupleDesc tupdesc)
memcpy(cpy->missing, constr->missing, tupdesc->natts * sizeof(AttrMissing));
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);
cpy->missing[i].ammissing = datumCopy(constr->missing[i].ammissing,
cpy->missing[i].am_value = datumCopy(constr->missing[i].am_value,
attr->attbyval,
attr->attlen);
}
......@@ -337,9 +337,9 @@ FreeTupleDesc(TupleDesc tupdesc)
for (i = tupdesc->natts - 1; i >= 0; i--)
{
if (attrmiss[i].ammissingPresent
if (attrmiss[i].am_present
&& !TupleDescAttr(tupdesc, i)->attbyval)
pfree(DatumGetPointer(attrmiss[i].ammissing));
pfree(DatumGetPointer(attrmiss[i].am_value));
}
pfree(attrmiss);
}
......@@ -512,13 +512,13 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
AttrMissing *missval1 = constr1->missing + i;
AttrMissing *missval2 = constr2->missing + i;
if (missval1->ammissingPresent != missval2->ammissingPresent)
if (missval1->am_present != missval2->am_present)
return false;
if (missval1->ammissingPresent)
if (missval1->am_present)
{
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))
return false;
}
......
......@@ -614,18 +614,18 @@ RelationBuildTupleDesc(Relation relation)
if (attp->attbyval)
{
/* for copy by val just copy the datum direct */
attrmiss[attnum - 1].ammissing = missval;
attrmiss[attnum - 1].am_value = missval;
}
else
{
/* otherwise copy in the correct context */
oldcxt = MemoryContextSwitchTo(CacheMemoryContext);
attrmiss[attnum - 1].ammissing = datumCopy(missval,
attrmiss[attnum - 1].am_value = datumCopy(missval,
attp->attbyval,
attp->attlen);
MemoryContextSwitchTo(oldcxt);
}
attrmiss[attnum - 1].ammissingPresent = true;
attrmiss[attnum - 1].am_present = true;
}
}
need--;
......
......@@ -19,11 +19,10 @@
* 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
*/
typedef struct attrMissing
{
bool ammissingPresent; /* true if non-NULL missing value exists */
Datum ammissing; /* value when attribute is missing */
bool am_present; /* true if non-NULL missing value exists */
Datum am_value; /* value when attribute is missing */
} AttrMissing;
#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