* (Re-)initialize the hash table(s) to empty. * * To implement hashed aggregation, we need a hashtable that stores a * representative tuple and an array of AggStatePerGroup structs for each * distinct set of GROUP BY column values. We compute the hash key from the * GROUP BY columns. The per-group data is allocated in lookup_hash_entry(), * for each entry. * * We have a separate hashtabl
| 1517 | * they are all reset at the same time). |
| 1518 | */ |
| 1519 | static void |
| 1520 | build_hash_tables(AggState *aggstate) |
| 1521 | { |
| 1522 | int setno; |
| 1523 | |
| 1524 | for (setno = 0; setno < aggstate->num_hashes; ++setno) |
| 1525 | { |
| 1526 | AggStatePerHash perhash = &aggstate->perhash[setno]; |
| 1527 | long nbuckets; |
| 1528 | Size memory; |
| 1529 | |
| 1530 | if (perhash->hashtable != NULL) |
| 1531 | { |
| 1532 | ResetTupleHashTable(perhash->hashtable); |
| 1533 | continue; |
| 1534 | } |
| 1535 | |
| 1536 | Assert(perhash->aggnode->numGroups > 0); |
| 1537 | |
| 1538 | memory = aggstate->hash_mem_limit / aggstate->num_hashes; |
| 1539 | |
| 1540 | /* choose reasonable number of buckets per hashtable */ |
| 1541 | nbuckets = hash_choose_num_buckets(aggstate->hashentrysize, |
| 1542 | perhash->aggnode->numGroups, |
| 1543 | memory); |
| 1544 | |
| 1545 | build_hash_table(aggstate, setno, nbuckets); |
| 1546 | |
| 1547 | /* initialize some statistic info of hash table */ |
| 1548 | perhash->num_output_groups = 0; |
| 1549 | perhash->num_spill_parts = 0; |
| 1550 | perhash->num_expansions = 0; |
| 1551 | perhash->bucket_total = 0; |
| 1552 | perhash->bucket_used = 0; |
| 1553 | perhash->chain_count = 0; |
| 1554 | perhash->chain_length_total = 0; |
| 1555 | perhash->chain_length_max = 0; |
| 1556 | } |
| 1557 | |
| 1558 | aggstate->hash_ngroups_current = 0; |
| 1559 | } |
| 1560 | |
| 1561 | /* |
| 1562 | * Build a single hashtable for this grouping set. |
no test coverage detected