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

Function agg_fill_hash_table

src/backend/executor/nodeAgg.c:2725–2784  ·  view source on GitHub ↗

* ExecAgg for hashed case: read input and build hash table */

Source from the content-addressed store, hash-verified

2723 * ExecAgg for hashed case: read input and build hash table
2724 */
2725static void
2726agg_fill_hash_table(AggState *aggstate)
2727{
2728 TupleTableSlot *outerslot;
2729 ExprContext *tmpcontext = aggstate->tmpcontext;
2730
2731 /*
2732 * Process each outer-plan tuple, and then fetch the next one, until we
2733 * exhaust the outer plan.
2734 */
2735 for (;;)
2736 {
2737 /* hash table in memory is filled, done with this round */
2738 if (aggstate->streaming && aggstate->table_filled)
2739 break;
2740
2741 outerslot = fetch_input_tuple(aggstate);
2742 if (TupIsNull(outerslot))
2743 {
2744 /* outer plan is done */
2745 aggstate->input_done = true;
2746
2747 if (aggstate->hash_ngroups_current == 0)
2748 {
2749 /* this round got nothing but NULL */
2750 aggstate->agg_done = true;
2751 return;
2752 }
2753 else
2754 {
2755 /* this round got things, break to initialize the hash table */
2756 break;
2757 }
2758 }
2759
2760 /* set up for lookup_hash_entries and advance_aggregates */
2761 tmpcontext->ecxt_outertuple = outerslot;
2762
2763 /* Find or build hashtable entries */
2764 lookup_hash_entries(aggstate);
2765
2766 /* Advance the aggregates (or combine functions) */
2767 advance_aggregates(aggstate);
2768
2769 /*
2770 * Reset per-input-tuple context after each tuple, but note that the
2771 * hash lookups do this too
2772 */
2773 ResetExprContext(aggstate->tmpcontext);
2774 }
2775
2776 /* finalize spills, if any */
2777 hashagg_finish_initial_spills(aggstate);
2778
2779 aggstate->table_filled = true;
2780 /* Initialize to walk the first hash table */
2781 select_current_set(aggstate, 0, true);
2782 ResetTupleHashIterator(aggstate->perhash[0].hashtable,

Callers 2

ExecAggFunction · 0.85
agg_retrieve_hash_tableFunction · 0.85

Calls 5

fetch_input_tupleFunction · 0.85
lookup_hash_entriesFunction · 0.85
advance_aggregatesFunction · 0.85
select_current_setFunction · 0.85

Tested by

no test coverage detected