PostgreSQL Source Code
git master
|
#include "postgres.h"
#include "access/htup_details.h"
#include "access/parallel.h"
#include "catalog/objectaccess.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_proc.h"
#include "catalog/pg_type.h"
#include "common/hashfn.h"
#include "executor/execExpr.h"
#include "executor/executor.h"
#include "executor/nodeAgg.h"
#include "lib/hyperloglog.h"
#include "miscadmin.h"
#include "nodes/nodeFuncs.h"
#include "optimizer/optimizer.h"
#include "parser/parse_agg.h"
#include "parser/parse_coerce.h"
#include "utils/acl.h"
#include "utils/builtins.h"
#include "utils/datum.h"
#include "utils/dynahash.h"
#include "utils/expandeddatum.h"
#include "utils/logtape.h"
#include "utils/lsyscache.h"
#include "utils/memutils.h"
#include "utils/syscache.h"
#include "utils/tuplesort.h"
Go to the source code of this file.
Data Structures | |
struct | HashAggSpill |
struct | HashAggBatch |
struct | FindColsContext |
Macros | |
#define | HASHAGG_PARTITION_FACTOR 1.50 |
#define | HASHAGG_MIN_PARTITIONS 4 |
#define | HASHAGG_MAX_PARTITIONS 1024 |
#define | HASHAGG_READ_BUFFER_SIZE BLCKSZ |
#define | HASHAGG_WRITE_BUFFER_SIZE BLCKSZ |
#define | HASHAGG_HLL_BIT_WIDTH 5 |
#define | CHUNKHDRSZ 16 |
Typedefs | |
typedef struct HashAggSpill | HashAggSpill |
typedef struct HashAggBatch | HashAggBatch |
typedef struct FindColsContext | FindColsContext |
Functions | |
static void | select_current_set (AggState *aggstate, int setno, bool is_hash) |
static void | initialize_phase (AggState *aggstate, int newphase) |
static TupleTableSlot * | fetch_input_tuple (AggState *aggstate) |
static void | initialize_aggregates (AggState *aggstate, AggStatePerGroup *pergroups, int numReset) |
static void | advance_transition_function (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate) |
static void | advance_aggregates (AggState *aggstate) |
static void | process_ordered_aggregate_single (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate) |
static void | process_ordered_aggregate_multi (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate) |
static void | finalize_aggregate (AggState *aggstate, AggStatePerAgg peragg, AggStatePerGroup pergroupstate, Datum *resultVal, bool *resultIsNull) |
static void | finalize_partialaggregate (AggState *aggstate, AggStatePerAgg peragg, AggStatePerGroup pergroupstate, Datum *resultVal, bool *resultIsNull) |
static void | prepare_hash_slot (AggStatePerHash perhash, TupleTableSlot *inputslot, TupleTableSlot *hashslot) |
static void | prepare_projection_slot (AggState *aggstate, TupleTableSlot *slot, int currentSet) |
static void | finalize_aggregates (AggState *aggstate, AggStatePerAgg peraggs, AggStatePerGroup pergroup) |
static TupleTableSlot * | project_aggregates (AggState *aggstate) |
static void | find_cols (AggState *aggstate, Bitmapset **aggregated, Bitmapset **unaggregated) |
static bool | find_cols_walker (Node *node, FindColsContext *context) |
static void | build_hash_tables (AggState *aggstate) |
static void | build_hash_table (AggState *aggstate, int setno, long nbuckets) |
static void | hashagg_recompile_expressions (AggState *aggstate, bool minslot, bool nullcheck) |
static long | hash_choose_num_buckets (double hashentrysize, long ngroups, Size memory) |
static int | hash_choose_num_partitions (double input_groups, double hashentrysize, int used_bits, int *log2_npartitions) |
static void | initialize_hash_entry (AggState *aggstate, TupleHashTable hashtable, TupleHashEntry entry) |
static void | lookup_hash_entries (AggState *aggstate) |
static TupleTableSlot * | agg_retrieve_direct (AggState *aggstate) |
static void | agg_fill_hash_table (AggState *aggstate) |
static bool | agg_refill_hash_table (AggState *aggstate) |
static TupleTableSlot * | agg_retrieve_hash_table (AggState *aggstate) |
static TupleTableSlot * | agg_retrieve_hash_table_in_memory (AggState *aggstate) |
static void | hash_agg_check_limits (AggState *aggstate) |
static void | hash_agg_enter_spill_mode (AggState *aggstate) |
static void | hash_agg_update_metrics (AggState *aggstate, bool from_tape, int npartitions) |
static void | hashagg_finish_initial_spills (AggState *aggstate) |
static void | hashagg_reset_spill_state (AggState *aggstate) |
static HashAggBatch * | hashagg_batch_new (LogicalTape *input_tape, int setno, int64 input_tuples, double input_card, int used_bits) |
static MinimalTuple | hashagg_batch_read (HashAggBatch *batch, uint32 *hashp) |
static void | hashagg_spill_init (HashAggSpill *spill, LogicalTapeSet *tapeset, int used_bits, double input_groups, double hashentrysize) |
static Size | hashagg_spill_tuple (AggState *aggstate, HashAggSpill *spill, TupleTableSlot *inputslot, uint32 hash) |
static void | hashagg_spill_finish (AggState *aggstate, HashAggSpill *spill, int setno) |
static Datum | GetAggInitVal (Datum textInitVal, Oid transtype) |
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) |
static void | initialize_aggregate (AggState *aggstate, AggStatePerTrans pertrans, AggStatePerGroup pergroupstate) |
static void | find_hash_columns (AggState *aggstate) |
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) |
static TupleTableSlot * | ExecAgg (PlanState *pstate) |
AggState * | ExecInitAgg (Agg *node, EState *estate, int eflags) |
void | ExecEndAgg (AggState *node) |
void | ExecReScanAgg (AggState *node) |
int | AggCheckCallContext (FunctionCallInfo fcinfo, MemoryContext *aggcontext) |
Aggref * | AggGetAggref (FunctionCallInfo fcinfo) |
MemoryContext | AggGetTempMemoryContext (FunctionCallInfo fcinfo) |
bool | AggStateIsShared (FunctionCallInfo fcinfo) |
void | AggRegisterCallback (FunctionCallInfo fcinfo, ExprContextCallbackFunction func, Datum arg) |
void | ExecAggEstimate (AggState *node, ParallelContext *pcxt) |
void | ExecAggInitializeDSM (AggState *node, ParallelContext *pcxt) |
void | ExecAggInitializeWorker (AggState *node, ParallelWorkerContext *pwcxt) |
void | ExecAggRetrieveInstrumentation (AggState *node) |
typedef struct FindColsContext FindColsContext |
typedef struct HashAggBatch HashAggBatch |
typedef struct HashAggSpill HashAggSpill |
|
static |
Definition at line 816 of file nodeAgg.c.
References AggStatePerPhaseData::evaltrans, ExecEvalExprSwitchContext(), AggState::phase, and AggState::tmpcontext.
Referenced by agg_fill_hash_table(), agg_refill_hash_table(), and agg_retrieve_direct().
|
static |
Definition at line 706 of file nodeAgg.c.
References FunctionCallInfoBaseData::args, AggState::curaggcontext, AggState::curpertrans, datumCopy(), DatumGetPointer(), ExprContext::ecxt_per_tuple_memory, ExecAggCopyTransValue(), FmgrInfo::fn_strict, FunctionCallInvoke, i, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MemoryContextSwitchTo(), AggStatePerGroupData::noTransValue, AggStatePerTransData::numTransInputs, AggState::tmpcontext, AggStatePerTransData::transfn, AggStatePerTransData::transfn_fcinfo, AggStatePerTransData::transtypeByVal, AggStatePerTransData::transtypeLen, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, and NullableDatum::value.
Referenced by process_ordered_aggregate_multi(), and process_ordered_aggregate_single().
|
static |
Definition at line 2540 of file nodeAgg.c.
References advance_aggregates(), ExprContext::ecxt_outertuple, fetch_input_tuple(), hashagg_finish_initial_spills(), AggStatePerHashData::hashiter, AggStatePerHashData::hashtable, lookup_hash_entries(), AggState::perhash, ResetExprContext, ResetTupleHashIterator, select_current_set(), AggState::table_filled, AggState::tmpcontext, and TupIsNull.
Referenced by ExecAgg().
Definition at line 2594 of file nodeAgg.c.
References TupleHashEntryData::additional, advance_aggregates(), AGG_MIXED, AggStatePerPhaseData::aggstrategy, Assert, CHECK_FOR_INTERRUPTS, AggState::current_phase, AggState::current_set, ExprContext::ecxt_outertuple, ExecStoreMinimalTuple(), hash(), hash_agg_set_limits(), hash_agg_update_metrics(), AggState::hash_batches, AggState::hash_mem_limit, AggState::hash_ngroups_current, AggState::hash_ngroups_limit, AggState::hash_pergroup, AggState::hash_spill_mode, AggState::hash_spill_rslot, AggState::hash_tapeset, hashagg_batch_read(), hashagg_recompile_expressions(), hashagg_spill_finish(), hashagg_spill_init(), hashagg_spill_tuple(), AggState::hashcontext, AggState::hashentrysize, AggStatePerHashData::hashiter, AggStatePerHashData::hashslot, AggStatePerHashData::hashtable, initialize_hash_entry(), HashAggBatch::input_card, HashAggBatch::input_tape, list_delete_last(), llast, LogicalTapeClose(), LookupTupleHashEntryHash(), MemSet, NIL, HashAggSpill::npartitions, AggState::num_hashes, AggState::perhash, pfree(), AggState::phase, AggState::phases, prepare_hash_slot(), ReScanExprContext(), ResetExprContext, ResetTupleHashIterator, ResetTupleHashTable(), select_current_set(), HashAggBatch::setno, AggState::tmpcontext, and HashAggBatch::used_bits.
Referenced by agg_retrieve_hash_table().
|
static |
Definition at line 2194 of file nodeAgg.c.
References advance_aggregates(), AggState::agg_done, AGG_MIXED, AGG_PLAIN, agg_retrieve_hash_table(), AggState::aggcontexts, AggStatePerPhaseData::aggnode, AggState::aggstrategy, Agg::aggstrategy, Assert, AggState::current_phase, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, AggStatePerPhaseData::eqfunctions, ExecCopySlotHeapTuple(), ExecForceStoreHeapTuple(), ExecQual(), ExecQualAndReset(), fetch_input_tuple(), finalize_aggregates(), AggState::grp_firstTuple, AggStatePerPhaseData::gset_lengths, hashagg_finish_initial_spills(), AggStatePerHashData::hashiter, AggStatePerHashData::hashtable, i, initialize_aggregates(), initialize_phase(), AggState::input_done, lookup_hash_entries(), Max, Agg::numCols, AggState::numphases, AggStatePerPhaseData::numsets, AggState::peragg, AggState::pergroups, AggState::perhash, AggState::phase, prepare_projection_slot(), project_aggregates(), AggState::projected_set, ScanState::ps, PlanState::ps_ExprContext, ReScanExprContext(), ResetExprContext, ResetTupleHashIterator, select_current_set(), AggState::ss, ScanState::ss_ScanTupleSlot, AggState::table_filled, AggState::tmpcontext, and TupIsNull.
Referenced by ExecAgg().
|
static |
Definition at line 2746 of file nodeAgg.c.
References AggState::agg_done, agg_refill_hash_table(), and agg_retrieve_hash_table_in_memory().
Referenced by agg_retrieve_direct(), and ExecAgg().
|
static |
Definition at line 2771 of file nodeAgg.c.
References TupleHashEntryData::additional, CHECK_FOR_INTERRUPTS, AggState::current_set, ExprContext::ecxt_outertuple, ExecClearTuple(), ExecStoreMinimalTuple(), ExecStoreVirtualTuple(), finalize_aggregates(), TupleHashEntryData::firstTuple, AggStatePerHashData::hashGrpColIdxInput, AggStatePerHashData::hashiter, AggStatePerHashData::hashslot, AggStatePerHashData::hashtable, i, TupleDescData::natts, AggStatePerHashData::numhashGrpCols, AggState::peragg, AggState::perhash, prepare_projection_slot(), project_aggregates(), ScanState::ps, PlanState::ps_ExprContext, ResetExprContext, ResetTupleHashIterator, ScanTupleHashTable, select_current_set(), slot_getallattrs(), AggState::ss, ScanState::ss_ScanTupleSlot, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.
Referenced by agg_retrieve_hash_table().
int AggCheckCallContext | ( | FunctionCallInfo | fcinfo, |
MemoryContext * | aggcontext | ||
) |
Definition at line 4511 of file nodeAgg.c.
References AGG_CONTEXT_AGGREGATE, AGG_CONTEXT_WINDOW, FunctionCallInfoBaseData::context, AggState::curaggcontext, ExprContext::ecxt_per_tuple_memory, and IsA.
Referenced by array_agg_array_combine(), array_agg_array_deserialize(), array_agg_array_finalfn(), array_agg_array_serialize(), array_agg_array_transfn(), array_agg_combine(), array_agg_deserialize(), array_agg_finalfn(), array_agg_serialize(), array_agg_transfn(), bytea_string_agg_finalfn(), fetch_array_arg_replace_nulls(), float4_accum(), float8_accum(), float8_combine(), float8_regr_accum(), float8_regr_combine(), hypothetical_dense_rank_final(), hypothetical_rank_common(), int2_avg_accum(), int2_avg_accum_inv(), int2_sum(), int4_avg_accum(), int4_avg_accum_inv(), int4_avg_combine(), int4_sum(), int8_avg_combine(), int8_avg_deserialize(), int8_avg_serialize(), int8dec(), int8inc(), interval_avg_deserialize(), interval_avg_serialize(), json_agg_finalfn(), json_agg_transfn_worker(), json_object_agg_finalfn(), json_object_agg_transfn_worker(), jsonb_agg_finalfn(), jsonb_agg_transfn_worker(), jsonb_object_agg_finalfn(), jsonb_object_agg_transfn_worker(), makeBoolAggState(), makeIntervalAggState(), makeNumericAggState(), makeStringAggState(), mode_final(), multirange_agg_transfn(), multirange_intersect_agg_transfn(), numeric_avg_combine(), numeric_avg_deserialize(), numeric_avg_serialize(), numeric_combine(), numeric_deserialize(), numeric_poly_combine(), numeric_poly_deserialize(), numeric_poly_serialize(), numeric_serialize(), ordered_set_startup(), percentile_cont_final_common(), percentile_cont_multi_final_common(), percentile_disc_final(), percentile_disc_multi_final(), range_agg_finalfn(), range_agg_transfn(), range_intersect_agg_transfn(), string_agg_combine(), string_agg_deserialize(), string_agg_finalfn(), and string_agg_serialize().
Aggref* AggGetAggref | ( | FunctionCallInfo | fcinfo | ) |
Definition at line 4555 of file nodeAgg.c.
References AggStatePerTransData::aggref, FunctionCallInfoBaseData::context, AggState::curperagg, AggState::curpertrans, if(), and IsA.
Referenced by ordered_set_startup().
MemoryContext AggGetTempMemoryContext | ( | FunctionCallInfo | fcinfo | ) |
Definition at line 4589 of file nodeAgg.c.
References FunctionCallInfoBaseData::context, ExprContext::ecxt_per_tuple_memory, IsA, and AggState::tmpcontext.
void AggRegisterCallback | ( | FunctionCallInfo | fcinfo, |
ExprContextCallbackFunction | func, | ||
Datum | arg | ||
) |
Definition at line 4654 of file nodeAgg.c.
References arg, FunctionCallInfoBaseData::context, AggState::curaggcontext, elog, ERROR, IsA, and RegisterExprContextCallback().
Referenced by ordered_set_startup().
bool AggStateIsShared | ( | FunctionCallInfo | fcinfo | ) |
Definition at line 4615 of file nodeAgg.c.
References AggStatePerTransData::aggshared, FunctionCallInfoBaseData::context, AggState::curperagg, AggState::curpertrans, if(), IsA, and AggState::pertrans.
Referenced by ordered_set_startup().
|
static |
Definition at line 1503 of file nodeAgg.c.
References AGG_HASHED, AGG_MIXED, AggStatePerHashData::aggnode, AggState::aggsplit, AggState::aggstrategy, Assert, BuildTupleHashTableExt(), DO_AGGSPLIT_SKIPFINAL, ExprContext::ecxt_per_tuple_memory, AggStatePerHashData::eqfuncoids, AggState::hash_metacxt, AggState::hashcontext, AggStatePerHashData::hashfunctions, AggStatePerHashData::hashGrpColIdxHash, AggStatePerHashData::hashslot, AggStatePerHashData::hashtable, AggStatePerHashData::numCols, AggState::numtrans, AggState::perhash, ScanState::ps, AggState::ss, AggState::tmpcontext, and TupleTableSlot::tts_tupleDescriptor.
Referenced by build_hash_tables().
|
static |
Definition at line 1468 of file nodeAgg.c.
References AggStatePerHashData::aggnode, Assert, build_hash_table(), hash_choose_num_buckets(), AggState::hash_mem_limit, AggState::hash_ngroups_current, AggState::hashentrysize, AggStatePerHashData::hashtable, AggState::num_hashes, Agg::numGroups, AggState::perhash, and ResetTupleHashTable().
Referenced by ExecInitAgg(), and ExecReScanAgg().
|
static |
Definition at line 4038 of file nodeAgg.c.
References AGG_HASHED, AGG_MIXED, AggStatePerTransData::aggCollation, Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, Aggref::aggorder, AggStatePerTransData::aggref, AggStatePerTransData::aggshared, AggStatePerTransData::aggsortrequired, AggState::aggsplit, AggState::aggstrategy, AggStatePerTransData::aggtranstype, Aggref::args, Assert, build_aggregate_deserialfn_expr(), build_aggregate_serialfn_expr(), build_aggregate_transfn_expr(), AggStatePerTransData::deserialfn, AggStatePerTransData::deserialfn_fcinfo, AggStatePerTransData::deserialfn_oid, DO_AGGSPLIT_COMBINE, AggStatePerTransData::equalfnMulti, AggStatePerTransData::equalfnOne, ExecInitExtraTupleSlot(), execTuplesMatchPrepare(), ExecTypeFromTL(), TargetEntry::expr, exprCollation(), fmgr_info(), fmgr_info_set_expr, get_opcode(), get_sortgroupclause_tle(), get_typlenbyval(), i, InitFunctionCallInfoData, AggStatePerTransData::initValue, initValue(), AggStatePerTransData::initValueIsNull, AggStatePerTransData::inputtypeByVal, AggStatePerTransData::inputtypeLen, InvalidOid, lfirst, list_length(), Max, AggState::maxsets, NIL, SortGroupClause::nulls_first, AggStatePerTransData::numDistinctCols, AggStatePerTransData::numInputs, AggStatePerTransData::numSortCols, AggStatePerTransData::numTransInputs, OidIsValid, palloc(), palloc0(), pfree(), ScanState::ps, TargetEntry::resno, AggStatePerTransData::serialfn, AggStatePerTransData::serialfn_fcinfo, AggStatePerTransData::serialfn_oid, SizeForFunctionCallInfo, AggStatePerTransData::sortColIdx, AggStatePerTransData::sortCollations, AggStatePerTransData::sortdesc, AggStatePerTransData::sortNullsFirst, SortGroupClause::sortop, AggStatePerTransData::sortOperators, AggStatePerTransData::sortslot, AggStatePerTransData::sortstates, AggState::ss, AggStatePerTransData::transfn, AggStatePerTransData::transfn_fcinfo, AggStatePerTransData::transfn_oid, AggStatePerTransData::transtypeByVal, AggStatePerTransData::transtypeLen, TTSOpsMinimalTuple, and AggStatePerTransData::uniqslot.
Referenced by ExecInitAgg().
|
static |
Definition at line 2158 of file nodeAgg.c.
References AggState::agg_done, agg_fill_hash_table(), AGG_HASHED, AGG_MIXED, AGG_PLAIN, agg_retrieve_direct(), agg_retrieve_hash_table(), AGG_SORTED, AggStatePerPhaseData::aggstrategy, castNode, CHECK_FOR_INTERRUPTS, AggState::phase, AggState::table_filled, and TupIsNull.
Referenced by ExecInitAgg().
void ExecAggEstimate | ( | AggState * | node, |
ParallelContext * | pcxt | ||
) |
Definition at line 4683 of file nodeAgg.c.
References add_size(), ParallelContext::estimator, PlanState::instrument, mul_size(), ParallelContext::nworkers, ScanState::ps, shm_toc_estimate_chunk, shm_toc_estimate_keys, size, and AggState::ss.
Referenced by ExecParallelEstimate().
void ExecAggInitializeDSM | ( | AggState * | node, |
ParallelContext * | pcxt | ||
) |
Definition at line 4704 of file nodeAgg.c.
References PlanState::instrument, SharedAggInfo::num_workers, ParallelContext::nworkers, PlanState::plan, Plan::plan_node_id, ScanState::ps, AggState::shared_info, shm_toc_allocate(), shm_toc_insert(), size, AggState::ss, and ParallelContext::toc.
Referenced by ExecParallelInitializeDSM().
void ExecAggInitializeWorker | ( | AggState * | node, |
ParallelWorkerContext * | pwcxt | ||
) |
Definition at line 4729 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().
void ExecAggRetrieveInstrumentation | ( | AggState * | node | ) |
Definition at line 4742 of file nodeAgg.c.
References SharedAggInfo::num_workers, palloc(), AggState::shared_info, and size.
Referenced by ExecParallelRetrieveInstrumentation().
void ExecEndAgg | ( | AggState * | node | ) |
Definition at line 4304 of file nodeAgg.c.
References AggState::aggcontexts, Assert, ExecEndNode(), 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, ReScanExprContext(), AggState::shared_info, SharedAggInfo::sinstrument, AggState::sort_in, AggState::sort_out, AggStatePerTransData::sortstates, and tuplesort_end().
Referenced by ExecEndNode().
Definition at line 3173 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, Aggref::aggfnoid, AggStatePerPhaseData::aggnode, AggStatePerHashData::aggnode, AggStatePerTransData::aggref, AggStatePerAggData::aggref, AggState::aggs, AggStatePerTransData::aggshared, AggState::aggsplit, Agg::aggsplit, AggStatePerPhaseData::aggstrategy, AggState::aggstrategy, Agg::aggstrategy, AggState::all_grouped_cols, AggState::all_pergroups, ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Aggref::args, 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_phase, 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, FmgrInfo::fn_strict, format_type_be(), FUNC_MAX_ARGS, get_aggregate_argtypes(), get_func_name(), get_typlenbyval(), GetAggInitVal(), GETSTRUCT, GetUserId(), AggStatePerPhaseData::grouped_cols, Agg::groupingSets, AggState::grp_firstTuple, AggStatePerPhaseData::gset_lengths, hash_agg_entry_size(), hash_agg_set_limits(), AggState::hash_batches_used, AggState::hash_mem_limit, AggState::hash_metacxt, AggState::hash_ngroups_limit, AggState::hash_pergroup, AggState::hash_planned_partitions, AggState::hash_spill_rslot, AggState::hash_spill_wslot, AggState::hashcontext, AggState::hashentrysize, HeapTupleIsValid, i, initialize_phase(), initValue(), AggStatePerTransData::initValueIsNull, AggState::input_done, InvalidOid, InvokeFunctionExecuteHook, IsBinaryCoercible(), j, lcons_int(), lfirst, list_length(), list_nth_node, makeNode, Max, AggState::maxsets, NIL, AggState::num_hashes, AggState::numaggs, AggStatePerHashData::numCols, Agg::numCols, AggStatePerAggData::numFinalArgs, Agg::numGroups, AggState::numphases, AggStatePerPhaseData::numsets, AggState::numtrans, AggStatePerTransData::numTransInputs, object_aclcheck(), OBJECT_AGGREGATE, OBJECT_FUNCTION, ObjectIdGetDatum(), OidIsValid, PlanState::outerops, PlanState::outeropsfixed, PlanState::outeropsset, outerPlan, outerPlanState, palloc(), palloc0(), AggState::peragg, AggState::pergroups, AggState::perhash, AggState::pertrans, AggState::phases, PlanState::plan, Agg::plan, Plan::plan_width, AggState::projected_set, ScanState::ps, PlanState::ps_ExprContext, PlanState::qual, Plan::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::table_filled, AggState::tmpcontext, AggStatePerTransData::transfn, Agg::transitionSpace, AggStatePerAggData::transno, TupleTableSlot::tts_tupleDescriptor, TTSOpsMinimalTuple, and TTSOpsVirtual.
Referenced by ExecInitNode().
void ExecReScanAgg | ( | AggState * | node | ) |
Definition at line 4364 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().
|
static |
Definition at line 547 of file nodeAgg.c.
References CHECK_FOR_INTERRUPTS, ExecProcNode(), outerPlanState, AggState::sort_in, AggState::sort_out, AggState::sort_slot, TupIsNull, tuplesort_gettupleslot(), and tuplesort_puttupleslot().
Referenced by agg_fill_hash_table(), and agg_retrieve_direct().
|
static |
Definition at line 1046 of file nodeAgg.c.
References AggStatePerTransData::aggCollation, AggStatePerAggData::aggdirectargs, AggState::curperagg, ExprContext::ecxt_per_tuple_memory, ExecEvalExpr(), AggStatePerAggData::finalfn, AggStatePerAggData::finalfn_oid, FUNC_MAX_ARGS, FunctionCallInvoke, i, InitFunctionCallInfoData, lfirst, LOCAL_FCINFO, MakeExpandedObjectReadOnly, MemoryContextSwitchTo(), AggStatePerAggData::numFinalArgs, OidIsValid, AggState::pertrans, ScanState::ps, PlanState::ps_ExprContext, AggStatePerAggData::resulttypeLen, AggState::ss, AggStatePerAggData::transno, AggStatePerTransData::transtypeLen, AggStatePerGroupData::transValue, and AggStatePerGroupData::transValueIsNull.
Referenced by finalize_aggregates().
|
static |
Definition at line 1294 of file nodeAgg.c.
References AGG_HASHED, AGG_MIXED, AggStatePerTransData::aggsortrequired, AggState::aggsplit, AggState::aggstrategy, Assert, DatumGetPointer(), DO_AGGSPLIT_SKIPFINAL, ExprContext::ecxt_aggnulls, ExprContext::ecxt_aggvalues, ExecClearTuple(), finalize_aggregate(), finalize_partialaggregate(), AggStatePerTransData::haslast, AggStatePerTransData::inputtypeByVal, AggStatePerTransData::lastdatum, AggStatePerTransData::lastisnull, AggState::numaggs, AggStatePerTransData::numDistinctCols, AggStatePerTransData::numInputs, AggState::numtrans, AggState::pertrans, pfree(), process_ordered_aggregate_multi(), process_ordered_aggregate_single(), ScanState::ps, PlanState::ps_ExprContext, AggState::ss, AggStatePerAggData::transno, and AggStatePerTransData::uniqslot.
Referenced by agg_retrieve_direct(), and agg_retrieve_hash_table_in_memory().
|
static |
Definition at line 1146 of file nodeAgg.c.
References FunctionCallInfoBaseData::args, ExprContext::ecxt_per_tuple_memory, FmgrInfo::fn_strict, FunctionCallInvoke, FunctionCallInfoBaseData::isnull, NullableDatum::isnull, MakeExpandedObjectReadOnly, MemoryContextSwitchTo(), OidIsValid, AggState::pertrans, ScanState::ps, PlanState::ps_ExprContext, AggStatePerAggData::resulttypeLen, AggStatePerTransData::serialfn, AggStatePerTransData::serialfn_fcinfo, AggStatePerTransData::serialfn_oid, AggState::ss, AggStatePerAggData::transno, AggStatePerTransData::transtypeLen, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, and NullableDatum::value.
Referenced by finalize_aggregates().
|
static |
Definition at line 1397 of file nodeAgg.c.
References bms_add_member(), context, find_cols_walker(), i, Agg::numCols, PlanState::plan, Agg::plan, ScanState::ps, Plan::qual, AggState::ss, and Plan::targetlist.
Referenced by find_hash_columns().
|
static |
Definition at line 1420 of file nodeAgg.c.
References Assert, bms_add_member(), context, expression_tree_walker, IsA, OUTER_VAR, Var::varattno, Var::varlevelsup, and Var::varno.
Referenced by find_cols().
|
static |
Definition at line 1563 of file nodeAgg.c.
References AggStatePerHashData::aggnode, AggState::all_cols_needed, AggState::all_grouped_cols, attnum, bms_add_member(), bms_copy(), bms_del_member(), bms_free(), bms_is_member(), bms_next_member(), bms_num_members(), bms_union(), AggState::colnos_needed, AggStatePerHashData::eqfuncoids, EState::es_tupleTable, ExecAllocTableSlot(), execTuplesHashPrepare(), ExecTypeFromTL(), find_cols(), AggStatePerPhaseData::grouped_cols, AggStatePerHashData::hashfunctions, AggStatePerHashData::hashGrpColIdxHash, AggStatePerHashData::hashGrpColIdxInput, AggStatePerHashData::hashslot, i, j, lappend(), AggStatePerHashData::largestGrpColIdx, lfirst_int, list_free(), list_nth(), Max, AggState::max_colno_needed, TupleDescData::natts, NIL, AggState::num_hashes, AggStatePerHashData::numCols, AggStatePerHashData::numhashGrpCols, outerPlanState, palloc(), AggState::perhash, AggState::phases, ScanState::ps, AggState::ss, ScanState::ss_ScanTupleSlot, PlanState::state, TupleTableSlot::tts_tupleDescriptor, and TTSOpsMinimalTuple.
Referenced by ExecInitAgg().
Definition at line 4288 of file nodeAgg.c.
References getTypeInputInfo(), OidInputFunctionCall(), pfree(), and TextDatumGetCString.
Referenced by ExecInitAgg().
|
static |
Definition at line 1856 of file nodeAgg.c.
References ExprContext::ecxt_per_tuple_memory, hash_agg_enter_spill_mode(), AggState::hash_mem_limit, AggState::hash_metacxt, AggState::hash_ngroups_current, AggState::hash_ngroups_limit, AggState::hashcontext, and MemoryContextMemAllocated().
Referenced by initialize_hash_entry().
|
static |
Definition at line 1882 of file nodeAgg.c.
References AggStatePerHashData::aggnode, Assert, AggState::hash_ever_spilled, AggState::hash_spill_mode, AggState::hash_spills, AggState::hash_tapeset, hashagg_recompile_expressions(), hashagg_spill_init(), AggState::hashentrysize, LogicalTapeSetCreate(), AggState::num_hashes, Agg::numGroups, palloc(), AggState::perhash, and AggState::table_filled.
Referenced by hash_agg_check_limits().
Definition at line 1694 of file nodeAgg.c.
References CHUNKHDRSZ, MAXALIGN, and SizeofMinimalTupleHeader.
Referenced by cost_agg(), estimate_hashagg_tablesize(), and ExecInitAgg().
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_memory_limit(), hash_choose_num_partitions(), HASHAGG_READ_BUFFER_SIZE, and HASHAGG_WRITE_BUFFER_SIZE.
Referenced by agg_refill_hash_table(), cost_agg(), and ExecInitAgg().
Definition at line 1917 of file nodeAgg.c.
References AGG_HASHED, AGG_MIXED, AggState::aggstrategy, ExprContext::ecxt_per_tuple_memory, AggState::hash_disk_used, AggState::hash_mem_peak, AggState::hash_metacxt, AggState::hash_ngroups_current, AggState::hash_tapeset, HASHAGG_READ_BUFFER_SIZE, HASHAGG_WRITE_BUFFER_SIZE, AggState::hashcontext, AggState::hashentrysize, LogicalTapeSetBlocks(), and MemoryContextMemAllocated().
Referenced by agg_refill_hash_table(), and hashagg_finish_initial_spills().
|
static |
|
static |
Definition at line 1991 of file nodeAgg.c.
References get_hash_memory_limit(), HASHAGG_MAX_PARTITIONS, HASHAGG_MIN_PARTITIONS, HASHAGG_PARTITION_FACTOR, HASHAGG_READ_BUFFER_SIZE, HASHAGG_WRITE_BUFFER_SIZE, and my_log2().
Referenced by hash_agg_set_limits(), and hashagg_spill_init().
|
static |
Definition at line 2991 of file nodeAgg.c.
References HashAggBatch::input_card, HashAggBatch::input_tape, HashAggBatch::input_tuples, palloc0(), HashAggBatch::setno, and HashAggBatch::used_bits.
Referenced by hashagg_spill_finish().
|
static |
Definition at line 3010 of file nodeAgg.c.
References ereport, errcode_for_file_access(), errmsg_internal(), ERROR, hash(), HashAggBatch::input_tape, LogicalTapeRead(), palloc(), and MinimalTupleData::t_len.
Referenced by agg_refill_hash_table().
|
static |
Definition at line 3059 of file nodeAgg.c.
References hash_agg_update_metrics(), AggState::hash_spill_mode, AggState::hash_spills, hashagg_spill_finish(), HashAggSpill::npartitions, AggState::num_hashes, and pfree().
Referenced by agg_fill_hash_table(), and agg_retrieve_direct().
|
static |
Definition at line 1741 of file nodeAgg.c.
References AGG_HASHED, AGG_MIXED, AggState::aggstrategy, Assert, AggStatePerPhaseData::evaltrans, AggStatePerPhaseData::evaltrans_cache, ExecBuildAggTrans(), i, j, PlanState::outerops, PlanState::outeropsfixed, AggState::phases, ScanState::ps, AggState::ss, and TTSOpsMinimalTuple.
Referenced by agg_refill_hash_table(), ExecReScanAgg(), and hash_agg_enter_spill_mode().
|
static |
Definition at line 3133 of file nodeAgg.c.
References AggState::hash_batches, AggState::hash_spills, AggState::hash_tapeset, list_free_deep(), LogicalTapeSetClose(), NIL, HashAggSpill::ntuples, AggState::num_hashes, HashAggSpill::partitions, and pfree().
Referenced by ExecEndAgg(), and ExecReScanAgg().
|
static |
Definition at line 3093 of file nodeAgg.c.
References estimateHyperLogLog(), freeHyperLogLog(), AggState::hash_batches, AggState::hash_batches_used, hashagg_batch_new(), HASHAGG_READ_BUFFER_SIZE, HashAggSpill::hll_card, i, lappend(), LogicalTapeRewindForRead(), HashAggSpill::npartitions, HashAggSpill::ntuples, HashAggSpill::partitions, pfree(), and HashAggSpill::shift.
Referenced by agg_refill_hash_table(), and hashagg_finish_initial_spills().
|
static |
Definition at line 2894 of file nodeAgg.c.
References for(), hash_choose_num_partitions(), HASHAGG_HLL_BIT_WIDTH, HashAggSpill::hll_card, i, initHyperLogLog(), LogicalTapeCreate(), HashAggSpill::mask, HashAggSpill::npartitions, HashAggSpill::ntuples, palloc0(), HashAggSpill::partitions, and HashAggSpill::shift.
Referenced by agg_refill_hash_table(), hash_agg_enter_spill_mode(), and lookup_hash_entries().
|
static |
Definition at line 2925 of file nodeAgg.c.
References addHyperLogLog(), AggState::all_cols_needed, Assert, bms_is_member(), AggState::colnos_needed, ExecClearTuple(), ExecFetchSlotMinimalTuple(), ExecStoreVirtualTuple(), hash(), hash_bytes_uint32(), AggState::hash_spill_wslot, HashAggSpill::hll_card, i, LogicalTapeWrite(), HashAggSpill::mask, AggState::max_colno_needed, TupleDescData::natts, HashAggSpill::ntuples, HashAggSpill::partitions, pfree(), HashAggSpill::shift, slot_getsomeattrs(), MinimalTupleData::t_len, TupleTableSlot::tts_isnull, TupleTableSlot::tts_tupleDescriptor, and TupleTableSlot::tts_values.
Referenced by agg_refill_hash_table(), and lookup_hash_entries().
|
static |
Definition at line 578 of file nodeAgg.c.
References AggStatePerTransData::aggsortrequired, AggState::curaggcontext, AggState::current_set, datumCopy(), ExprContext::ecxt_per_tuple_memory, AggStatePerTransData::initValue, AggStatePerTransData::initValueIsNull, MemoryContextSwitchTo(), AggStatePerGroupData::noTransValue, AggStatePerTransData::numInputs, AggStatePerTransData::numSortCols, AggStatePerTransData::sortColIdx, AggStatePerTransData::sortCollations, AggStatePerTransData::sortdesc, AggStatePerTransData::sortNullsFirst, AggStatePerTransData::sortOperators, AggStatePerTransData::sortstates, AggStatePerTransData::transtypeByVal, AggStatePerTransData::transtypeLen, AggStatePerGroupData::transValue, AggStatePerGroupData::transValueIsNull, TupleDescAttr, tuplesort_begin_datum(), tuplesort_begin_heap(), tuplesort_end(), TUPLESORT_NONE, and work_mem.
Referenced by initialize_aggregates(), and initialize_hash_entry().
|
static |
Definition at line 665 of file nodeAgg.c.
References initialize_aggregate(), Max, AggStatePerPhaseData::numsets, AggState::numtrans, AggState::pertrans, AggState::phase, and select_current_set().
Referenced by agg_retrieve_direct().
|
static |
Definition at line 2045 of file nodeAgg.c.
References TupleHashEntryData::additional, hash_agg_check_limits(), AggState::hash_ngroups_current, initialize_aggregate(), MemoryContextAlloc(), AggState::numtrans, AggState::pertrans, and TupleHashTableData::tablecxt.
Referenced by agg_refill_hash_table(), and lookup_hash_entries().
|
static |
Definition at line 477 of file nodeAgg.c.
References Assert, AggState::current_phase, ExecGetResultType(), Sort::numCols, outerPlanState, AggState::phase, AggState::phases, AggState::sort_in, AggState::sort_out, AggStatePerPhaseData::sortnode, tuplesort_begin_heap(), tuplesort_end(), TUPLESORT_NONE, tuplesort_performsort(), and work_mem.
Referenced by agg_retrieve_direct(), ExecInitAgg(), and ExecReScanAgg().
|
static |
Definition at line 2095 of file nodeAgg.c.
References TupleHashEntryData::additional, AggStatePerHashData::aggnode, ExprContext::ecxt_outertuple, hash(), AggState::hash_pergroup, AggState::hash_spill_mode, AggState::hash_spills, AggState::hash_tapeset, hashagg_spill_init(), hashagg_spill_tuple(), AggState::hashentrysize, AggStatePerHashData::hashslot, AggStatePerHashData::hashtable, initialize_hash_entry(), LookupTupleHashEntry(), AggState::num_hashes, Agg::numGroups, HashAggSpill::partitions, AggState::perhash, prepare_hash_slot(), select_current_set(), and AggState::tmpcontext.
Referenced by agg_fill_hash_table(), and agg_retrieve_direct().
|
inlinestatic |
Definition at line 1204 of file nodeAgg.c.
References ExecClearTuple(), ExecStoreVirtualTuple(), AggStatePerHashData::hashGrpColIdxInput, i, AggStatePerHashData::largestGrpColIdx, AggStatePerHashData::numhashGrpCols, slot_getsomeattrs(), TupleTableSlot::tts_isnull, and TupleTableSlot::tts_values.
Referenced by agg_refill_hash_table(), and lookup_hash_entries().
|
static |
Definition at line 1249 of file nodeAgg.c.
References AggState::all_grouped_cols, attnum, bms_is_member(), ExecStoreAllNullTuple(), AggStatePerPhaseData::grouped_cols, AggState::grouped_cols, lfirst_int, linitial_int, AggState::phase, slot_getsomeattrs(), TTS_EMPTY, and TupleTableSlot::tts_isnull.
Referenced by agg_retrieve_direct(), and agg_retrieve_hash_table_in_memory().
|
static |
Definition at line 949 of file nodeAgg.c.
References advance_transition_function(), FunctionCallInfoBaseData::args, CHECK_FOR_INTERRUPTS, AggState::current_set, ExprContext::ecxt_innertuple, ExprContext::ecxt_outertuple, AggStatePerTransData::equalfnMulti, ExecClearTuple(), ExecQual(), i, NullableDatum::isnull, AggStatePerTransData::numDistinctCols, AggStatePerTransData::numTransInputs, ResetExprContext, slot_getsomeattrs(), AggStatePerTransData::sortslot, AggStatePerTransData::sortstates, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, TupleTableSlot::tts_isnull, TupleTableSlot::tts_values, tuplesort_end(), tuplesort_gettupleslot(), tuplesort_performsort(), AggStatePerTransData::uniqslot, and NullableDatum::value.
Referenced by finalize_aggregates().
|
static |
Definition at line 848 of file nodeAgg.c.
References advance_transition_function(), AggStatePerTransData::aggCollation, FunctionCallInfoBaseData::args, Assert, AggState::current_set, datumCopy(), DatumGetBool(), DatumGetPointer(), ExprContext::ecxt_per_tuple_memory, AggStatePerTransData::equalfnOne, FunctionCall2Coll(), AggStatePerTransData::inputtypeByVal, AggStatePerTransData::inputtypeLen, NullableDatum::isnull, MemoryContextReset(), MemoryContextSwitchTo(), AggStatePerTransData::numDistinctCols, pfree(), AggStatePerTransData::sortstates, AggState::tmpcontext, AggStatePerTransData::transfn_fcinfo, tuplesort_end(), tuplesort_getdatum(), tuplesort_performsort(), and NullableDatum::value.
Referenced by finalize_aggregates().
|
static |
Definition at line 1371 of file nodeAgg.c.
References ExecProject(), ExecQual(), InstrCountFiltered1, ScanState::ps, PlanState::ps_ExprContext, PlanState::ps_ProjInfo, PlanState::qual, and AggState::ss.
Referenced by agg_retrieve_direct(), and agg_retrieve_hash_table_in_memory().
Definition at line 455 of file nodeAgg.c.
References AggState::aggcontexts, AggState::curaggcontext, AggState::current_set, and AggState::hashcontext.
Referenced by agg_fill_hash_table(), agg_refill_hash_table(), agg_retrieve_direct(), agg_retrieve_hash_table_in_memory(), ExecInitAgg(), ExecReScanAgg(), initialize_aggregates(), and lookup_hash_entries().