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

Function agg_retrieve_hash_table

src/backend/executor/nodeAgg.c:2951–3007  ·  view source on GitHub ↗

* ExecAgg for hashed case: retrieving groups from hash table * * After exhausting in-memory tuples, also try refilling the hash table using * previously-spilled tuples. Only returns NULL after all in-memory and * spilled tuples are exhausted. */

Source from the content-addressed store, hash-verified

2949 * spilled tuples are exhausted.
2950 */
2951static TupleTableSlot *
2952agg_retrieve_hash_table(AggState *aggstate)
2953{
2954 TupleTableSlot *result = NULL;
2955
2956 while (result == NULL)
2957 {
2958 result = agg_retrieve_hash_table_in_memory(aggstate);
2959 if (result == NULL)
2960 {
2961 if (aggstate->streaming)
2962 {
2963 /* outer plan is already done, halt the agg */
2964 if (aggstate->input_done)
2965 {
2966 aggstate->agg_done = true;
2967 break;
2968 }
2969
2970 /*
2971 * reset hash tables and related structures, codes are copied
2972 * from agg_refill_hash_table()
2973 */
2974 {
2975 /* there could be residual pergroup pointers; clear them */
2976 for (int setoff = 0;
2977 setoff < aggstate->maxsets + aggstate->num_hashes;
2978 setoff++)
2979 aggstate->all_pergroups[setoff] = NULL;
2980
2981 /* free memory and reset hash tables */
2982 ReScanExprContext(aggstate->hashcontext);
2983 for (int setno = 0; setno < aggstate->num_hashes; setno++)
2984 ResetTupleHashTable(aggstate->perhash[setno].hashtable);
2985
2986 aggstate->hash_ngroups_current = 0;
2987
2988 aggstate->table_filled = false;
2989 }
2990
2991 /* refill the hash table from outer, since streaming doesn't spill */
2992 agg_fill_hash_table(aggstate);
2993
2994 /* halt if outer got nothing but NULL in the above agg_fill_hash_table() */
2995 if (aggstate->agg_done)
2996 break;
2997 }
2998 else if (!agg_refill_hash_table(aggstate))
2999 {
3000 aggstate->agg_done = true;
3001 break;
3002 }
3003 }
3004 }
3005
3006 return result;
3007}
3008

Callers 2

ExecAggFunction · 0.85
agg_retrieve_directFunction · 0.85

Calls 5

ReScanExprContextFunction · 0.85
ResetTupleHashTableFunction · 0.85
agg_fill_hash_tableFunction · 0.85
agg_refill_hash_tableFunction · 0.85

Tested by

no test coverage detected