* Look up hash entries for the current tuple in all hashed grouping sets. * * Be aware that lookup_hash_entry can reset the tmpcontext. * * Some entries may be left NULL if we are in "spill mode". The same tuple * will belong to different groups for each grouping set, so may match a group * already in memory for one set and match a group not in memory for another * set. When in "spill mode"
| 2268 | * efficient. |
| 2269 | */ |
| 2270 | static void |
| 2271 | lookup_hash_entries(AggState *aggstate) |
| 2272 | { |
| 2273 | AggStatePerGroup *pergroup = aggstate->hash_pergroup; |
| 2274 | TupleTableSlot *outerslot = aggstate->tmpcontext->ecxt_outertuple; |
| 2275 | int setno; |
| 2276 | |
| 2277 | for (setno = 0; setno < aggstate->num_hashes; setno++) |
| 2278 | { |
| 2279 | AggStatePerHash perhash = &aggstate->perhash[setno]; |
| 2280 | TupleHashTable hashtable = perhash->hashtable; |
| 2281 | TupleTableSlot *hashslot = perhash->hashslot; |
| 2282 | TupleHashEntry entry; |
| 2283 | uint32 hash; |
| 2284 | bool isnew = false; |
| 2285 | bool *p_isnew; |
| 2286 | |
| 2287 | /* if hash table already spilled, don't create new entries */ |
| 2288 | p_isnew = (aggstate->hash_spill_mode || (aggstate->streaming && aggstate->table_filled)) ? NULL : &isnew; |
| 2289 | |
| 2290 | select_current_set(aggstate, setno, true); |
| 2291 | prepare_hash_slot(perhash, |
| 2292 | outerslot, |
| 2293 | hashslot); |
| 2294 | |
| 2295 | entry = LookupTupleHashEntry(hashtable, hashslot, |
| 2296 | p_isnew, &hash); |
| 2297 | |
| 2298 | if (entry != NULL) |
| 2299 | { |
| 2300 | if (isnew) |
| 2301 | initialize_hash_entry(aggstate, hashtable, entry); |
| 2302 | pergroup[setno] = entry->additional; |
| 2303 | } |
| 2304 | else if (!aggstate->streaming) |
| 2305 | { |
| 2306 | HashAggSpill *spill = &aggstate->hash_spills[setno]; |
| 2307 | TupleTableSlot *slot = aggstate->tmpcontext->ecxt_outertuple; |
| 2308 | |
| 2309 | if (spill->partitions == NULL) |
| 2310 | hashagg_spill_init(aggstate, spill, aggstate->hash_tapeinfo, 0, |
| 2311 | perhash->aggnode->numGroups, |
| 2312 | aggstate->hashentrysize); |
| 2313 | perhash->num_spill_parts += spill->npartitions; |
| 2314 | |
| 2315 | hashagg_spill_tuple(aggstate, spill, slot, hash); |
| 2316 | pergroup[setno] = NULL; |
| 2317 | } |
| 2318 | } |
| 2319 | } |
| 2320 | |
| 2321 | /* |
| 2322 | * ExecAgg - |
no test coverage detected