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

Put vectorized aggregation results in short-lived memory context #7461

Merged
merged 8 commits into from
Nov 21, 2024
Merged
Changes from 1 commit
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
25 changes: 19 additions & 6 deletions tsl/src/nodes/vector_agg/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,23 +194,30 @@ static TupleTableSlot *
vector_agg_exec(CustomScanState *node)
{
VectorAggState *vector_agg_state = (VectorAggState *) node;
ExprContext *econtext = node->ss.ps.ps_ExprContext;

TupleTableSlot *aggregated_slot = vector_agg_state->custom.ss.ps.ps_ResultTupleSlot;
ExecClearTuple(aggregated_slot);

/*
* If we have more partial aggregation results, continue returning them.
*/
GroupingPolicy *grouping = vector_agg_state->grouping;
if (grouping->gp_do_emit(grouping, aggregated_slot))
MemoryContext old_context = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
bool have_partial = grouping->gp_do_emit(grouping, aggregated_slot);
MemoryContextSwitchTo(old_context);
if (have_partial)
{
/* The grouping policy produced a partial aggregation result. */
return ExecStoreVirtualTuple(aggregated_slot);
}

/*
* If the partial aggregation results have ended, and the input has ended,
* we're done.
*/
if (vector_agg_state->input_ended)
{
/*
* The partial aggregation results have ended, and the input has ended,
* so we're done.
*/
return NULL;
}

Expand Down Expand Up @@ -285,7 +292,13 @@ vector_agg_exec(CustomScanState *node)
grouping->gp_add_batch(grouping, batch_state);
}

if (grouping->gp_do_emit(grouping, aggregated_slot))
/*
* If we have partial aggregation results, start returning them.
*/
old_context = MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
have_partial = grouping->gp_do_emit(grouping, aggregated_slot);
MemoryContextSwitchTo(old_context);
if (have_partial)
{
/* Have partial aggregation results. */
return ExecStoreVirtualTuple(aggregated_slot);
Expand Down
Loading