MCPcopy Create free account
hub / github.com/apache/cloudberry / ExecReScanAgg

Function ExecReScanAgg

src/backend/executor/nodeAgg.c:4741–4869  ·  view source on GitHub ↗

* It's quite different from upstream, because Cloudberry share some same works * with ExecEagerFreeAgg() here. */

Source from the content-addressed store, hash-verified

4739 * with ExecEagerFreeAgg() here.
4740 */
4741void
4742ExecReScanAgg(AggState *node)
4743{
4744 ExprContext *econtext = node->ss.ps.ps_ExprContext;
4745 PlanState *outerPlan = outerPlanState(node);
4746 int transno;
4747 int numGroupingSets = Max(node->maxsets, 1);
4748 int setno;
4749
4750 node->agg_done = false;
4751
4752 /*
4753 * Greenplum: on streaming mode, the hash table's status is complex, just
4754 * don't reuse it at all.
4755 */
4756 if (node->aggstrategy == AGG_HASHED && !node->streaming)
4757 {
4758 /*
4759 * In the hashed case, if we haven't yet built the hash table then we
4760 * can just return; nothing done yet, so nothing to undo. If subnode's
4761 * chgParam is not NULL then it will be re-scanned by ExecProcNode,
4762 * else no reason to re-scan it at all.
4763 */
4764 if (!node->table_filled)
4765 return;
4766
4767 /*
4768 * If we do have the hash table, and it never spilled, and the subplan
4769 * does not have any parameter changes, and none of our own parameter
4770 * changes affect input expressions of the aggregated functions, then
4771 * we can just rescan the existing hash table; no need to build it
4772 * again.
4773 */
4774 if (ReuseHashTable(node))
4775 {
4776 ResetTupleHashIterator(node->perhash[0].hashtable,
4777 &node->perhash[0].hashiter);
4778 select_current_set(node, 0, true);
4779 return;
4780 }
4781 }
4782
4783 /* Make sure we have closed any open tuplesorts */
4784 for (transno = 0; transno < node->numtrans; transno++)
4785 {
4786 if (!bms_is_member(transno, node->aggs_used))
4787 continue;
4788 for (setno = 0; setno < numGroupingSets; setno++)
4789 {
4790 AggStatePerTrans pertrans = &node->pertrans[transno];
4791
4792 if (pertrans->sortstates[setno])
4793 {
4794 tuplesort_end(pertrans->sortstates[setno]);
4795 pertrans->sortstates[setno] = NULL;
4796 }
4797 }
4798 }

Callers 1

ExecReScanFunction · 0.85

Calls 12

ReuseHashTableFunction · 0.85
select_current_setFunction · 0.85
bms_is_memberFunction · 0.85
tuplesort_endFunction · 0.85
ReScanExprContextFunction · 0.85
heap_freetupleFunction · 0.85
ExecClearTupleFunction · 0.85
build_hash_tablesFunction · 0.85
initialize_phaseFunction · 0.85
ExecReScanFunction · 0.85

Tested by

no test coverage detected