296 #define HASHAGG_PARTITION_FACTOR 1.50
297 #define HASHAGG_MIN_PARTITIONS 4
298 #define HASHAGG_MAX_PARTITIONS 1024
306 #define HASHAGG_READ_BUFFER_SIZE BLCKSZ
307 #define HASHAGG_WRITE_BUFFER_SIZE BLCKSZ
315 #define HASHAGG_HLL_BIT_WIDTH 5
321 #define CHUNKHDRSZ 16
387 Datum *resultVal,
bool *resultIsNull);
391 Datum *resultVal,
bool *resultIsNull);
410 long ngroups,
Size memory);
412 double hashentrysize,
414 int *log2_npartitions);
431 int64 input_tuples,
double input_card,
435 int used_bits,
double input_groups,
436 double hashentrysize);
445 Oid aggtranstype,
Oid aggserialfn,
447 bool initValueIsNull,
Oid *inputTypes,
480 Assert(newphase <= 1 || newphase == aggstate->current_phase + 1);
519 if (newphase > 0 && newphase < aggstate->numphases - 1)
527 sortnode->sortColIdx,
528 sortnode->sortOperators,
529 sortnode->collations,
530 sortnode->nullsFirst,
677 numReset = numGroupingSets;
679 for (setno = 0; setno < numReset; setno++)
685 for (transno = 0; transno < numTrans; transno++)
724 for (
i = 1;
i <= numTransInputs;
i++)
854 bool oldIsNull =
true;
855 bool haveOldVal =
false;
880 true,
false, newVal, isNull, &newAbbrevVal))
894 ((oldIsNull && *isNull) ||
895 (!oldIsNull && !*isNull &&
896 oldAbbrevVal == newAbbrevVal &&
924 oldAbbrevVal = newAbbrevVal;
962 bool haveOldValue =
false;
973 true,
true, slot1, &newAbbrevVal))
980 if (numDistinctCols == 0 ||
982 newAbbrevVal != oldAbbrevVal ||
993 for (
i = 0;
i < numTransInputs;
i++)
1001 if (numDistinctCols > 0)
1009 oldAbbrevVal = newAbbrevVal;
1010 haveOldValue =
true;
1050 Datum *resultVal,
bool *resultIsNull)
1053 bool anynull =
false;
1074 &fcinfo->args[
i].isnull);
1075 anynull |= fcinfo->args[
i].isnull;
1092 (
void *) aggstate, NULL);
1095 fcinfo->args[0].value =
1103 for (;
i < numFinalArgs;
i++)
1105 fcinfo->args[
i].value = (
Datum) 0;
1106 fcinfo->args[
i].isnull =
true;
1110 if (fcinfo->flinfo->fn_strict && anynull)
1113 *resultVal = (
Datum) 0;
1114 *resultIsNull =
true;
1121 *resultIsNull = fcinfo->isnull;
1126 aggstate->curperagg = NULL;
1150 Datum *resultVal,
bool *resultIsNull)
1166 *resultVal = (
Datum) 0;
1167 *resultIsNull =
true;
1182 *resultIsNull = fcinfo->
isnull;
1308 for (
int transno = 0; transno < aggstate->
numtrans; transno++)
1313 pergroupstate = &pergroup[transno];
1349 for (aggno = 0; aggno < aggstate->
numaggs; aggno++)
1352 int transno = peragg->
transno;
1355 pergroupstate = &pergroup[transno];
1359 &aggvalues[aggno], &aggnulls[aggno]);
1362 &aggvalues[aggno], &aggnulls[aggno]);
1404 context.aggregated = NULL;
1405 context.unaggregated = NULL;
1416 *aggregated = context.aggregated;
1417 *unaggregated = context.unaggregated;
1445 context->is_aggref =
false;
1473 for (setno = 0; setno < aggstate->
num_hashes; ++setno)
1510 Size additionalsize;
1529 perhash->
aggnode->grpCollations,
1575 find_cols(aggstate, &aggregated_colnos, &base_colnos);
1580 for (
int i = 0;
i < scanDesc->
natts;
i++)
1590 for (
j = 0;
j < numHashes; ++
j)
1677 perhash->
aggnode->grpOperators,
1697 Size tupleChunkSize;
1698 Size pergroupChunkSize;
1699 Size transitionChunkSize;
1706 if (pergroupSize > 0)
1707 pergroupChunkSize =
CHUNKHDRSZ + pergroupSize;
1709 pergroupChunkSize = 0;
1711 if (transitionSpace > 0)
1712 transitionChunkSize =
CHUNKHDRSZ + transitionSpace;
1714 transitionChunkSize = 0;
1720 transitionChunkSize;
1745 int i = minslot ? 1 : 0;
1746 int j = nullcheck ? 1 : 0;
1752 phase = &aggstate->
phases[0];
1754 phase = &aggstate->
phases[1];
1761 bool dosort =
false;
1800 Size *mem_limit, uint64 *ngroups_limit,
1801 int *num_partitions)
1808 if (input_groups * hashentrysize <= hash_mem_limit)
1810 if (num_partitions != NULL)
1811 *num_partitions = 0;
1812 *mem_limit = hash_mem_limit;
1813 *ngroups_limit = hash_mem_limit / hashentrysize;
1826 if (num_partitions != NULL)
1827 *num_partitions = npartitions;
1838 if (hash_mem_limit > 4 * partition_mem)
1839 *mem_limit = hash_mem_limit - partition_mem;
1841 *mem_limit = hash_mem_limit * 0.75;
1843 if (*mem_limit > hashentrysize)
1844 *ngroups_limit = *mem_limit / hashentrysize;
1899 for (
int setno = 0; setno < aggstate->
num_hashes; setno++)
1941 total_mem = meta_mem + hashkey_mem + buffer_mem;
1970 long nbuckets = ngroups;
1972 max_nbuckets = memory / hashentrysize;
1980 if (nbuckets > max_nbuckets)
1981 nbuckets = max_nbuckets;
1983 return Max(nbuckets, 1);
1993 int used_bits,
int *log2_npartitions)
1996 double partition_limit;
2013 dpartitions = 1 + (mem_wanted / hash_mem_limit);
2015 if (dpartitions > partition_limit)
2016 dpartitions = partition_limit;
2024 npartitions = (int) dpartitions;
2027 partition_bits =
my_log2(npartitions);
2030 if (partition_bits + used_bits >= 32)
2031 partition_bits = 32 - used_bits;
2033 if (log2_npartitions != NULL)
2034 *log2_npartitions = partition_bits;
2037 npartitions = 1 << partition_bits;
2069 for (transno = 0; transno < aggstate->
numtrans; transno++)
2102 for (setno = 0; setno < aggstate->
num_hashes; setno++)
2140 pergroup[setno] = NULL;
2222 peragg = aggstate->
peragg;
2258 numReset = numGroupingSets;
2267 for (
i = 0;
i < numReset;
i++)
2286 numReset = numGroupingSets;
2377 if (hasGroupingSets)
2470 if (hasGroupingSets)
2522 pergroups[currentSet]);
2601 bool spill_initialized =
false;
2626 for (
int setno = 0; setno < aggstate->
num_hashes; setno++)
2690 if (!spill_initialized)
2696 spill_initialized =
true;
2719 if (spill_initialized)
2751 while (result == NULL)
2788 peragg = aggstate->
peragg;
2816 if (nextset < aggstate->num_hashes)
2896 double input_groups,
double hashentrysize)
2902 used_bits, &partition_bits);
2908 for (
int i = 0;
i < npartitions;
i++)
2911 spill->
shift = 32 - used_bits - partition_bits;
2912 spill->
mask = (npartitions - 1) << spill->
shift;
2915 for (
int i = 0;
i < npartitions;
i++)
2933 int total_written = 0;
2957 spillslot = inputslot;
2974 total_written +=
sizeof(
uint32);
2977 total_written += tuple->
t_len;
2982 return total_written;
2993 int64 input_tuples,
double input_card,
int used_bits)
2997 batch->
setno = setno;
3022 if (nread !=
sizeof(
uint32))
3025 errmsg_internal(
"unexpected EOF for tape %p: requested %zu bytes, read %zu bytes",
3026 tape,
sizeof(
uint32), nread)));
3031 if (nread !=
sizeof(
uint32))
3034 errmsg_internal(
"unexpected EOF for tape %p: requested %zu bytes, read %zu bytes",
3035 tape,
sizeof(
uint32), nread)));
3038 tuple->
t_len = t_len;
3041 (
char *) tuple +
sizeof(
uint32),
3043 if (nread != t_len -
sizeof(
uint32))
3046 errmsg_internal(
"unexpected EOF for tape %p: requested %zu bytes, read %zu bytes",
3047 tape, t_len -
sizeof(
uint32), nread)));
3063 int total_npartitions = 0;
3067 for (setno = 0; setno < aggstate->
num_hashes; setno++)
3097 int used_bits = 32 - spill->
shift;
3141 for (setno = 0; setno < aggstate->
num_hashes; setno++)
3192 int numGroupingSets = 1;
3233 numPhases = (use_hashing ? 1 : 2);
3234 numHashes = (use_hashing ? 1 : 0);
3245 foreach(l, node->
chain)
3249 numGroupingSets =
Max(numGroupingSets,
3263 aggstate->
maxsets = numGroupingSets;
3286 for (
i = 0;
i < numGroupingSets; ++
i)
3376 foreach(l, aggstate->
aggs)
3380 max_aggno =
Max(max_aggno, aggref->aggno);
3381 max_transno =
Max(max_transno, aggref->aggtransno);
3383 numaggs = max_aggno + 1;
3384 numtrans = max_transno + 1;
3418 Assert(phase <= 1 || sortnode);
3467 for (
j = 0;
j < current_length; ++
j)
3500 for (
int k = 0; k < phasedata->
numsets; k++)
3516 aggnode->grpOperators,
3517 aggnode->grpCollations,
3529 aggnode->grpOperators,
3530 aggnode->grpCollations,
3559 aggstate->
peragg = peraggs;
3560 aggstate->
pertrans = pertransstates;
3565 * (numGroupingSets + numHashes));
3570 for (
i = 0;
i < numGroupingSets;
i++)
3577 pergroups += numGroupingSets;
3586 uint64 totalGroups = 0;
3589 "HashAgg meta context",
3609 for (
int k = 0; k < aggstate->
num_hashes; k++)
3651 foreach(l, aggstate->
aggs)
3657 int numAggTransFnArgs;
3670 Assert(aggref->agglevelsup == 0);
3674 peragg = &peraggs[aggref->aggno];
3677 if (peragg->
aggref != NULL)
3681 peragg->
transno = aggref->aggtransno;
3687 elog(
ERROR,
"cache lookup failed for aggregate %u",
3700 aggtranstype = aggref->aggtranstype;
3707 peragg->
finalfn_oid = finalfn_oid = aggform->aggfinalfn;
3716 if (aggtranstype == INTERNALOID)
3729 elog(
ERROR,
"serialfunc not provided for serialization aggregation");
3730 serialfn_oid = aggform->aggserialfn;
3740 elog(
ERROR,
"deserialfunc not provided for deserialization aggregation");
3741 deserialfn_oid = aggform->aggdeserialfn;
3752 elog(
ERROR,
"cache lookup failed for function %u",
3759 aclresult =
object_aclcheck(ProcedureRelationId, finalfn_oid, aggOwner,
3768 aclresult =
object_aclcheck(ProcedureRelationId, serialfn_oid, aggOwner,
3777 aclresult =
object_aclcheck(ProcedureRelationId, deserialfn_oid, aggOwner,
3792 aggTransFnInputTypes);
3798 if (aggform->aggfinalextra)
3817 aggref->inputcollid,
3833 pertrans = &pertransstates[aggref->aggtransno];
3834 if (pertrans->
aggref == NULL)
3838 bool initValueIsNull;
3848 transfn_oid = aggform->aggcombinefn;
3852 elog(
ERROR,
"combinefn not set for aggregate function");
3855 transfn_oid = aggform->aggtransfn;
3868 Anum_pg_aggregate_agginitval,
3870 if (initValueIsNull)
3877 Oid combineFnInputTypes[] = {aggtranstype,
3889 aggref, transfn_oid, aggtranstype,
3890 serialfn_oid, deserialfn_oid,
3892 combineFnInputTypes, 2);
3902 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
3903 errmsg(
"combine function with transition type %s must not be declared STRICT",
3909 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
3915 aggref, transfn_oid, aggtranstype,
3916 serialfn_oid, deserialfn_oid,
3918 aggTransFnInputTypes,
3932 if (numAggTransFnArgs <= numDirectArgs ||
3936 (
errcode(ERRCODE_INVALID_FUNCTION_DEFINITION),
3937 errmsg(
"aggregate %u needs to have compatible input type and transition type",
3966 (
errcode(ERRCODE_GROUPING_ERROR),
3967 errmsg(
"aggregate function calls cannot be nested")));
3976 for (phaseidx = 0; phaseidx < aggstate->
numphases; phaseidx++)
3979 bool dohash =
false;
3980 bool dosort =
false;
4042 Oid transfn_oid,
Oid aggtranstype,
4043 Oid aggserialfn,
Oid aggdeserialfn,
4045 Oid *inputTypes,
int numArguments)
4047 int numGroupingSets =
Max(aggstate->
maxsets, 1);
4050 Expr *serialfnexpr = NULL;
4051 Expr *deserialfnexpr = NULL;
4057 int numDistinctCols;
4061 pertrans->
aggref = aggref;
4088 aggref->aggvariadic,
4090 aggref->inputcollid,
4105 (
void *) aggstate, NULL);
4125 (
void *) aggstate, NULL);
4141 (
void *) aggstate, NULL);
4159 if (AGGKIND_IS_ORDERED_SET(aggref->aggkind))
4162 numSortCols = numDistinctCols = 0;
4168 numSortCols = numDistinctCols = 0;
4174 numSortCols = numDistinctCols =
list_length(sortlist);
4182 numDistinctCols = 0;
4194 if (numSortCols > 0 || aggref->
aggfilter)
4202 if (numSortCols > 0)
4220 else if (numDistinctCols > 0)
4236 (
bool *)
palloc(numSortCols *
sizeof(
bool));
4239 foreach(lc, sortlist)
4260 Assert(numArguments > 0);
4263 ops =
palloc(numDistinctCols *
sizeof(
Oid));
4270 if (numDistinctCols == 1)
4321 Assert(ParallelWorkerNumber <= node->shared_info->num_workers);
4343 for (transno = 0; transno < node->
numtrans; transno++)
4347 for (setno = 0; setno < numGroupingSets; setno++)
4355 for (setno = 0; setno < numGroupingSets; setno++)
4405 for (transno = 0; transno < node->
numtrans; transno++)
4407 for (setno = 0; setno < numGroupingSets; setno++)
4427 for (setno = 0; setno < numGroupingSets; setno++)
4471 for (setno = 0; setno < numGroupingSets; setno++)
4568 return curperagg->aggref;
4574 return curpertrans->
aggref;
4668 elog(
ERROR,
"aggregate function cannot register a callback in this context");
void aclcheck_error(AclResult aclerr, ObjectType objtype, const char *objectname)
AclResult object_aclcheck(Oid classid, Oid objectid, Oid roleid, AclMode mode)
int bms_next_member(const Bitmapset *a, int prevbit)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
#define TextDatumGetCString(d)
#define MemSet(start, val, len)
#define OidIsValid(objectId)
Datum datumCopy(Datum value, bool typByVal, int typLen)
elog(ERROR, "%s: %s", p2, msg)
int errmsg_internal(const char *fmt,...)
int errcode_for_file_access(void)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
void ExecReScan(PlanState *node)
Datum ExecAggCopyTransValue(AggState *aggstate, AggStatePerTrans pertrans, Datum newValue, bool newValueIsNull, Datum oldValue, bool oldValueIsNull)
List * ExecInitExprList(List *nodes, PlanState *parent)
ExprState * ExecBuildAggTrans(AggState *aggstate, AggStatePerPhase phase, bool doSort, bool doHash, bool nullcheck)
ExprState * ExecInitQual(List *qual, PlanState *parent)
void execTuplesHashPrepare(int numCols, const Oid *eqOperators, Oid **eqFuncOids, FmgrInfo **hashFunctions)
TupleHashEntry LookupTupleHashEntryHash(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 hash)
TupleHashEntry LookupTupleHashEntry(TupleHashTable hashtable, TupleTableSlot *slot, bool *isnew, uint32 *hash)
TupleHashTable BuildTupleHashTableExt(PlanState *parent, TupleDesc inputDesc, int numCols, AttrNumber *keyColIdx, const Oid *eqfuncoids, FmgrInfo *hashfunctions, Oid *collations, long nbuckets, Size additionalsize, MemoryContext metacxt, MemoryContext tablecxt, MemoryContext tempcxt, bool use_variable_hash_iv)
void ResetTupleHashTable(TupleHashTable hashtable)
ExprState * execTuplesMatchPrepare(TupleDesc desc, int numCols, const AttrNumber *keyColIdx, const Oid *eqOperators, const Oid *collations, PlanState *parent)
void ExecEndNode(PlanState *node)
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
const TupleTableSlotOps TTSOpsVirtual
TupleTableSlot * ExecStoreVirtualTuple(TupleTableSlot *slot)
MinimalTuple ExecFetchSlotMinimalTuple(TupleTableSlot *slot, bool *shouldFree)
TupleTableSlot * ExecStoreAllNullTuple(TupleTableSlot *slot)
TupleTableSlot * ExecStoreMinimalTuple(MinimalTuple mtup, TupleTableSlot *slot, bool shouldFree)
TupleTableSlot * ExecInitExtraTupleSlot(EState *estate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
void ExecInitResultTupleSlotTL(PlanState *planstate, const TupleTableSlotOps *tts_ops)
const TupleTableSlotOps TTSOpsMinimalTuple
TupleDesc ExecTypeFromTL(List *targetList)
TupleTableSlot * ExecAllocTableSlot(List **tupleTable, TupleDesc desc, const TupleTableSlotOps *tts_ops)
void ExecForceStoreHeapTuple(HeapTuple tuple, TupleTableSlot *slot, bool shouldFree)
TupleDesc ExecGetResultType(PlanState *planstate)
void ReScanExprContext(ExprContext *econtext)
ExprContext * CreateWorkExprContext(EState *estate)
const TupleTableSlotOps * ExecGetResultSlotOps(PlanState *planstate, bool *isfixed)
void ExecCreateScanSlotFromOuterPlan(EState *estate, ScanState *scanstate, const TupleTableSlotOps *tts_ops)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
void ExecAssignProjectionInfo(PlanState *planstate, TupleDesc inputDesc)
void RegisterExprContextCallback(ExprContext *econtext, ExprContextCallbackFunction function, Datum arg)
void(* ExprContextCallbackFunction)(Datum arg)
#define InstrCountFiltered1(node, delta)
#define outerPlanState(node)
#define ScanTupleHashTable(htable, iter)
#define ResetTupleHashIterator(htable, iter)
struct AggStatePerGroupData * AggStatePerGroup
struct AggStatePerTransData * AggStatePerTrans
struct TupleHashEntryData TupleHashEntryData
struct AggregateInstrumentation AggregateInstrumentation
struct AggStatePerAggData * AggStatePerAgg
#define EXEC_FLAG_BACKWARD
static TupleTableSlot * ExecProject(ProjectionInfo *projInfo)
#define ResetExprContext(econtext)
static bool ExecQual(ExprState *state, ExprContext *econtext)
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
static Datum ExecEvalExpr(ExprState *state, ExprContext *econtext, bool *isNull)
static Datum ExecEvalExprSwitchContext(ExprState *state, ExprContext *econtext, bool *isNull)
#define EXEC_FLAG_EXPLAIN_ONLY
static TupleTableSlot * ExecProcNode(PlanState *node)
#define MakeExpandedObjectReadOnly(d, isnull, typlen)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
void fmgr_info(Oid functionId, FmgrInfo *finfo)
Datum OidInputFunctionCall(Oid functionId, char *str, Oid typioparam, int32 typmod)
#define SizeForFunctionCallInfo(nargs)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define AGG_CONTEXT_WINDOW
#define LOCAL_FCINFO(name, nargs)
#define AGG_CONTEXT_AGGREGATE
struct FunctionCallInfoBaseData * FunctionCallInfo
#define FunctionCallInvoke(fcinfo)
#define fmgr_info_set_expr(expr, finfo)
uint32 hash_bytes_uint32(uint32 k)
void heap_freetuple(HeapTuple htup)
MinimalTupleData * MinimalTuple
#define HeapTupleIsValid(tuple)
#define SizeofMinimalTupleHeader
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
void freeHyperLogLog(hyperLogLogState *cState)
#define IsParallelWorker()
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
List * lcons_int(int datum, List *list)
List * lappend(List *list, void *datum)
void list_free(List *list)
void list_free_deep(List *list)
List * list_delete_last(List *list)
LogicalTape * LogicalTapeCreate(LogicalTapeSet *lts)
void LogicalTapeRewindForRead(LogicalTape *lt, size_t buffer_size)
size_t LogicalTapeRead(LogicalTape *lt, void *ptr, size_t size)
int64 LogicalTapeSetBlocks(LogicalTapeSet *lts)
void LogicalTapeClose(LogicalTape *lt)
void LogicalTapeSetClose(LogicalTapeSet *lts)
void LogicalTapeWrite(LogicalTape *lt, const void *ptr, size_t size)
LogicalTapeSet * LogicalTapeSetCreate(bool preallocate, SharedFileSet *fileset, int worker)
void get_typlenbyval(Oid typid, int16 *typlen, bool *typbyval)
RegProcedure get_opcode(Oid opno)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
char * get_func_name(Oid funcid)
void MemoryContextReset(MemoryContext context)
void pfree(void *pointer)
void * palloc0(Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
Size MemoryContextMemAllocated(MemoryContext context, bool recurse)
void MemoryContextDelete(MemoryContext context)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define CHECK_FOR_INTERRUPTS()
static void hashagg_finish_initial_spills(AggState *aggstate)
static long hash_choose_num_buckets(double hashentrysize, long ngroups, Size memory)
static void hash_agg_check_limits(AggState *aggstate)
static void initialize_hash_entry(AggState *aggstate, TupleHashTable hashtable, TupleHashEntry entry)
static void find_hash_columns(AggState *aggstate)
static bool agg_refill_hash_table(AggState *aggstate)
static void build_hash_table(AggState *aggstate, int setno, long nbuckets)
void ExecAggEstimate(AggState *node, ParallelContext *pcxt)
struct FindColsContext FindColsContext
static void hash_agg_enter_spill_mode(AggState *aggstate)
struct HashAggBatch HashAggBatch
static Datum GetAggInitVal(Datum textInitVal, Oid transtype)
static void find_cols(AggState *aggstate, Bitmapset **aggregated, Bitmapset **unaggregated)
void AggRegisterCallback(FunctionCallInfo fcinfo, ExprContextCallbackFunction func, Datum arg)
#define HASHAGG_HLL_BIT_WIDTH
static void agg_fill_hash_table(AggState *aggstate)
static void initialize_aggregate(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate)
static TupleTableSlot * fetch_input_tuple(AggState *aggstate)
static void hashagg_spill_finish(AggState *aggstate, HashAggSpill *spill, int setno)
static bool find_cols_walker(Node *node, FindColsContext *context)
void ExecAggInitializeWorker(AggState *node, ParallelWorkerContext *pwcxt)
AggState * ExecInitAgg(Agg *node, EState *estate, int eflags)
void ExecAggRetrieveInstrumentation(AggState *node)
static TupleTableSlot * ExecAgg(PlanState *pstate)
static TupleTableSlot * project_aggregates(AggState *aggstate)
static MinimalTuple hashagg_batch_read(HashAggBatch *batch, uint32 *hashp)
struct HashAggSpill HashAggSpill
static void process_ordered_aggregate_multi(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate)
void ExecReScanAgg(AggState *node)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
static void advance_transition_function(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate)
static void hash_agg_update_metrics(AggState *aggstate, bool from_tape, int npartitions)
static void finalize_aggregates(AggState *aggstate, AggStatePerAgg peraggs, AggStatePerGroup pergroup)
static void initialize_phase(AggState *aggstate, int newphase)
Size hash_agg_entry_size(int numTrans, Size tupleWidth, Size transitionSpace)
static void initialize_aggregates(AggState *aggstate, AggStatePerGroup *pergroups, int numReset)
static TupleTableSlot * agg_retrieve_hash_table_in_memory(AggState *aggstate)
void ExecAggInitializeDSM(AggState *node, ParallelContext *pcxt)
static void finalize_aggregate(AggState *aggstate, AggStatePerAgg peragg, AggStatePerGroup pergroupstate, Datum *resultVal, bool *resultIsNull)
#define HASHAGG_MAX_PARTITIONS
static void lookup_hash_entries(AggState *aggstate)
static TupleTableSlot * agg_retrieve_direct(AggState *aggstate)
static void hashagg_recompile_expressions(AggState *aggstate, bool minslot, bool nullcheck)
static void prepare_projection_slot(AggState *aggstate, TupleTableSlot *slot, int currentSet)
bool AggStateIsShared(FunctionCallInfo fcinfo)
static void build_pertrans_for_aggref(AggStatePerTrans pertrans, AggState *aggstate, EState *estate, Aggref *aggref, Oid transfn_oid, Oid aggtranstype, Oid aggserialfn, Oid aggdeserialfn, Datum initValue, bool initValueIsNull, Oid *inputTypes, int numArguments)
Aggref * AggGetAggref(FunctionCallInfo fcinfo)
static TupleTableSlot * agg_retrieve_hash_table(AggState *aggstate)
static void process_ordered_aggregate_single(AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate)
static void advance_aggregates(AggState *aggstate)
static void prepare_hash_slot(AggStatePerHash perhash, TupleTableSlot *inputslot, TupleTableSlot *hashslot)
static void build_hash_tables(AggState *aggstate)
void ExecEndAgg(AggState *node)
#define HASHAGG_READ_BUFFER_SIZE
static void hashagg_reset_spill_state(AggState *aggstate)
static Size hashagg_spill_tuple(AggState *aggstate, HashAggSpill *spill, TupleTableSlot *inputslot, uint32 hash)
static void select_current_set(AggState *aggstate, int setno, bool is_hash)
static void finalize_partialaggregate(AggState *aggstate, AggStatePerAgg peragg, AggStatePerGroup pergroupstate, Datum *resultVal, bool *resultIsNull)
static void hashagg_spill_init(HashAggSpill *spill, LogicalTapeSet *tapeset, int used_bits, double input_groups, double hashentrysize)
#define HASHAGG_MIN_PARTITIONS
void hash_agg_set_limits(double hashentrysize, double input_groups, int used_bits, Size *mem_limit, uint64 *ngroups_limit, int *num_partitions)
MemoryContext AggGetTempMemoryContext(FunctionCallInfo fcinfo)
#define HASHAGG_PARTITION_FACTOR
static HashAggBatch * hashagg_batch_new(LogicalTape *input_tape, int setno, int64 input_tuples, double input_card, int used_bits)
#define HASHAGG_WRITE_BUFFER_SIZE
static int hash_choose_num_partitions(double input_groups, double hashentrysize, int used_bits, int *log2_npartitions)
struct AggStatePerGroupData AggStatePerGroupData
Oid exprCollation(const Node *expr)
#define expression_tree_walker(n, w, c)
size_t get_hash_memory_limit(void)
#define DO_AGGSPLIT_SKIPFINAL(as)
#define IsA(nodeptr, _type_)
#define DO_AGGSPLIT_DESERIALIZE(as)
#define DO_AGGSPLIT_COMBINE(as)
#define DO_AGGSPLIT_SERIALIZE(as)
#define castNode(_type_, nodeptr)
#define InvokeFunctionExecuteHook(objectId)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
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)
void build_aggregate_deserialfn_expr(Oid deserialfn_oid, Expr **deserialfnexpr)
void build_aggregate_transfn_expr(Oid *agg_input_types, int agg_num_inputs, int agg_num_direct_inputs, bool agg_variadic, Oid agg_state_type, Oid agg_input_collation, Oid transfn_oid, Oid invtransfn_oid, Expr **transfnexpr, Expr **invtransfnexpr)
int get_aggregate_argtypes(Aggref *aggref, Oid *inputTypes)
void build_aggregate_serialfn_expr(Oid serialfn_oid, Expr **serialfnexpr)
bool IsBinaryCoercible(Oid srctype, Oid targettype)
FormData_pg_aggregate * Form_pg_aggregate
FormData_pg_attribute * Form_pg_attribute
static int list_length(const List *l)
static void * list_nth(const List *list, int n)
#define list_nth_node(type, list, n)
FormData_pg_proc * Form_pg_proc
static bool DatumGetBool(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static unsigned hash(unsigned *uv, int n)
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
#define shm_toc_estimate_chunk(e, sz)
#define shm_toc_estimate_keys(e, cnt)
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
TupleTableSlot * hashslot
TupleHashIterator hashiter
AttrNumber * hashGrpColIdxHash
AttrNumber * hashGrpColIdxInput
Bitmapset ** grouped_cols
ExprState * evaltrans_cache[2][2]
TupleTableSlot * sortslot
Tuplesortstate ** sortstates
TupleTableSlot * uniqslot
FunctionCallInfo deserialfn_fcinfo
FunctionCallInfo serialfn_fcinfo
FunctionCallInfo transfn_fcinfo
MemoryContext hash_metacxt
Tuplesortstate * sort_out
AggStatePerGroup * all_pergroups
AggStatePerGroup * hash_pergroup
int hash_planned_partitions
ExprContext * curaggcontext
AggStatePerTrans curpertrans
AggStatePerTrans pertrans
struct LogicalTapeSet * hash_tapeset
ExprContext * hashcontext
SharedAggInfo * shared_info
uint64 hash_ngroups_limit
AggStatePerGroup * pergroups
uint64 hash_ngroups_current
TupleTableSlot * hash_spill_wslot
struct HashAggSpill * hash_spills
TupleTableSlot * sort_slot
TupleTableSlot * hash_spill_rslot
ExprContext ** aggcontexts
Bitmapset * colnos_needed
MemoryContext es_query_cxt
MemoryContext ecxt_per_tuple_memory
TupleTableSlot * ecxt_innertuple
TupleTableSlot * ecxt_outertuple
NullableDatum args[FLEXIBLE_ARRAY_MEMBER]
hyperLogLogState * hll_card
LogicalTape ** partitions
shm_toc_estimator estimator