PostgreSQL Source Code  git master
nodeAgg.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
Include dependency graph for nodeAgg.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  AggStatePerTransData
 
struct  AggStatePerAggData
 
struct  AggStatePerGroupData
 
struct  AggStatePerPhaseData
 
struct  AggStatePerHashData
 

Macros

#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE   0
 
#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL   1
 
#define FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE   2
 

Typedefs

typedef struct AggStatePerTransData AggStatePerTransData
 
typedef struct AggStatePerAggData AggStatePerAggData
 
typedef struct AggStatePerGroupData AggStatePerGroupData
 
typedef struct AggStatePerPhaseData AggStatePerPhaseData
 
typedef struct AggStatePerHashData AggStatePerHashData
 

Functions

AggStateExecInitAgg (Agg *node, EState *estate, int eflags)
 
void ExecEndAgg (AggState *node)
 
void ExecReScanAgg (AggState *node)
 
Size hash_agg_entry_size (int numTrans, Size tupleWidth, Size transitionSpace)
 
void hash_agg_set_limits (double hashentrysize, double input_groups, int used_bits, Size *mem_limit, uint64 *ngroups_limit, int *num_partitions)
 
void ExecAggEstimate (AggState *node, ParallelContext *pcxt)
 
void ExecAggInitializeDSM (AggState *node, ParallelContext *pcxt)
 
void ExecAggInitializeWorker (AggState *node, ParallelWorkerContext *pwcxt)
 
void ExecAggRetrieveInstrumentation (AggState *node)
 

Macro Definition Documentation

◆ FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE

#define FIELDNO_AGGSTATEPERGROUPDATA_NOTRANSVALUE   2

Definition at line 249 of file nodeAgg.h.

Referenced by llvm_compile_expr().

◆ FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE

#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUE   0

Definition at line 244 of file nodeAgg.h.

Referenced by llvm_compile_expr().

◆ FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL

#define FIELDNO_AGGSTATEPERGROUPDATA_TRANSVALUEISNULL   1

Definition at line 246 of file nodeAgg.h.

Referenced by llvm_compile_expr().

Typedef Documentation

◆ AggStatePerAggData

◆ AggStatePerGroupData

◆ AggStatePerHashData

◆ AggStatePerPhaseData

◆ AggStatePerTransData

Function Documentation

◆ ExecAggEstimate()

void ExecAggEstimate ( AggState node,
ParallelContext pcxt 
)

Definition at line 4760 of file nodeAgg.c.

References add_size(), ParallelContext::estimator, PlanState::instrument, mul_size(), ParallelContext::nworkers, offsetof, ScanState::ps, shm_toc_estimate_chunk, shm_toc_estimate_keys, and AggState::ss.

Referenced by ExecParallelEstimate().

4761 {
4762  Size size;
4763 
4764  /* don't need this if not instrumenting or no workers */
4765  if (!node->ss.ps.instrument || pcxt->nworkers == 0)
4766  return;
4767 
4768  size = mul_size(pcxt->nworkers, sizeof(AggregateInstrumentation));
4769  size = add_size(size, offsetof(SharedAggInfo, sinstrument));
4770  shm_toc_estimate_chunk(&pcxt->estimator, size);
4771  shm_toc_estimate_keys(&pcxt->estimator, 1);
4772 }
Instrumentation * instrument
Definition: execnodes.h:975
ScanState ss
Definition: execnodes.h:2274
shm_toc_estimator estimator
Definition: parallel.h:42
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
PlanState ps
Definition: execnodes.h:1376
Size mul_size(Size s1, Size s2)
Definition: shmem.c:519
Size add_size(Size s1, Size s2)
Definition: shmem.c:502
size_t Size
Definition: c.h:540
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
#define offsetof(type, field)
Definition: c.h:727

◆ ExecAggInitializeDSM()

void ExecAggInitializeDSM ( AggState node,
ParallelContext pcxt 
)

Definition at line 4781 of file nodeAgg.c.

References PlanState::instrument, SharedAggInfo::num_workers, ParallelContext::nworkers, offsetof, PlanState::plan, Plan::plan_node_id, ScanState::ps, AggState::shared_info, shm_toc_allocate(), shm_toc_insert(), AggState::ss, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

4782 {
4783  Size size;
4784 
4785  /* don't need this if not instrumenting or no workers */
4786  if (!node->ss.ps.instrument || pcxt->nworkers == 0)
4787  return;
4788 
4789  size = offsetof(SharedAggInfo, sinstrument)
4790  + pcxt->nworkers * sizeof(AggregateInstrumentation);
4791  node->shared_info = shm_toc_allocate(pcxt->toc, size);
4792  /* ensure any unfilled slots will contain zeroes */
4793  memset(node->shared_info, 0, size);
4794  node->shared_info->num_workers = pcxt->nworkers;
4795  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id,
4796  node->shared_info);
4797 }
Instrumentation * instrument
Definition: execnodes.h:975
ScanState ss
Definition: execnodes.h:2274
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1376
struct AggregateInstrumentation AggregateInstrumentation
Plan * plan
Definition: execnodes.h:965
size_t Size
Definition: c.h:540
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
SharedAggInfo * shared_info
Definition: execnodes.h:2346
#define offsetof(type, field)
Definition: c.h:727
shm_toc * toc
Definition: parallel.h:45

◆ ExecAggInitializeWorker()

void ExecAggInitializeWorker ( AggState node,
ParallelWorkerContext pwcxt 
)

Definition at line 4806 of file nodeAgg.c.

References PlanState::plan, Plan::plan_node_id, ScanState::ps, AggState::shared_info, shm_toc_lookup(), AggState::ss, and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

4807 {
4808  node->shared_info =
4809  shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, true);
4810 }
ScanState ss
Definition: execnodes.h:2274
int plan_node_id
Definition: plannodes.h:140
PlanState ps
Definition: execnodes.h:1376
Plan * plan
Definition: execnodes.h:965
SharedAggInfo * shared_info
Definition: execnodes.h:2346
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

◆ ExecAggRetrieveInstrumentation()

void ExecAggRetrieveInstrumentation ( AggState node)

Definition at line 4819 of file nodeAgg.c.

References SharedAggInfo::num_workers, offsetof, palloc(), and AggState::shared_info.

Referenced by ExecParallelRetrieveInstrumentation().

4820 {
4821  Size size;
4822  SharedAggInfo *si;
4823 
4824  if (node->shared_info == NULL)
4825  return;
4826 
4827  size = offsetof(SharedAggInfo, sinstrument)
4829  si = palloc(size);
4830  memcpy(si, node->shared_info, size);
4831  node->shared_info = si;
4832 }
struct AggregateInstrumentation AggregateInstrumentation
size_t Size
Definition: c.h:540
void * palloc(Size size)
Definition: mcxt.c:1062
SharedAggInfo * shared_info
Definition: execnodes.h:2346
#define offsetof(type, field)
Definition: c.h:727

◆ ExecEndAgg()

void ExecEndAgg ( AggState node)

Definition at line 4371 of file nodeAgg.c.

References AggState::aggcontexts, Assert, ExecClearTuple(), ExecEndNode(), ExecFreeExprContext(), AggregateInstrumentation::hash_batches_used, AggState::hash_batches_used, AggregateInstrumentation::hash_disk_used, AggState::hash_disk_used, AggregateInstrumentation::hash_mem_peak, AggState::hash_mem_peak, AggState::hash_metacxt, hashagg_reset_spill_state(), AggState::hashcontext, IsParallelWorker, Max, AggState::maxsets, MemoryContextDelete(), AggState::numtrans, outerPlan, outerPlanState, ParallelWorkerNumber, AggState::pertrans, ScanState::ps, ReScanExprContext(), AggState::shared_info, SharedAggInfo::sinstrument, AggState::sort_in, AggState::sort_out, AggStatePerTransData::sortstates, AggState::ss, ScanState::ss_ScanTupleSlot, and tuplesort_end().

Referenced by ExecEndNode().

4372 {
4374  int transno;
4375  int numGroupingSets = Max(node->maxsets, 1);
4376  int setno;
4377 
4378  /*
4379  * When ending a parallel worker, copy the statistics gathered by the
4380  * worker back into shared memory so that it can be picked up by the main
4381  * process to report in EXPLAIN ANALYZE.
4382  */
4383  if (node->shared_info && IsParallelWorker())
4384  {
4386 
4387  Assert(ParallelWorkerNumber <= node->shared_info->num_workers);
4390  si->hash_disk_used = node->hash_disk_used;
4391  si->hash_mem_peak = node->hash_mem_peak;
4392  }
4393 
4394  /* Make sure we have closed any open tuplesorts */
4395 
4396  if (node->sort_in)
4397  tuplesort_end(node->sort_in);
4398  if (node->sort_out)
4399  tuplesort_end(node->sort_out);
4400 
4402 
4403  if (node->hash_metacxt != NULL)
4404  {
4406  node->hash_metacxt = NULL;
4407  }
4408 
4409  for (transno = 0; transno < node->numtrans; transno++)
4410  {
4411  AggStatePerTrans pertrans = &node->pertrans[transno];
4412 
4413  for (setno = 0; setno < numGroupingSets; setno++)
4414  {
4415  if (pertrans->sortstates[setno])
4416  tuplesort_end(pertrans->sortstates[setno]);
4417  }
4418  }
4419 
4420  /* And ensure any agg shutdown callbacks have been called */
4421  for (setno = 0; setno < numGroupingSets; setno++)
4422  ReScanExprContext(node->aggcontexts[setno]);
4423  if (node->hashcontext)
4425 
4426  /*
4427  * We don't actually free any ExprContexts here (see comment in
4428  * ExecFreeExprContext), just unlinking the output one from the plan node
4429  * suffices.
4430  */
4431  ExecFreeExprContext(&node->ss.ps);
4432 
4433  /* clean up tuple table */
4435 
4436  outerPlan = outerPlanState(node);
4437  ExecEndNode(outerPlan);
4438 }
static void hashagg_reset_spill_state(AggState *aggstate)
Definition: nodeAgg.c:3194
void MemoryContextDelete(MemoryContext context)
Definition: mcxt.c:218
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:556
Tuplesortstate * sort_out
Definition: execnodes.h:2307
ScanState ss
Definition: execnodes.h:2274
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1379
AggregateInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:2250
AggStatePerTrans pertrans
Definition: execnodes.h:2284
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:650
int numtrans
Definition: execnodes.h:2277
PlanState ps
Definition: execnodes.h:1376
int maxsets
Definition: execnodes.h:2304
MemoryContext hash_metacxt
Definition: execnodes.h:2316
Tuplesortstate * sort_in
Definition: execnodes.h:2306
#define outerPlanState(node)
Definition: execnodes.h:1061
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
int ParallelWorkerNumber
Definition: parallel.c:112
#define IsParallelWorker()
Definition: parallel.h:61
int hash_batches_used
Definition: execnodes.h:2335
#define outerPlan(node)
Definition: plannodes.h:171
ExprContext * hashcontext
Definition: execnodes.h:2285
uint64 hash_disk_used
Definition: execnodes.h:2334
#define Max(x, y)
Definition: c.h:980
ExprContext ** aggcontexts
Definition: execnodes.h:2286
#define Assert(condition)
Definition: c.h:804
void ReScanExprContext(ExprContext *econtext)
Definition: execUtils.c:438
Size hash_mem_peak
Definition: execnodes.h:2331
SharedAggInfo * shared_info
Definition: execnodes.h:2346
void tuplesort_end(Tuplesortstate *state)
Definition: tuplesort.c:1464

◆ ExecInitAgg()

AggState* ExecInitAgg ( Agg node,
EState estate,
int  eflags 
)

Definition at line 3246 of file nodeAgg.c.

References ACL_EXECUTE, aclcheck_error(), ACLCHECK_OK, AggState::agg_done, AGG_HASHED, AGG_MIXED, AGG_PLAIN, AGG_SORTED, AggState::aggcontexts, AggStatePerAggData::aggdirectargs, Aggref::aggdirectargs, AGGFNOID, Aggref::aggfnoid, Aggref::agglevelsup, Aggref::aggno, AggStatePerPhaseData::aggnode, AggStatePerHashData::aggnode, AggStatePerTransData::aggref, AggStatePerAggData::aggref, AggState::aggs, AggStatePerTransData::aggshared, Aggref::aggsplit, Agg::aggsplit, AggState::aggsplit, AggStatePerPhaseData::aggstrategy, Agg::aggstrategy, AggState::aggstrategy, Aggref::aggtransno, Aggref::aggtranstype, Aggref::aggtype, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, bms_add_member(), bms_add_members(), bms_next_member(), build_aggregate_finalfn_expr(), build_hash_tables(), build_pertrans_for_aggref(), castNode, Agg::chain, CreateWorkExprContext(), AggState::curperagg, AggState::curpertrans, AggState::current_set, DO_AGGSPLIT_COMBINE, DO_AGGSPLIT_DESERIALIZE, DO_AGGSPLIT_SERIALIZE, DO_AGGSPLIT_SKIPFINAL, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, elog, AggStatePerPhaseData::eqfunctions, ereport, errcode(), errmsg(), ERROR, EState::es_query_cxt, AggStatePerPhaseData::evaltrans, AggStatePerPhaseData::evaltrans_cache, EXEC_FLAG_BACKWARD, EXEC_FLAG_EXPLAIN_ONLY, EXEC_FLAG_MARK, EXEC_FLAG_REWIND, ExecAgg(), ExecAssignExprContext(), ExecAssignProjectionInfo(), ExecBuildAggTrans(), ExecCreateScanSlotFromOuterPlan(), ExecGetResultSlotOps(), ExecInitExprList(), ExecInitExtraTupleSlot(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlotTL(), PlanState::ExecProcNode, execTuplesMatchPrepare(), AggStatePerAggData::finalfn, AggStatePerAggData::finalfn_oid, find_hash_columns(), fmgr_info(), fmgr_info_set_expr, FUNC_MAX_ARGS, get_aggregate_argtypes(), get_func_name(), get_typlenbyval(), GetAggInitVal(), GETSTRUCT, GetUserId(), AggStatePerPhaseData::grouped_cols, Agg::groupingSets, AggState::grp_firstTuple, Agg::grpColIdx, Agg::grpCollations, Agg::grpOperators, AggStatePerPhaseData::gset_lengths, hash_agg_entry_size(), hash_agg_set_limits(), AggState::hashcontext, HeapTupleIsValid, i, initialize_phase(), initValue(), AggState::input_done, Aggref::inputcollid, InvalidOid, InvokeFunctionExecuteHook, lcons_int(), Plan::lefttree, lfirst, list_length(), list_nth_node, makeNode, Max, AggState::maxsets, NIL, AggState::numaggs, AggStatePerHashData::numCols, Agg::numCols, AggStatePerAggData::numFinalArgs, AggState::numphases, AggStatePerPhaseData::numsets, AggState::numtrans, OBJECT_AGGREGATE, OBJECT_FUNCTION, ObjectIdGetDatum, OidIsValid, PlanState::outerops, PlanState::outeropsfixed, PlanState::outeropsset, outerPlan, outerPlanState, palloc(), palloc0(), AggState::peragg, AggState::pergroups, AggState::pertrans, pg_proc_aclcheck(), Agg::plan, PlanState::plan, Plan::plan_width, PROCOID, AggState::projected_set, ScanState::ps, PlanState::ps_ExprContext, Plan::qual, PlanState::qual, ReleaseSysCache(), AggStatePerAggData::resulttypeByVal, AggStatePerAggData::resulttypeLen, SearchSysCache1(), select_current_set(), AggState::sort_in, AggState::sort_out, AggState::sort_slot, AggStatePerPhaseData::sortnode, AggState::ss, ScanState::ss_ScanTupleSlot, PlanState::state, SysCacheGetAttr(), AggState::tmpcontext, Agg::transitionSpace, AggStatePerAggData::transno, TupleTableSlot::tts_tupleDescriptor, TTSOpsMinimalTuple, and TTSOpsVirtual.

Referenced by ExecInitNode().

3247 {
3248  AggState *aggstate;
3249  AggStatePerAgg peraggs;
3250  AggStatePerTrans pertransstates;
3251  AggStatePerGroup *pergroups;
3252  Plan *outerPlan;
3253  ExprContext *econtext;
3254  TupleDesc scanDesc;
3255  int max_aggno;
3256  int max_transno;
3257  int numaggrefs;
3258  int numaggs;
3259  int numtrans;
3260  int phase;
3261  int phaseidx;
3262  ListCell *l;
3263  Bitmapset *all_grouped_cols = NULL;
3264  int numGroupingSets = 1;
3265  int numPhases;
3266  int numHashes;
3267  int i = 0;
3268  int j = 0;
3269  bool use_hashing = (node->aggstrategy == AGG_HASHED ||
3270  node->aggstrategy == AGG_MIXED);
3271 
3272  /* check for unsupported flags */
3273  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
3274 
3275  /*
3276  * create state structure
3277  */
3278  aggstate = makeNode(AggState);
3279  aggstate->ss.ps.plan = (Plan *) node;
3280  aggstate->ss.ps.state = estate;
3281  aggstate->ss.ps.ExecProcNode = ExecAgg;
3282 
3283  aggstate->aggs = NIL;
3284  aggstate->numaggs = 0;
3285  aggstate->numtrans = 0;
3286  aggstate->aggstrategy = node->aggstrategy;
3287  aggstate->aggsplit = node->aggsplit;
3288  aggstate->maxsets = 0;
3289  aggstate->projected_set = -1;
3290  aggstate->current_set = 0;
3291  aggstate->peragg = NULL;
3292  aggstate->pertrans = NULL;
3293  aggstate->curperagg = NULL;
3294  aggstate->curpertrans = NULL;
3295  aggstate->input_done = false;
3296  aggstate->agg_done = false;
3297  aggstate->pergroups = NULL;
3298  aggstate->grp_firstTuple = NULL;
3299  aggstate->sort_in = NULL;
3300  aggstate->sort_out = NULL;
3301 
3302  /*
3303  * phases[0] always exists, but is dummy in sorted/plain mode
3304  */
3305  numPhases = (use_hashing ? 1 : 2);
3306  numHashes = (use_hashing ? 1 : 0);
3307 
3308  /*
3309  * Calculate the maximum number of grouping sets in any phase; this
3310  * determines the size of some allocations. Also calculate the number of
3311  * phases, since all hashed/mixed nodes contribute to only a single phase.
3312  */
3313  if (node->groupingSets)
3314  {
3315  numGroupingSets = list_length(node->groupingSets);
3316 
3317  foreach(l, node->chain)
3318  {
3319  Agg *agg = lfirst(l);
3320 
3321  numGroupingSets = Max(numGroupingSets,
3322  list_length(agg->groupingSets));
3323 
3324  /*
3325  * additional AGG_HASHED aggs become part of phase 0, but all
3326  * others add an extra phase.
3327  */
3328  if (agg->aggstrategy != AGG_HASHED)
3329  ++numPhases;
3330  else
3331  ++numHashes;
3332  }
3333  }
3334 
3335  aggstate->maxsets = numGroupingSets;
3336  aggstate->numphases = numPhases;
3337 
3338  aggstate->aggcontexts = (ExprContext **)
3339  palloc0(sizeof(ExprContext *) * numGroupingSets);
3340 
3341  /*
3342  * Create expression contexts. We need three or more, one for
3343  * per-input-tuple processing, one for per-output-tuple processing, one
3344  * for all the hashtables, and one for each grouping set. The per-tuple
3345  * memory context of the per-grouping-set ExprContexts (aggcontexts)
3346  * replaces the standalone memory context formerly used to hold transition
3347  * values. We cheat a little by using ExecAssignExprContext() to build
3348  * all of them.
3349  *
3350  * NOTE: the details of what is stored in aggcontexts and what is stored
3351  * in the regular per-query memory context are driven by a simple
3352  * decision: we want to reset the aggcontext at group boundaries (if not
3353  * hashing) and in ExecReScanAgg to recover no-longer-wanted space.
3354  */
3355  ExecAssignExprContext(estate, &aggstate->ss.ps);
3356  aggstate->tmpcontext = aggstate->ss.ps.ps_ExprContext;
3357 
3358  for (i = 0; i < numGroupingSets; ++i)
3359  {
3360  ExecAssignExprContext(estate, &aggstate->ss.ps);
3361  aggstate->aggcontexts[i] = aggstate->ss.ps.ps_ExprContext;
3362  }
3363 
3364  if (use_hashing)
3365  aggstate->hashcontext = CreateWorkExprContext(estate);
3366 
3367  ExecAssignExprContext(estate, &aggstate->ss.ps);
3368 
3369  /*
3370  * Initialize child nodes.
3371  *
3372  * If we are doing a hashed aggregation then the child plan does not need
3373  * to handle REWIND efficiently; see ExecReScanAgg.
3374  */
3375  if (node->aggstrategy == AGG_HASHED)
3376  eflags &= ~EXEC_FLAG_REWIND;
3377  outerPlan = outerPlan(node);
3378  outerPlanState(aggstate) = ExecInitNode(outerPlan, estate, eflags);
3379 
3380  /*
3381  * initialize source tuple type.
3382  */
3383  aggstate->ss.ps.outerops =
3385  &aggstate->ss.ps.outeropsfixed);
3386  aggstate->ss.ps.outeropsset = true;
3387 
3388  ExecCreateScanSlotFromOuterPlan(estate, &aggstate->ss,
3389  aggstate->ss.ps.outerops);
3390  scanDesc = aggstate->ss.ss_ScanTupleSlot->tts_tupleDescriptor;
3391 
3392  /*
3393  * If there are more than two phases (including a potential dummy phase
3394  * 0), input will be resorted using tuplesort. Need a slot for that.
3395  */
3396  if (numPhases > 2)
3397  {
3398  aggstate->sort_slot = ExecInitExtraTupleSlot(estate, scanDesc,
3400 
3401  /*
3402  * The output of the tuplesort, and the output from the outer child
3403  * might not use the same type of slot. In most cases the child will
3404  * be a Sort, and thus return a TTSOpsMinimalTuple type slot - but the
3405  * input can also be presorted due an index, in which case it could be
3406  * a different type of slot.
3407  *
3408  * XXX: For efficiency it would be good to instead/additionally
3409  * generate expressions with corresponding settings of outerops* for
3410  * the individual phases - deforming is often a bottleneck for
3411  * aggregations with lots of rows per group. If there's multiple
3412  * sorts, we know that all but the first use TTSOpsMinimalTuple (via
3413  * the nodeAgg.c internal tuplesort).
3414  */
3415  if (aggstate->ss.ps.outeropsfixed &&
3416  aggstate->ss.ps.outerops != &TTSOpsMinimalTuple)
3417  aggstate->ss.ps.outeropsfixed = false;
3418  }
3419 
3420  /*
3421  * Initialize result type, slot and projection.
3422  */
3424  ExecAssignProjectionInfo(&aggstate->ss.ps, NULL);
3425 
3426  /*
3427  * initialize child expressions
3428  *
3429  * We expect the parser to have checked that no aggs contain other agg
3430  * calls in their arguments (and just to be sure, we verify it again while
3431  * initializing the plan node). This would make no sense under SQL
3432  * semantics, and it's forbidden by the spec. Because it is true, we
3433  * don't need to worry about evaluating the aggs in any particular order.
3434  *
3435  * Note: execExpr.c finds Aggrefs for us, and adds them to aggstate->aggs.
3436  * Aggrefs in the qual are found here; Aggrefs in the targetlist are found
3437  * during ExecAssignProjectionInfo, above.
3438  */
3439  aggstate->ss.ps.qual =
3440  ExecInitQual(node->plan.qual, (PlanState *) aggstate);
3441 
3442  /*
3443  * We should now have found all Aggrefs in the targetlist and quals.
3444  */
3445  numaggrefs = list_length(aggstate->aggs);
3446  max_aggno = -1;
3447  max_transno = -1;
3448  foreach(l, aggstate->aggs)
3449  {
3450  Aggref *aggref = (Aggref *) lfirst(l);
3451 
3452  max_aggno = Max(max_aggno, aggref->aggno);
3453  max_transno = Max(max_transno, aggref->aggtransno);
3454  }
3455  numaggs = max_aggno + 1;
3456  numtrans = max_transno + 1;
3457 
3458  /*
3459  * For each phase, prepare grouping set data and fmgr lookup data for
3460  * compare functions. Accumulate all_grouped_cols in passing.
3461  */
3462  aggstate->phases = palloc0(numPhases * sizeof(AggStatePerPhaseData));
3463 
3464  aggstate->num_hashes = numHashes;
3465  if (numHashes)
3466  {
3467  aggstate->perhash = palloc0(sizeof(AggStatePerHashData) * numHashes);
3468  aggstate->phases[0].numsets = 0;
3469  aggstate->phases[0].gset_lengths = palloc(numHashes * sizeof(int));
3470  aggstate->phases[0].grouped_cols = palloc(numHashes * sizeof(Bitmapset *));
3471  }
3472 
3473  phase = 0;
3474  for (phaseidx = 0; phaseidx <= list_length(node->chain); ++phaseidx)
3475  {
3476  Agg *aggnode;
3477  Sort *sortnode;
3478 
3479  if (phaseidx > 0)
3480  {
3481  aggnode = list_nth_node(Agg, node->chain, phaseidx - 1);
3482  sortnode = castNode(Sort, aggnode->plan.lefttree);
3483  }
3484  else
3485  {
3486  aggnode = node;
3487  sortnode = NULL;
3488  }
3489 
3490  Assert(phase <= 1 || sortnode);
3491 
3492  if (aggnode->aggstrategy == AGG_HASHED
3493  || aggnode->aggstrategy == AGG_MIXED)
3494  {
3495  AggStatePerPhase phasedata = &aggstate->phases[0];
3496  AggStatePerHash perhash;
3497  Bitmapset *cols = NULL;
3498 
3499  Assert(phase == 0);
3500  i = phasedata->numsets++;
3501  perhash = &aggstate->perhash[i];
3502 
3503  /* phase 0 always points to the "real" Agg in the hash case */
3504  phasedata->aggnode = node;
3505  phasedata->aggstrategy = node->aggstrategy;
3506 
3507  /* but the actual Agg node representing this hash is saved here */
3508  perhash->aggnode = aggnode;
3509 
3510  phasedata->gset_lengths[i] = perhash->numCols = aggnode->numCols;
3511 
3512  for (j = 0; j < aggnode->numCols; ++j)
3513  cols = bms_add_member(cols, aggnode->grpColIdx[j]);
3514 
3515  phasedata->grouped_cols[i] = cols;
3516 
3517  all_grouped_cols = bms_add_members(all_grouped_cols, cols);
3518  continue;
3519  }
3520  else
3521  {
3522  AggStatePerPhase phasedata = &aggstate->phases[++phase];
3523  int num_sets;
3524 
3525  phasedata->numsets = num_sets = list_length(aggnode->groupingSets);
3526 
3527  if (num_sets)
3528  {
3529  phasedata->gset_lengths = palloc(num_sets * sizeof(int));
3530  phasedata->grouped_cols = palloc(num_sets * sizeof(Bitmapset *));
3531 
3532  i = 0;
3533  foreach(l, aggnode->groupingSets)
3534  {
3535  int current_length = list_length(lfirst(l));
3536  Bitmapset *cols = NULL;
3537 
3538  /* planner forces this to be correct */
3539  for (j = 0; j < current_length; ++j)
3540  cols = bms_add_member(cols, aggnode->grpColIdx[j]);
3541 
3542  phasedata->grouped_cols[i] = cols;
3543  phasedata->gset_lengths[i] = current_length;
3544 
3545  ++i;
3546  }
3547 
3548  all_grouped_cols = bms_add_members(all_grouped_cols,
3549  phasedata->grouped_cols[0]);
3550  }
3551  else
3552  {
3553  Assert(phaseidx == 0);
3554 
3555  phasedata->gset_lengths = NULL;
3556  phasedata->grouped_cols = NULL;
3557  }
3558 
3559  /*
3560  * If we are grouping, precompute fmgr lookup data for inner loop.
3561  */
3562  if (aggnode->aggstrategy == AGG_SORTED)
3563  {
3564  int i = 0;
3565 
3566  Assert(aggnode->numCols > 0);
3567 
3568  /*
3569  * Build a separate function for each subset of columns that
3570  * need to be compared.
3571  */
3572  phasedata->eqfunctions =
3573  (ExprState **) palloc0(aggnode->numCols * sizeof(ExprState *));
3574 
3575  /* for each grouping set */
3576  for (i = 0; i < phasedata->numsets; i++)
3577  {
3578  int length = phasedata->gset_lengths[i];
3579 
3580  if (phasedata->eqfunctions[length - 1] != NULL)
3581  continue;
3582 
3583  phasedata->eqfunctions[length - 1] =
3584  execTuplesMatchPrepare(scanDesc,
3585  length,
3586  aggnode->grpColIdx,
3587  aggnode->grpOperators,
3588  aggnode->grpCollations,
3589  (PlanState *) aggstate);
3590  }
3591 
3592  /* and for all grouped columns, unless already computed */
3593  if (phasedata->eqfunctions[aggnode->numCols - 1] == NULL)
3594  {
3595  phasedata->eqfunctions[aggnode->numCols - 1] =
3596  execTuplesMatchPrepare(scanDesc,
3597  aggnode->numCols,
3598  aggnode->grpColIdx,
3599  aggnode->grpOperators,
3600  aggnode->grpCollations,
3601  (PlanState *) aggstate);
3602  }
3603  }
3604 
3605  phasedata->aggnode = aggnode;
3606  phasedata->aggstrategy = aggnode->aggstrategy;
3607  phasedata->sortnode = sortnode;
3608  }
3609  }
3610 
3611  /*
3612  * Convert all_grouped_cols to a descending-order list.
3613  */
3614  i = -1;
3615  while ((i = bms_next_member(all_grouped_cols, i)) >= 0)
3616  aggstate->all_grouped_cols = lcons_int(i, aggstate->all_grouped_cols);
3617 
3618  /*
3619  * Set up aggregate-result storage in the output expr context, and also
3620  * allocate my private per-agg working storage
3621  */
3622  econtext = aggstate->ss.ps.ps_ExprContext;
3623  econtext->ecxt_aggvalues = (Datum *) palloc0(sizeof(Datum) * numaggs);
3624  econtext->ecxt_aggnulls = (bool *) palloc0(sizeof(bool) * numaggs);
3625 
3626  peraggs = (AggStatePerAgg) palloc0(sizeof(AggStatePerAggData) * numaggs);
3627  pertransstates = (AggStatePerTrans) palloc0(sizeof(AggStatePerTransData) * numtrans);
3628 
3629  aggstate->peragg = peraggs;
3630  aggstate->pertrans = pertransstates;
3631 
3632 
3633  aggstate->all_pergroups =
3635  * (numGroupingSets + numHashes));
3636  pergroups = aggstate->all_pergroups;
3637 
3638  if (node->aggstrategy != AGG_HASHED)
3639  {
3640  for (i = 0; i < numGroupingSets; i++)
3641  {
3642  pergroups[i] = (AggStatePerGroup) palloc0(sizeof(AggStatePerGroupData)
3643  * numaggs);
3644  }
3645 
3646  aggstate->pergroups = pergroups;
3647  pergroups += numGroupingSets;
3648  }
3649 
3650  /*
3651  * Hashing can only appear in the initial phase.
3652  */
3653  if (use_hashing)
3654  {
3655  Plan *outerplan = outerPlan(node);
3656  uint64 totalGroups = 0;
3657  int i;
3658 
3659  aggstate->hash_metacxt = AllocSetContextCreate(aggstate->ss.ps.state->es_query_cxt,
3660  "HashAgg meta context",
3662  aggstate->hash_spill_rslot = ExecInitExtraTupleSlot(estate, scanDesc,
3664  aggstate->hash_spill_wslot = ExecInitExtraTupleSlot(estate, scanDesc,
3665  &TTSOpsVirtual);
3666 
3667  /* this is an array of pointers, not structures */
3668  aggstate->hash_pergroup = pergroups;
3669 
3670  aggstate->hashentrysize = hash_agg_entry_size(aggstate->numtrans,
3671  outerplan->plan_width,
3672  node->transitionSpace);
3673 
3674  /*
3675  * Consider all of the grouping sets together when setting the limits
3676  * and estimating the number of partitions. This can be inaccurate
3677  * when there is more than one grouping set, but should still be
3678  * reasonable.
3679  */
3680  for (i = 0; i < aggstate->num_hashes; i++)
3681  totalGroups += aggstate->perhash[i].aggnode->numGroups;
3682 
3683  hash_agg_set_limits(aggstate->hashentrysize, totalGroups, 0,
3684  &aggstate->hash_mem_limit,
3685  &aggstate->hash_ngroups_limit,
3686  &aggstate->hash_planned_partitions);
3687  find_hash_columns(aggstate);
3688 
3689  /* Skip massive memory allocation if we are just doing EXPLAIN */
3690  if (!(eflags & EXEC_FLAG_EXPLAIN_ONLY))
3691  build_hash_tables(aggstate);
3692 
3693  aggstate->table_filled = false;
3694 
3695  /* Initialize this to 1, meaning nothing spilled, yet */
3696  aggstate->hash_batches_used = 1;
3697  }
3698 
3699  /*
3700  * Initialize current phase-dependent values to initial phase. The initial
3701  * phase is 1 (first sort pass) for all strategies that use sorting (if
3702  * hashing is being done too, then phase 0 is processed last); but if only
3703  * hashing is being done, then phase 0 is all there is.
3704  */
3705  if (node->aggstrategy == AGG_HASHED)
3706  {
3707  aggstate->current_phase = 0;
3708  initialize_phase(aggstate, 0);
3709  select_current_set(aggstate, 0, true);
3710  }
3711  else
3712  {
3713  aggstate->current_phase = 1;
3714  initialize_phase(aggstate, 1);
3715  select_current_set(aggstate, 0, false);
3716  }
3717 
3718  /*
3719  * Perform lookups of aggregate function info, and initialize the
3720  * unchanging fields of the per-agg and per-trans data.
3721  */
3722  foreach(l, aggstate->aggs)
3723  {
3724  Aggref *aggref = lfirst(l);
3725  AggStatePerAgg peragg;
3726  AggStatePerTrans pertrans;
3727  Oid inputTypes[FUNC_MAX_ARGS];
3728  int numArguments;
3729  int numDirectArgs;
3730  HeapTuple aggTuple;
3731  Form_pg_aggregate aggform;
3732  AclResult aclresult;
3733  Oid finalfn_oid;
3734  Oid serialfn_oid,
3735  deserialfn_oid;
3736  Oid aggOwner;
3737  Expr *finalfnexpr;
3738  Oid aggtranstype;
3739 
3740  /* Planner should have assigned aggregate to correct level */
3741  Assert(aggref->agglevelsup == 0);
3742  /* ... and the split mode should match */
3743  Assert(aggref->aggsplit == aggstate->aggsplit);
3744 
3745  peragg = &peraggs[aggref->aggno];
3746 
3747  /* Check if we initialized the state for this aggregate already. */
3748  if (peragg->aggref != NULL)
3749  continue;
3750 
3751  peragg->aggref = aggref;
3752  peragg->transno = aggref->aggtransno;
3753 
3754  /* Fetch the pg_aggregate row */
3755  aggTuple = SearchSysCache1(AGGFNOID,
3756  ObjectIdGetDatum(aggref->aggfnoid));
3757  if (!HeapTupleIsValid(aggTuple))
3758  elog(ERROR, "cache lookup failed for aggregate %u",
3759  aggref->aggfnoid);
3760  aggform = (Form_pg_aggregate) GETSTRUCT(aggTuple);
3761 
3762  /* Check permission to call aggregate function */
3763  aclresult = pg_proc_aclcheck(aggref->aggfnoid, GetUserId(),
3764  ACL_EXECUTE);
3765  if (aclresult != ACLCHECK_OK)
3766  aclcheck_error(aclresult, OBJECT_AGGREGATE,
3767  get_func_name(aggref->aggfnoid));
3769 
3770  /* planner recorded transition state type in the Aggref itself */
3771  aggtranstype = aggref->aggtranstype;
3772  Assert(OidIsValid(aggtranstype));
3773 
3774  /* Final function only required if we're finalizing the aggregates */
3775  if (DO_AGGSPLIT_SKIPFINAL(aggstate->aggsplit))
3776  peragg->finalfn_oid = finalfn_oid = InvalidOid;
3777  else
3778  peragg->finalfn_oid = finalfn_oid = aggform->aggfinalfn;
3779 
3780  serialfn_oid = InvalidOid;
3781  deserialfn_oid = InvalidOid;
3782 
3783  /*
3784  * Check if serialization/deserialization is required. We only do it
3785  * for aggregates that have transtype INTERNAL.
3786  */
3787  if (aggtranstype == INTERNALOID)
3788  {
3789  /*
3790  * The planner should only have generated a serialize agg node if
3791  * every aggregate with an INTERNAL state has a serialization
3792  * function. Verify that.
3793  */
3794  if (DO_AGGSPLIT_SERIALIZE(aggstate->aggsplit))
3795  {
3796  /* serialization only valid when not running finalfn */
3798 
3799  if (!OidIsValid(aggform->aggserialfn))
3800  elog(ERROR, "serialfunc not provided for serialization aggregation");
3801  serialfn_oid = aggform->aggserialfn;
3802  }
3803 
3804  /* Likewise for deserialization functions */
3805  if (DO_AGGSPLIT_DESERIALIZE(aggstate->aggsplit))
3806  {
3807  /* deserialization only valid when combining states */
3808  Assert(DO_AGGSPLIT_COMBINE(aggstate->aggsplit));
3809 
3810  if (!OidIsValid(aggform->aggdeserialfn))
3811  elog(ERROR, "deserialfunc not provided for deserialization aggregation");
3812  deserialfn_oid = aggform->aggdeserialfn;
3813  }
3814  }
3815 
3816  /* Check that aggregate owner has permission to call component fns */
3817  {
3818  HeapTuple procTuple;
3819 
3820  procTuple = SearchSysCache1(PROCOID,
3821  ObjectIdGetDatum(aggref->aggfnoid));
3822  if (!HeapTupleIsValid(procTuple))
3823  elog(ERROR, "cache lookup failed for function %u",
3824  aggref->aggfnoid);
3825  aggOwner = ((Form_pg_proc) GETSTRUCT(procTuple))->proowner;
3826  ReleaseSysCache(procTuple);
3827 
3828  if (OidIsValid(finalfn_oid))
3829  {
3830  aclresult = pg_proc_aclcheck(finalfn_oid, aggOwner,
3831  ACL_EXECUTE);
3832  if (aclresult != ACLCHECK_OK)
3833  aclcheck_error(aclresult, OBJECT_FUNCTION,
3834  get_func_name(finalfn_oid));
3835  InvokeFunctionExecuteHook(finalfn_oid);
3836  }
3837  if (OidIsValid(serialfn_oid))
3838  {
3839  aclresult = pg_proc_aclcheck(serialfn_oid, aggOwner,
3840  ACL_EXECUTE);
3841  if (aclresult != ACLCHECK_OK)
3842  aclcheck_error(aclresult, OBJECT_FUNCTION,
3843  get_func_name(serialfn_oid));
3844  InvokeFunctionExecuteHook(serialfn_oid);
3845  }
3846  if (OidIsValid(deserialfn_oid))
3847  {
3848  aclresult = pg_proc_aclcheck(deserialfn_oid, aggOwner,
3849  ACL_EXECUTE);
3850  if (aclresult != ACLCHECK_OK)
3851  aclcheck_error(aclresult, OBJECT_FUNCTION,
3852  get_func_name(deserialfn_oid));
3853  InvokeFunctionExecuteHook(deserialfn_oid);
3854  }
3855  }
3856 
3857  /*
3858  * Get actual datatypes of the (nominal) aggregate inputs. These
3859  * could be different from the agg's declared input types, when the
3860  * agg accepts ANY or a polymorphic type.
3861  */
3862  numArguments = get_aggregate_argtypes(aggref, inputTypes);
3863 
3864  /* Count the "direct" arguments, if any */
3865  numDirectArgs = list_length(aggref->aggdirectargs);
3866 
3867  /* Detect how many arguments to pass to the finalfn */
3868  if (aggform->aggfinalextra)
3869  peragg->numFinalArgs = numArguments + 1;
3870  else
3871  peragg->numFinalArgs = numDirectArgs + 1;
3872 
3873  /* Initialize any direct-argument expressions */
3874  peragg->aggdirectargs = ExecInitExprList(aggref->aggdirectargs,
3875  (PlanState *) aggstate);
3876 
3877  /*
3878  * build expression trees using actual argument & result types for the
3879  * finalfn, if it exists and is required.
3880  */
3881  if (OidIsValid(finalfn_oid))
3882  {
3883  build_aggregate_finalfn_expr(inputTypes,
3884  peragg->numFinalArgs,
3885  aggtranstype,
3886  aggref->aggtype,
3887  aggref->inputcollid,
3888  finalfn_oid,
3889  &finalfnexpr);
3890  fmgr_info(finalfn_oid, &peragg->finalfn);
3891  fmgr_info_set_expr((Node *) finalfnexpr, &peragg->finalfn);
3892  }
3893 
3894  /* get info about the output value's datatype */
3895  get_typlenbyval(aggref->aggtype,
3896  &peragg->resulttypeLen,
3897  &peragg->resulttypeByVal);
3898 
3899  /*
3900  * Build working state for invoking the transition function, if we
3901  * haven't done it already.
3902  */
3903  pertrans = &pertransstates[aggref->aggtransno];
3904  if (pertrans->aggref == NULL)
3905  {
3906  Datum textInitVal;
3907  Datum initValue;
3908  bool initValueIsNull;
3909  Oid transfn_oid;
3910 
3911  /*
3912  * If this aggregation is performing state combines, then instead
3913  * of using the transition function, we'll use the combine
3914  * function
3915  */
3916  if (DO_AGGSPLIT_COMBINE(aggstate->aggsplit))
3917  {
3918  transfn_oid = aggform->aggcombinefn;
3919 
3920  /* If not set then the planner messed up */
3921  if (!OidIsValid(transfn_oid))
3922  elog(ERROR, "combinefn not set for aggregate function");
3923  }
3924  else
3925  transfn_oid = aggform->aggtransfn;
3926 
3927  aclresult = pg_proc_aclcheck(transfn_oid, aggOwner,
3928  ACL_EXECUTE);
3929  if (aclresult != ACLCHECK_OK)
3930  aclcheck_error(aclresult, OBJECT_FUNCTION,
3931  get_func_name(transfn_oid));
3932  InvokeFunctionExecuteHook(transfn_oid);
3933 
3934  /*
3935  * initval is potentially null, so don't try to access it as a
3936  * struct field. Must do it the hard way with SysCacheGetAttr.
3937  */
3938  textInitVal = SysCacheGetAttr(AGGFNOID, aggTuple,
3939  Anum_pg_aggregate_agginitval,
3940  &initValueIsNull);
3941  if (initValueIsNull)
3942  initValue = (Datum) 0;
3943  else
3944  initValue = GetAggInitVal(textInitVal, aggtranstype);
3945 
3946  build_pertrans_for_aggref(pertrans, aggstate, estate,
3947  aggref, transfn_oid, aggtranstype,
3948  serialfn_oid, deserialfn_oid,
3949  initValue, initValueIsNull,
3950  inputTypes, numArguments);
3951  }
3952  else
3953  pertrans->aggshared = true;
3954  ReleaseSysCache(aggTuple);
3955  }
3956 
3957  /*
3958  * Update aggstate->numaggs to be the number of unique aggregates found.
3959  * Also set numstates to the number of unique transition states found.
3960  */
3961  aggstate->numaggs = numaggs;
3962  aggstate->numtrans = numtrans;
3963 
3964  /*
3965  * Last, check whether any more aggregates got added onto the node while
3966  * we processed the expressions for the aggregate arguments (including not
3967  * only the regular arguments and FILTER expressions handled immediately
3968  * above, but any direct arguments we might've handled earlier). If so,
3969  * we have nested aggregate functions, which is semantically nonsensical,
3970  * so complain. (This should have been caught by the parser, so we don't
3971  * need to work hard on a helpful error message; but we defend against it
3972  * here anyway, just to be sure.)
3973  */
3974  if (numaggrefs != list_length(aggstate->aggs))
3975  ereport(ERROR,
3976  (errcode(ERRCODE_GROUPING_ERROR),
3977  errmsg("aggregate function calls cannot be nested")));
3978 
3979  /*
3980  * Build expressions doing all the transition work at once. We build a
3981  * different one for each phase, as the number of transition function
3982  * invocation can differ between phases. Note this'll work both for
3983  * transition and combination functions (although there'll only be one
3984  * phase in the latter case).
3985  */
3986  for (phaseidx = 0; phaseidx < aggstate->numphases; phaseidx++)
3987  {
3988  AggStatePerPhase phase = &aggstate->phases[phaseidx];
3989  bool dohash = false;
3990  bool dosort = false;
3991 
3992  /* phase 0 doesn't necessarily exist */
3993  if (!phase->aggnode)
3994  continue;
3995 
3996  if (aggstate->aggstrategy == AGG_MIXED && phaseidx == 1)
3997  {
3998  /*
3999  * Phase one, and only phase one, in a mixed agg performs both
4000  * sorting and aggregation.
4001  */
4002  dohash = true;
4003  dosort = true;
4004  }
4005  else if (aggstate->aggstrategy == AGG_MIXED && phaseidx == 0)
4006  {
4007  /*
4008  * No need to compute a transition function for an AGG_MIXED phase
4009  * 0 - the contents of the hashtables will have been computed
4010  * during phase 1.
4011  */
4012  continue;
4013  }
4014  else if (phase->aggstrategy == AGG_PLAIN ||
4015  phase->aggstrategy == AGG_SORTED)
4016  {
4017  dohash = false;
4018  dosort = true;
4019  }
4020  else if (phase->aggstrategy == AGG_HASHED)
4021  {
4022  dohash = true;
4023  dosort = false;
4024  }
4025  else
4026  Assert(false);
4027 
4028  phase->evaltrans = ExecBuildAggTrans(aggstate, phase, dosort, dohash,
4029  false);
4030 
4031  /* cache compiled expression for outer slot without NULL check */
4032  phase->evaltrans_cache[0][0] = phase->evaltrans;
4033  }
4034 
4035  return aggstate;
4036 }
struct AggStatePerTransData * AggStatePerTrans
Definition: execnodes.h:2267
ExprState ** eqfunctions
Definition: nodeAgg.h:278
AggStatePerGroup * hash_pergroup
Definition: execnodes.h:2338
#define NIL
Definition: pg_list.h:65
struct AggStatePerGroupData * AggStatePerGroup
Definition: execnodes.h:2268
static void select_current_set(AggState *aggstate, int setno, bool is_hash)
Definition: nodeAgg.c:475
int numCols
Definition: plannodes.h:862
List * qual
Definition: plannodes.h:142
AggStatePerPhase phases
Definition: execnodes.h:2305
double hashentrysize
Definition: execnodes.h:2330
#define AllocSetContextCreate
Definition: memutils.h:173
Datum * ecxt_aggvalues
Definition: execnodes.h:245
uint64 hash_ngroups_limit
Definition: execnodes.h:2327
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1831
#define GETSTRUCT(TUP)
Definition: htup_details.h:654
AttrNumber * grpColIdx
Definition: plannodes.h:863
uint64 transitionSpace
Definition: plannodes.h:867
int aggtransno
Definition: primnodes.h:341
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
Definition: execUtils.c:499
List * lcons_int(int datum, List *list)
Definition: list.c:486
int numaggs
Definition: execnodes.h:2276
Oid GetUserId(void)
Definition: miscinit.c:478
bool agg_done
Definition: execnodes.h:2294
#define castNode(_type_, nodeptr)
Definition: nodes.h:608
Oid * grpCollations
Definition: plannodes.h:865
TupleTableSlot * sort_slot
Definition: execnodes.h:2308
List * all_grouped_cols
Definition: execnodes.h:2299
Tuplesortstate * sort_out
Definition: execnodes.h:2307
ScanState ss
Definition: execnodes.h:2274
ExprContext * ps_ExprContext
Definition: execnodes.h:1004
ExprState * evaltrans
Definition: nodeAgg.h:283
int bms_next_member(const Bitmapset *a, int prevbit)
Definition: bitmapset.c:1043
const TupleTableSlotOps TTSOpsVirtual
Definition: execTuples.c:83
Oid inputcollid
Definition: primnodes.h:326
int current_phase
Definition: execnodes.h:2282
Definition: nodes.h:539
AggSplit aggsplit
Definition: execnodes.h:2279
static TupleTableSlot * ExecAgg(PlanState *pstate)
Definition: nodeAgg.c:2154
int errcode(int sqlerrcode)
Definition: elog.c:698
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1379
void build_aggregate_finalfn_expr(Oid *agg_input_types, int num_finalfn_inputs, Oid agg_state_type, Oid agg_result_type, Oid agg_input_collation, Oid finalfn_oid, Expr **finalfnexpr)
Definition: parse_agg.c:2105
TupleTableSlot * hash_spill_rslot
Definition: execnodes.h:2320
AggStatePerTrans pertrans
Definition: execnodes.h:2284
EState * state
Definition: execnodes.h:967
int projected_set
Definition: execnodes.h:2295
unsigned int Oid
Definition: postgres_ext.h:31
HeapTuple grp_firstTuple
Definition: execnodes.h:2312
Aggref * aggref
Definition: nodeAgg.h:187
int current_set
Definition: execnodes.h:2297
#define OidIsValid(objectId)
Definition: c.h:710
#define DO_AGGSPLIT_COMBINE(as)
Definition: nodes.h:801
int numtrans
Definition: execnodes.h:2277
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:209
ExprContext * tmpcontext
Definition: execnodes.h:2287
#define FUNC_MAX_ARGS
Aggref * aggref
Definition: nodeAgg.h:44
Bitmapset ** grouped_cols
Definition: nodeAgg.h:277
PlanState ps
Definition: execnodes.h:1376
int maxsets
Definition: execnodes.h:2304
Size hash_agg_entry_size(int numTrans, Size tupleWidth, Size transitionSpace)
Definition: nodeAgg.c:1694
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
Definition: aclchk.c:3313
#define DO_AGGSPLIT_SERIALIZE(as)
Definition: nodes.h:803
MemoryContext es_query_cxt
Definition: execnodes.h:599
AggStrategy aggstrategy
Definition: plannodes.h:860
bool table_filled
Definition: execnodes.h:2314
AggStrategy aggstrategy
Definition: execnodes.h:2278
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define ERROR
Definition: elog.h:46
char * get_func_name(Oid funcid)
Definition: lsyscache.c:1579
MemoryContext hash_metacxt
Definition: execnodes.h:2316
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Definition: fmgr.c:126
static void find_hash_columns(AggState *aggstate)
Definition: nodeAgg.c:1564
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
Tuplesortstate * sort_in
Definition: execnodes.h:2306
#define EXEC_FLAG_BACKWARD
Definition: executor.h:58
#define outerPlanState(node)
Definition: execnodes.h:1061
#define list_nth_node(type, list, n)
Definition: pg_list.h:306
static int initValue(long lng_val)
Definition: informix.c:677
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
Definition: execUtils.c:535
#define fmgr_info_set_expr(expr, finfo)
Definition: fmgr.h:135
List * ExecInitExprList(List *nodes, PlanState *parent)
Definition: execExpr.c:318
Index agglevelsup
Definition: primnodes.h:338
int hash_planned_partitions
Definition: execnodes.h:2328
List * aggdirectargs
Definition: primnodes.h:329
static Datum GetAggInitVal(Datum textInitVal, Oid transtype)
Definition: nodeAgg.c:4355
AggStatePerAgg curperagg
Definition: execnodes.h:2290
AggStatePerHash perhash
Definition: execnodes.h:2337
bool outeropsset
Definition: execnodes.h:1048
AggStrategy aggstrategy
Definition: nodeAgg.h:274
ExprState * evaltrans_cache[2][2]
Definition: nodeAgg.h:291
#define EXEC_FLAG_REWIND
Definition: executor.h:57
int hash_batches_used
Definition: execnodes.h:2335
#define InvokeFunctionExecuteHook(objectId)
Definition: objectaccess.h:191
#define outerPlan(node)
Definition: plannodes.h:171
int num_hashes
Definition: execnodes.h:2315
Plan plan
Definition: plannodes.h:859
HeapTuple SearchSysCache1(int cacheId, Datum key1)
Definition: syscache.c:1127
bool input_done
Definition: execnodes.h:2293
TupleDesc tts_tupleDescriptor
Definition: tuptable.h:124
ExprContext * hashcontext
Definition: execnodes.h:2285
bool * ecxt_aggnulls
Definition: execnodes.h:247
void * palloc0(Size size)
Definition: mcxt.c:1093
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:971
AclResult
Definition: acl.h:177
uintptr_t Datum
Definition: postgres.h:411
void ReleaseSysCache(HeapTuple tuple)
Definition: syscache.c:1175
Datum SysCacheGetAttr(int cacheId, HeapTuple tup, AttrNumber attributeNumber, bool *isNull)
Definition: syscache.c:1388
List * groupingSets
Definition: plannodes.h:870
int16 resulttypeLen
Definition: nodeAgg.h:216
static void initialize_phase(AggState *aggstate, int newphase)
Definition: nodeAgg.c:497
FormData_pg_proc * Form_pg_proc
Definition: pg_proc.h:136
Plan * plan
Definition: execnodes.h:965
#define InvalidOid
Definition: postgres_ext.h:36
Oid aggfnoid
Definition: primnodes.h:323
#define ereport(elevel,...)
Definition: elog.h:157
int aggno
Definition: primnodes.h:340
#define Max(x, y)
Definition: c.h:980
ExprContext ** aggcontexts
Definition: execnodes.h:2286
#define makeNode(_type_)
Definition: nodes.h:587
int plan_width
Definition: plannodes.h:124
#define HeapTupleIsValid(tuple)
Definition: htup.h:78
#define Assert(condition)
Definition: c.h:804
#define lfirst(lc)
Definition: pg_list.h:169
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
Definition: execGrouping.c:59
#define EXEC_FLAG_MARK
Definition: executor.h:59
AggSplit aggsplit
Definition: plannodes.h:861
struct AggStatePerAggData * AggStatePerAgg
Definition: execnodes.h:2266
FormData_pg_aggregate * Form_pg_aggregate
Definition: pg_aggregate.h:109
AggSplit aggsplit
Definition: primnodes.h:339
AggStatePerGroup * pergroups
Definition: execnodes.h:2310
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:480
static int list_length(const List *l)
Definition: pg_list.h:149
long numGroups
Definition: plannodes.h:866
#define DO_AGGSPLIT_SKIPFINAL(as)
Definition: nodes.h:802
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
Definition: lsyscache.c:2198
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1799
bool outeropsfixed
Definition: execnodes.h:1044
Bitmapset * bms_add_member(Bitmapset *a, int x)
Definition: bitmapset.c:736
#define DO_AGGSPLIT_DESERIALIZE(as)
Definition: nodes.h:804
Size hash_mem_limit
Definition: execnodes.h:2326
struct Plan * lefttree
Definition: plannodes.h:143
int numphases
Definition: execnodes.h:2281
ExprState * qual
Definition: execnodes.h:986
void hash_agg_set_limits(double hashentrysize, double input_groups, int used_bits, Size *mem_limit, uint64 *ngroups_limit, int *num_partitions)
Definition: nodeAgg.c:1798
Oid * grpOperators
Definition: plannodes.h:864
void * palloc(Size size)
Definition: mcxt.c:1062
int errmsg(const char *fmt,...)
Definition: elog.c:909
List * chain
Definition: plannodes.h:871
AggStatePerAgg peragg
Definition: execnodes.h:2283
#define ACL_EXECUTE
Definition: parsenodes.h:89
#define elog(elevel,...)
Definition: elog.h:232
AclResult pg_proc_aclcheck(Oid proc_oid, Oid roleid, AclMode mode)
Definition: aclchk.c:4723
int i
List * aggdirectargs
Definition: nodeAgg.h:210
Oid aggtranstype
Definition: primnodes.h:327
AggStatePerTrans curpertrans
Definition: execnodes.h:2292
Oid aggtype
Definition: primnodes.h:324
bool resulttypeByVal
Definition: nodeAgg.h:217
Definition: plannodes.h:857
ExprContext * CreateWorkExprContext(EState *estate)
Definition: execUtils.c:316
List * aggs
Definition: execnodes.h:2275
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
Definition: execUtils.c:682
int get_aggregate_argtypes(Aggref *aggref, Oid *inputTypes)
Definition: parse_agg.c:1887
static void build_pertrans_for_aggref(AggStatePerTrans pertrans, AggState *aggstate, EState *estate, Aggref *aggref, Oid aggtransfn, Oid aggtranstype, Oid aggserialfn, Oid aggdeserialfn, Datum initValue, bool initValueIsNull, Oid *inputTypes, int numArguments)
Definition: nodeAgg.c:4047
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:141
#define EXEC_FLAG_EXPLAIN_ONLY
Definition: executor.h:56
const TupleTableSlotOps TTSOpsMinimalTuple
Definition: execTuples.c:85
FmgrInfo finalfn
Definition: nodeAgg.h:199
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:793
TupleTableSlot * hash_spill_wslot
Definition: execnodes.h:2321
static void build_hash_tables(AggState *aggstate)
Definition: nodeAgg.c:1469
const TupleTableSlotOps * outerops
Definition: execnodes.h:1040
ExprState * ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, bool doSort, bool doHash, bool nullcheck)
Definition: execExpr.c:3265
AggStatePerGroup * all_pergroups
Definition: execnodes.h:2343

◆ ExecReScanAgg()

void ExecReScanAgg ( AggState node)

Definition at line 4441 of file nodeAgg.c.

References AggState::agg_done, AGG_HASHED, AGG_MIXED, AggState::aggcontexts, Agg::aggParams, AggState::aggstrategy, bms_overlap(), build_hash_tables(), PlanState::chgParam, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExecClearTuple(), ExecReScan(), AggState::grp_firstTuple, AggState::hash_ever_spilled, AggState::hash_ngroups_current, AggState::hash_spill_mode, hashagg_recompile_expressions(), hashagg_reset_spill_state(), AggState::hashcontext, AggStatePerHashData::hashiter, AggStatePerHashData::hashtable, heap_freetuple(), initialize_phase(), AggState::input_done, Max, AggState::maxsets, MemSet, AggState::numaggs, AggState::numtrans, outerPlan, outerPlanState, AggState::pergroups, AggState::perhash, AggState::pertrans, PlanState::plan, AggState::projected_set, ScanState::ps, PlanState::ps_ExprContext, ReScanExprContext(), ResetTupleHashIterator, select_current_set(), AggStatePerTransData::sortstates, AggState::ss, ScanState::ss_ScanTupleSlot, AggState::table_filled, and tuplesort_end().

Referenced by ExecReScan().

4442 {
4443  ExprContext *econtext = node->ss.ps.ps_ExprContext;
4445  Agg *aggnode = (Agg *) node->ss.ps.plan;
4446  int transno;
4447  int numGroupingSets = Max(node->maxsets, 1);
4448  int setno;
4449 
4450  node->agg_done = false;
4451 
4452  if (node->aggstrategy == AGG_HASHED)
4453  {
4454  /*
4455  * In the hashed case, if we haven't yet built the hash table then we
4456  * can just return; nothing done yet, so nothing to undo. If subnode's
4457  * chgParam is not NULL then it will be re-scanned by ExecProcNode,
4458  * else no reason to re-scan it at all.
4459  */
4460  if (!node->table_filled)
4461  return;
4462 
4463  /*
4464  * If we do have the hash table, and it never spilled, and the subplan
4465  * does not have any parameter changes, and none of our own parameter
4466  * changes affect input expressions of the aggregated functions, then
4467  * we can just rescan the existing hash table; no need to build it
4468  * again.
4469  */
4470  if (outerPlan->chgParam == NULL && !node->hash_ever_spilled &&
4471  !bms_overlap(node->ss.ps.chgParam, aggnode->aggParams))
4472  {
4474  &node->perhash[0].hashiter);
4475  select_current_set(node, 0, true);
4476  return;
4477  }
4478  }
4479 
4480  /* Make sure we have closed any open tuplesorts */
4481  for (transno = 0; transno < node->numtrans; transno++)
4482  {
4483  for (setno = 0; setno < numGroupingSets; setno++)
4484  {
4485  AggStatePerTrans pertrans = &node->pertrans[transno];
4486 
4487  if (pertrans->sortstates[setno])
4488  {
4489  tuplesort_end(pertrans->sortstates[setno]);
4490  pertrans->sortstates[setno] = NULL;
4491  }
4492  }
4493  }
4494 
4495  /*
4496  * We don't need to ReScanExprContext the output tuple context here;
4497  * ExecReScan already did it. But we do need to reset our per-grouping-set
4498  * contexts, which may have transvalues stored in them. (We use rescan
4499  * rather than just reset because transfns may have registered callbacks
4500  * that need to be run now.) For the AGG_HASHED case, see below.
4501  */
4502 
4503  for (setno = 0; setno < numGroupingSets; setno++)
4504  {
4505  ReScanExprContext(node->aggcontexts[setno]);
4506  }
4507 
4508  /* Release first tuple of group, if we have made a copy */
4509  if (node->grp_firstTuple != NULL)
4510  {
4512  node->grp_firstTuple = NULL;
4513  }
4515 
4516  /* Forget current agg values */
4517  MemSet(econtext->ecxt_aggvalues, 0, sizeof(Datum) * node->numaggs);
4518  MemSet(econtext->ecxt_aggnulls, 0, sizeof(bool) * node->numaggs);
4519 
4520  /*
4521  * With AGG_HASHED/MIXED, the hash table is allocated in a sub-context of
4522  * the hashcontext. This used to be an issue, but now, resetting a context
4523  * automatically deletes sub-contexts too.
4524  */
4525  if (node->aggstrategy == AGG_HASHED || node->aggstrategy == AGG_MIXED)
4526  {
4528 
4529  node->hash_ever_spilled = false;
4530  node->hash_spill_mode = false;
4531  node->hash_ngroups_current = 0;
4532 
4534  /* Rebuild an empty hash table */
4535  build_hash_tables(node);
4536  node->table_filled = false;
4537  /* iterator will be reset when the table is filled */
4538 
4539  hashagg_recompile_expressions(node, false, false);
4540  }
4541 
4542  if (node->aggstrategy != AGG_HASHED)
4543  {
4544  /*
4545  * Reset the per-group state (in particular, mark transvalues null)
4546  */
4547  for (setno = 0; setno < numGroupingSets; setno++)
4548  {
4549  MemSet(node->pergroups[setno], 0,
4550  sizeof(AggStatePerGroupData) * node->numaggs);
4551  }
4552 
4553  /* reset to phase 1 */
4554  initialize_phase(node, 1);
4555 
4556  node->input_done = false;
4557  node->projected_set = -1;
4558  }
4559 
4560  if (outerPlan->chgParam == NULL)
4561  ExecReScan(outerPlan);
4562 }
static void hashagg_reset_spill_state(AggState *aggstate)
Definition: nodeAgg.c:3194
static void select_current_set(AggState *aggstate, int setno, bool is_hash)
Definition: nodeAgg.c:475
Datum * ecxt_aggvalues
Definition: execnodes.h:245
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:425
int numaggs
Definition: execnodes.h:2276
bool agg_done
Definition: execnodes.h:2294
ScanState ss
Definition: execnodes.h:2274
ExprContext * ps_ExprContext
Definition: execnodes.h:1004
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
#define MemSet(start, val, len)
Definition: c.h:1008
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1379
AggStatePerTrans pertrans
Definition: execnodes.h:2284
int projected_set
Definition: execnodes.h:2295
void heap_freetuple(HeapTuple htup)
Definition: heaptuple.c:1338
HeapTuple grp_firstTuple
Definition: execnodes.h:2312
int numtrans
Definition: execnodes.h:2277
bool hash_spill_mode
Definition: execnodes.h:2324
PlanState ps
Definition: execnodes.h:1376
int maxsets
Definition: execnodes.h:2304
bool table_filled
Definition: execnodes.h:2314
AggStrategy aggstrategy
Definition: execnodes.h:2278
#define outerPlanState(node)
Definition: execnodes.h:1061
Tuplesortstate ** sortstates
Definition: nodeAgg.h:154
Bitmapset * aggParams
Definition: plannodes.h:868
AggStatePerHash perhash
Definition: execnodes.h:2337
Bitmapset * chgParam
Definition: execnodes.h:997
#define outerPlan(node)
Definition: plannodes.h:171
TupleHashIterator hashiter
Definition: nodeAgg.h:304
bool input_done
Definition: execnodes.h:2293
ExprContext * hashcontext
Definition: execnodes.h:2285
bool * ecxt_aggnulls
Definition: execnodes.h:247
uintptr_t Datum
Definition: postgres.h:411
static void initialize_phase(AggState *aggstate, int newphase)
Definition: nodeAgg.c:497
Plan * plan
Definition: execnodes.h:965
#define ResetTupleHashIterator(htable, iter)
Definition: execnodes.h:768
static void hashagg_recompile_expressions(AggState *aggstate, bool minslot, bool nullcheck)
Definition: nodeAgg.c:1741
#define Max(x, y)
Definition: c.h:980
ExprContext ** aggcontexts
Definition: execnodes.h:2286
bool hash_ever_spilled
Definition: execnodes.h:2323
AggStatePerGroup * pergroups
Definition: execnodes.h:2310
void ReScanExprContext(ExprContext *econtext)
Definition: execUtils.c:438
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Definition: bitmapset.c:494
uint64 hash_ngroups_current
Definition: execnodes.h:2332
Definition: plannodes.h:857
void tuplesort_end(Tuplesortstate *state)
Definition: tuplesort.c:1464
TupleHashTable hashtable
Definition: nodeAgg.h:303
static void build_hash_tables(AggState *aggstate)
Definition: nodeAgg.c:1469

◆ hash_agg_entry_size()

Size hash_agg_entry_size ( int  numTrans,
Size  tupleWidth,
Size  transitionSpace 
)

Definition at line 1694 of file nodeAgg.c.

References CHUNKHDRSZ, MAXALIGN, and SizeofMinimalTupleHeader.

Referenced by cost_agg(), estimate_hashagg_tablesize(), and ExecInitAgg().

1695 {
1696  Size tupleChunkSize;
1697  Size pergroupChunkSize;
1698  Size transitionChunkSize;
1699  Size tupleSize = (MAXALIGN(SizeofMinimalTupleHeader) +
1700  tupleWidth);
1701  Size pergroupSize = numTrans * sizeof(AggStatePerGroupData);
1702 
1703  tupleChunkSize = CHUNKHDRSZ + tupleSize;
1704 
1705  if (pergroupSize > 0)
1706  pergroupChunkSize = CHUNKHDRSZ + pergroupSize;
1707  else
1708  pergroupChunkSize = 0;
1709 
1710  if (transitionSpace > 0)
1711  transitionChunkSize = CHUNKHDRSZ + transitionSpace;
1712  else
1713  transitionChunkSize = 0;
1714 
1715  return
1716  sizeof(TupleHashEntryData) +
1717  tupleChunkSize +
1718  pergroupChunkSize +
1719  transitionChunkSize;
1720 }
struct TupleHashEntryData TupleHashEntryData
struct AggStatePerGroupData AggStatePerGroupData
#define SizeofMinimalTupleHeader
Definition: htup_details.h:648
size_t Size
Definition: c.h:540
#define MAXALIGN(LEN)
Definition: c.h:757
#define CHUNKHDRSZ
Definition: nodeAgg.c:312

◆ hash_agg_set_limits()

void hash_agg_set_limits ( double  hashentrysize,
double  input_groups,
int  used_bits,
Size mem_limit,
uint64 *  ngroups_limit,
int *  num_partitions 
)

Definition at line 1798 of file nodeAgg.c.

References get_hash_mem(), hash_choose_num_partitions(), HASHAGG_READ_BUFFER_SIZE, and HASHAGG_WRITE_BUFFER_SIZE.

Referenced by agg_refill_hash_table(), cost_agg(), and ExecInitAgg().

1801 {
1802  int npartitions;
1803  Size partition_mem;
1804  int hash_mem = get_hash_mem();
1805 
1806  /* if not expected to spill, use all of hash_mem */
1807  if (input_groups * hashentrysize < hash_mem * 1024L)
1808  {
1809  if (num_partitions != NULL)
1810  *num_partitions = 0;
1811  *mem_limit = hash_mem * 1024L;
1812  *ngroups_limit = *mem_limit / hashentrysize;
1813  return;
1814  }
1815 
1816  /*
1817  * Calculate expected memory requirements for spilling, which is the size
1818  * of the buffers needed for all the tapes that need to be open at once.
1819  * Then, subtract that from the memory available for holding hash tables.
1820  */
1821  npartitions = hash_choose_num_partitions(input_groups,
1822  hashentrysize,
1823  used_bits,
1824  NULL);
1825  if (num_partitions != NULL)
1826  *num_partitions = npartitions;
1827 
1828  partition_mem =
1830  HASHAGG_WRITE_BUFFER_SIZE * npartitions;
1831 
1832  /*
1833  * Don't set the limit below 3/4 of hash_mem. In that case, we are at the
1834  * minimum number of partitions, so we aren't going to dramatically exceed
1835  * work mem anyway.
1836  */
1837  if (hash_mem * 1024L > 4 * partition_mem)
1838  *mem_limit = hash_mem * 1024L - partition_mem;
1839  else
1840  *mem_limit = hash_mem * 1024L * 0.75;
1841 
1842  if (*mem_limit > hashentrysize)
1843  *ngroups_limit = *mem_limit / hashentrysize;
1844  else
1845  *ngroups_limit = 1;
1846 }
static int hash_choose_num_partitions(double input_groups, double hashentrysize, int used_bits, int *log2_npartittions)
Definition: nodeAgg.c:1991
#define HASHAGG_READ_BUFFER_SIZE
Definition: nodeAgg.c:297
size_t Size
Definition: c.h:540
#define HASHAGG_WRITE_BUFFER_SIZE
Definition: nodeAgg.c:298
int get_hash_mem(void)
Definition: nodeHash.c:3389