Commit ed698643 authored by Andrew Dunstan's avatar Andrew Dunstan

Small cleanups in fast default code.

Problems identified by Andres Freund and Haribabu Kommi
parent 94173d3e
...@@ -127,7 +127,6 @@ slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum) ...@@ -127,7 +127,6 @@ slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
if (slot->tts_tupleDescriptor->constr) if (slot->tts_tupleDescriptor->constr)
attrmiss = slot->tts_tupleDescriptor->constr->missing; attrmiss = slot->tts_tupleDescriptor->constr->missing;
if (!attrmiss) if (!attrmiss)
{ {
/* no missing values array at all, so just fill everything in as NULL */ /* no missing values array at all, so just fill everything in as NULL */
...@@ -139,9 +138,9 @@ slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum) ...@@ -139,9 +138,9 @@ slot_getmissingattrs(TupleTableSlot *slot, int startAttNum, int lastAttNum)
else else
{ {
/* if there is a missing values array we must process them one by one */ /* if there is a missing values array we must process them one by one */
for (missattnum = lastAttNum - 1; for (missattnum = startAttNum;
missattnum >= startAttNum; missattnum < lastAttNum;
missattnum--) missattnum++)
{ {
slot->tts_values[missattnum] = attrmiss[missattnum].ammissing; slot->tts_values[missattnum] = attrmiss[missattnum].ammissing;
slot->tts_isnull[missattnum] = slot->tts_isnull[missattnum] =
...@@ -1636,6 +1635,8 @@ slot_getallattrs(TupleTableSlot *slot) ...@@ -1636,6 +1635,8 @@ slot_getallattrs(TupleTableSlot *slot)
slot_deform_tuple(slot, attnum); slot_deform_tuple(slot, attnum);
attnum = slot->tts_nvalid;
/* /*
* If tuple doesn't have all the atts indicated by tupleDesc, read the * If tuple doesn't have all the atts indicated by tupleDesc, read the
* rest as NULLS or missing values. * rest as NULLS or missing values.
...@@ -1681,8 +1682,10 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum) ...@@ -1681,8 +1682,10 @@ slot_getsomeattrs(TupleTableSlot *slot, int attnum)
slot_deform_tuple(slot, attno); slot_deform_tuple(slot, attno);
attno = slot->tts_nvalid;
/* /*
* If tuple doesn't have all the atts indicated by tupleDesc, read the * If tuple doesn't have all the atts indicated by attnum, read the
* rest as NULLs or missing values * rest as NULLs or missing values
*/ */
if (attno < attnum) if (attno < attnum)
......
...@@ -626,8 +626,7 @@ ExecCopySlotMinimalTuple(TupleTableSlot *slot) ...@@ -626,8 +626,7 @@ ExecCopySlotMinimalTuple(TupleTableSlot *slot)
return heap_copy_minimal_tuple(slot->tts_mintuple); return heap_copy_minimal_tuple(slot->tts_mintuple);
if (slot->tts_tuple) if (slot->tts_tuple)
{ {
if (TTS_HAS_PHYSICAL_TUPLE(slot) && if (HeapTupleHeaderGetNatts(slot->tts_tuple->t_data)
HeapTupleHeaderGetNatts(slot->tts_tuple->t_data)
< slot->tts_tupleDescriptor->natts) < slot->tts_tupleDescriptor->natts)
return minimal_expand_tuple(slot->tts_tuple, return minimal_expand_tuple(slot->tts_tuple,
slot->tts_tupleDescriptor); slot->tts_tupleDescriptor);
...@@ -675,19 +674,16 @@ ExecFetchSlotTuple(TupleTableSlot *slot) ...@@ -675,19 +674,16 @@ ExecFetchSlotTuple(TupleTableSlot *slot)
if (HeapTupleHeaderGetNatts(slot->tts_tuple->t_data) < if (HeapTupleHeaderGetNatts(slot->tts_tuple->t_data) <
slot->tts_tupleDescriptor->natts) slot->tts_tupleDescriptor->natts)
{ {
HeapTuple tuple;
MemoryContext oldContext = MemoryContextSwitchTo(slot->tts_mcxt); MemoryContext oldContext = MemoryContextSwitchTo(slot->tts_mcxt);
slot->tts_tuple = heap_expand_tuple(slot->tts_tuple, tuple = heap_expand_tuple(slot->tts_tuple,
slot->tts_tupleDescriptor); slot->tts_tupleDescriptor);
slot->tts_shouldFree = true;
MemoryContextSwitchTo(oldContext); MemoryContextSwitchTo(oldContext);
return slot->tts_tuple; slot = ExecStoreTuple(tuple, slot, InvalidBuffer, true);
} }
else
{
return slot->tts_tuple; return slot->tts_tuple;
} }
}
/* /*
* Otherwise materialize the slot... * Otherwise materialize the slot...
......
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