* Initialize a freshly-created TupleHashEntry. */
| 2217 | * Initialize a freshly-created TupleHashEntry. |
| 2218 | */ |
| 2219 | static void |
| 2220 | initialize_hash_entry(AggState *aggstate, TupleHashTable hashtable, |
| 2221 | TupleHashEntry entry) |
| 2222 | { |
| 2223 | AggStatePerGroup pergroup; |
| 2224 | int transno; |
| 2225 | |
| 2226 | aggstate->hash_ngroups_current++; |
| 2227 | hash_agg_check_limits(aggstate); |
| 2228 | |
| 2229 | /* no need to allocate or initialize per-group state */ |
| 2230 | if (aggstate->numtrans == 0) |
| 2231 | return; |
| 2232 | |
| 2233 | pergroup = (AggStatePerGroup) |
| 2234 | MemoryContextAlloc(hashtable->tablecxt, |
| 2235 | sizeof(AggStatePerGroupData) * aggstate->numtrans); |
| 2236 | |
| 2237 | entry->additional = pergroup; |
| 2238 | |
| 2239 | /* |
| 2240 | * Initialize aggregates for new tuple group, lookup_hash_entries() |
| 2241 | * already has selected the relevant grouping set. |
| 2242 | */ |
| 2243 | for (transno = 0; transno < aggstate->numtrans; transno++) |
| 2244 | { |
| 2245 | AggStatePerTrans pertrans = &aggstate->pertrans[transno]; |
| 2246 | AggStatePerGroup pergroupstate = &pergroup[transno]; |
| 2247 | if (!bms_is_member(transno, aggstate->aggs_used)) |
| 2248 | continue; |
| 2249 | initialize_aggregate(aggstate, pertrans, pergroupstate); |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | /* |
| 2254 | * Look up hash entries for the current tuple in all hashed grouping sets. |
no test coverage detected