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

Function hashagg_recompile_expressions

src/backend/executor/nodeAgg.c:1801–1848  ·  view source on GitHub ↗

* hashagg_recompile_expressions() * * Identifies the right phase, compiles the right expression given the * arguments, and then sets phase->evalfunc to that expression. * * Different versions of the compiled expression are needed depending on * whether hash aggregation has spilled or not, and whether it's reading from * the outer plan or a tape. Before spilling to disk, the expression reads

Source from the content-addressed store, hash-verified

1799 * expressions in the AggStatePerPhase, and reuse when appropriate.
1800 */
1801static void
1802hashagg_recompile_expressions(AggState *aggstate, bool minslot, bool nullcheck)
1803{
1804 AggStatePerPhase phase;
1805 int i = minslot ? 1 : 0;
1806 int j = nullcheck ? 1 : 0;
1807
1808 Assert(aggstate->aggstrategy == AGG_HASHED ||
1809 aggstate->aggstrategy == AGG_MIXED);
1810
1811 if (aggstate->aggstrategy == AGG_HASHED)
1812 phase = &aggstate->phases[0];
1813 else /* AGG_MIXED */
1814 phase = &aggstate->phases[1];
1815
1816 if (phase->evaltrans_cache[i][j] == NULL)
1817 {
1818 const TupleTableSlotOps *outerops = aggstate->ss.ps.outerops;
1819 bool outerfixed = aggstate->ss.ps.outeropsfixed;
1820 bool dohash = true;
1821 bool dosort = false;
1822
1823 /*
1824 * If minslot is true, that means we are processing a spilled batch
1825 * (inside agg_refill_hash_table()), and we must not advance the
1826 * sorted grouping sets.
1827 */
1828 if (aggstate->aggstrategy == AGG_MIXED && !minslot)
1829 dosort = true;
1830
1831 /* temporarily change the outerops while compiling the expression */
1832 if (minslot)
1833 {
1834 aggstate->ss.ps.outerops = &TTSOpsMinimalTuple;
1835 aggstate->ss.ps.outeropsfixed = true;
1836 }
1837
1838 phase->evaltrans_cache[i][j] = ExecBuildAggTrans(aggstate, phase,
1839 dosort, dohash,
1840 nullcheck);
1841
1842 /* change back */
1843 aggstate->ss.ps.outerops = outerops;
1844 aggstate->ss.ps.outeropsfixed = outerfixed;
1845 }
1846
1847 phase->evaltrans = phase->evaltrans_cache[i][j];
1848}
1849
1850/*
1851 * Set limits that trigger spilling to avoid exceeding hash_mem. Consider the

Callers 3

agg_refill_hash_tableFunction · 0.85
ExecReScanAggFunction · 0.85

Calls 1

ExecBuildAggTransFunction · 0.85

Tested by

no test coverage detected