Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak when executing vectorized quals #242

Merged
merged 2 commits into from
Mar 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion columnar/src/backend/columnar/columnar_customscan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2380,7 +2380,7 @@ CustomExecScan(ColumnarScanState *columnarScanState,
bool *resultQual =
ExecuteVectorizedQual(slot,
columnarScanState->vectorization.constructedVectorizedQualList,
AND_EXPR);
AND_EXPR, econtext);

memcpy(vectorSlot->keep, resultQual, COLUMNAR_VECTOR_COLUMN_SIZE);
}
Expand Down
2 changes: 2 additions & 0 deletions columnar/src/backend/columnar/columnar_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2165,9 +2165,11 @@ ReadStripeNextVector(StripeReadState *stripeReadState, Datum *columnValues,
else
stripeReadState->currentRow += stripeReadState->chunkGroupReadState->rowCount;

pfree(columnValueOffset);
return true;
}

pfree(columnValueOffset);
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,16 +390,21 @@ vectorizedOr(bool *left, bool *right, int dimension)
}

static bool *
executeVectorizedExpr(VectorQual *vectorQual)
executeVectorizedExpr(VectorQual *vectorQual, ExprContext *econtext)
{
MemoryContext oldContext;

oldContext = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
VectorColumn *res =
(VectorColumn *) vectorQual->u.expr.fmgrInfo->fn_addr(vectorQual->u.expr.fcInfo);
MemoryContextSwitchTo(oldContext);

return (bool *) res->value;
}

bool *
ExecuteVectorizedQual(TupleTableSlot *slot, List *vectorizedQualList, BoolExprType boolType)
ExecuteVectorizedQual(TupleTableSlot *slot, List *vectorizedQualList,
BoolExprType boolType, ExprContext *econtext)
{
VectorTupleTableSlot *vectorSlot = (VectorTupleTableSlot *) slot;
ListCell *lc;
Expand All @@ -416,18 +421,22 @@ ExecuteVectorizedQual(TupleTableSlot *slot, List *vectorizedQualList, BoolExprTy
{
case VECTOR_QUAL_EXPR:
{
qualResult = executeVectorizedExpr(vectorQual);
qualResult = executeVectorizedExpr(vectorQual, econtext);
break;
}
case VECTOR_QUAL_BOOL_EXPR:
{
if (vectorQual->u.boolExpr.boolExprType == AND_EXPR)
{
qualResult = ExecuteVectorizedQual(slot, vectorQual->u.boolExpr.vectorQualExprList, AND_EXPR);
qualResult = ExecuteVectorizedQual(slot,
vectorQual->u.boolExpr.vectorQualExprList,
AND_EXPR, econtext);
}
else if (vectorQual->u.boolExpr.boolExprType == OR_EXPR)
{
qualResult = ExecuteVectorizedQual(slot, vectorQual->u.boolExpr.vectorQualExprList, OR_EXPR);
qualResult = ExecuteVectorizedQual(slot,
vectorQual->u.boolExpr.vectorQualExprList,
OR_EXPR, econtext);
}
break;
}
Expand All @@ -448,4 +457,4 @@ ExecuteVectorizedQual(TupleTableSlot *slot, List *vectorizedQualList, BoolExprTy
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern List * CreateVectorizedExprList(List *exprList);
extern List * ConstructVectorizedQualList(TupleTableSlot *slot, List *vectorizedQual);
extern bool * ExecuteVectorizedQual(TupleTableSlot *slot,
List *vectorizedQualList,
BoolExprType boolType);
BoolExprType boolType,
ExprContext *econtext);

#endif
#endif