Skip to content

Commit

Permalink
Fix an out-of-memory when inserting large values (#253)
Browse files Browse the repository at this point in the history
The InsertTupleAndEnforceConstraints() constructed tuple on-the-fly, and
on other reference, so we can safely set shouldFree to true for
ExecStoreHeapTuple() to avoid duplicate memory allocation.
  • Loading branch information
japinli authored Oct 7, 2024
1 parent 5a258d2 commit 063eb72
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion columnar/src/backend/columnar/columnar_metadata.c
Original file line number Diff line number Diff line change
Expand Up @@ -2095,7 +2095,16 @@ InsertTupleAndEnforceConstraints(ModifyState *state, Datum *values, bool *nulls)
TupleTableSlot *slot = ExecInitExtraTupleSlot(state->estate, tupleDescriptor,
&TTSOpsHeapTuple);

ExecStoreHeapTuple(tuple, slot, false);
/*
* The tuple has no other reference. Therefore, we can safely set
* shouldFree to true, which can avoid duplicate memory allocation.
*
* When working with low-memory machines, it's important to be mindful
* of duplicate memory allocation for large values. This can lead to
* out-of-memory errors and cause issues with the performance of the
* machine.
*/
ExecStoreHeapTuple(tuple, slot, true);

/* use ExecSimpleRelationInsert to enforce constraints */
ExecSimpleRelationInsert_compat(state->resultRelInfo, state->estate, slot);
Expand Down

0 comments on commit 063eb72

Please sign in to comment.