Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/backend/executor/execIndexing.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,13 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS];
ItemPointer tupleid;

Datum rowidDatum = (Datum) 0;

if (table_get_row_ref_type(resultRelInfo->ri_RelationDesc) == ROW_REF_ROWID)
{
bool isnull;
tupleid = DatumGetItemPointer(slot_getsysattr(slot, RowIdAttributeNumber, &isnull));
rowidDatum = slot_getsysattr(slot, RowIdAttributeNumber, &isnull);
tupleid = DatumGetItemPointer(rowidDatum);
Assert(!isnull);
}
else
Expand Down Expand Up @@ -514,6 +515,9 @@ ExecInsertIndexTuples(ResultRelInfo *resultRelInfo,
}
}

if (DatumGetPointer(rowidDatum) != NULL)
pfree(DatumGetPointer(rowidDatum));

return result;
}

Expand All @@ -537,11 +541,13 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS];
ItemPointer tupleid;
Datum rowidDatum = (Datum) 0;

if (table_get_row_ref_type(resultRelInfo->ri_RelationDesc) == ROW_REF_ROWID)
{
bool isnull;
tupleid = DatumGetItemPointer(slot_getsysattr(slot, RowIdAttributeNumber, &isnull));
rowidDatum = slot_getsysattr(slot, RowIdAttributeNumber, &isnull);
tupleid = DatumGetItemPointer(rowidDatum);
Assert(!isnull);
}
else
Expand Down Expand Up @@ -666,12 +672,14 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
Datum valuesOld[INDEX_MAX_KEYS];
bool isnullOld[INDEX_MAX_KEYS];
Datum oldTupleid;
Datum oldRowIdDatum = (Datum) 0;
bool old_valid = true;

if (table_get_row_ref_type(resultRelInfo->ri_RelationDesc) == ROW_REF_ROWID)
{
bool isnull;
oldTupleid = slot_getsysattr(oldSlot, RowIdAttributeNumber, &isnull);
oldRowIdDatum = slot_getsysattr(oldSlot, RowIdAttributeNumber, &isnull);
oldTupleid = oldRowIdDatum;
Assert(!isnull);
}
else
Expand Down Expand Up @@ -724,6 +732,8 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
checkUnique, /* type of uniqueness check to do */
indexInfo); /* index AM may need this */

if (DatumGetPointer(oldRowIdDatum) != NULL)
pfree(DatumGetPointer(oldRowIdDatum));
}
else
{
Expand Down Expand Up @@ -808,6 +818,9 @@ ExecUpdateIndexTuples(ResultRelInfo *resultRelInfo,
}
}

if (DatumGetPointer(rowidDatum) != NULL)
pfree(DatumGetPointer(rowidDatum));

return result;
}

Expand All @@ -824,11 +837,13 @@ ExecDeleteIndexTuples(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
Datum values[INDEX_MAX_KEYS];
bool isnull[INDEX_MAX_KEYS];
Datum tupleid;
Datum rowidDatum = (Datum) 0;

if (table_get_row_ref_type(resultRelInfo->ri_RelationDesc) == ROW_REF_ROWID)
{
bool isnull;
tupleid = slot_getsysattr(slot, RowIdAttributeNumber, &isnull);
rowidDatum = slot_getsysattr(slot, RowIdAttributeNumber, &isnull);
tupleid = rowidDatum;
Assert(!isnull);
}
else
Expand Down Expand Up @@ -915,6 +930,9 @@ ExecDeleteIndexTuples(ResultRelInfo *resultRelInfo, TupleTableSlot *slot,
heapRelation, /* heap relation */
indexInfo); /* index AM may need this */
}

if (DatumGetPointer(rowidDatum) != NULL)
pfree(DatumGetPointer(rowidDatum));
}

/* ----------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/backend/executor/nodeModifyTable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2403,6 +2403,7 @@ ExecOnConflictUpdate(ModifyTableContext *context,
ExprState *onConflictSetWhere = resultRelInfo->ri_onConflict->oc_WhereClause;
TupleTableSlot *existing = resultRelInfo->ri_onConflict->oc_Existing;
Datum tupleid;
Datum rowidDatum = (Datum) 0;

/*
* Parse analysis should have blocked ON CONFLICT for all system
Expand All @@ -2415,7 +2416,8 @@ ExecOnConflictUpdate(ModifyTableContext *context,
if (table_get_row_ref_type(resultRelInfo->ri_RelationDesc) == ROW_REF_ROWID)
{
bool isnull;
tupleid = slot_getsysattr(existing, RowIdAttributeNumber, &isnull);
rowidDatum = slot_getsysattr(existing, RowIdAttributeNumber, &isnull);
tupleid = rowidDatum;
Assert(!isnull);
}
else
Expand All @@ -2438,6 +2440,10 @@ ExecOnConflictUpdate(ModifyTableContext *context,
{
ExecClearTuple(existing); /* see return below */
InstrCountFiltered1(&mtstate->ps, 1);

if (DatumGetPointer(rowidDatum) != NULL)
pfree(DatumGetPointer(rowidDatum));

return true; /* done with the tuple */
}

Expand Down Expand Up @@ -2488,6 +2494,10 @@ ExecOnConflictUpdate(ModifyTableContext *context,
* query.
*/
ExecClearTuple(existing);

if (DatumGetPointer(rowidDatum) != NULL)
pfree(DatumGetPointer(rowidDatum));

return true;
}

Expand Down