* hash_agg_check_limits * * After adding a new group to the hash table, check whether we need to enter * spill mode. Allocations may happen without adding new groups (for instance, * if the transition state size grows), so this check is imperfect. */
| 1924 | * if the transition state size grows), so this check is imperfect. |
| 1925 | */ |
| 1926 | static void |
| 1927 | hash_agg_check_limits(AggState *aggstate) |
| 1928 | { |
| 1929 | uint64 ngroups = aggstate->hash_ngroups_current; |
| 1930 | Size meta_mem = MemoryContextMemAllocated(aggstate->hash_metacxt, |
| 1931 | true); |
| 1932 | Size hashkey_mem = MemoryContextMemAllocated(aggstate->hashcontext->ecxt_per_tuple_memory, |
| 1933 | true); |
| 1934 | |
| 1935 | /* |
| 1936 | * Don't spill unless there's at least one group in the hash table so we |
| 1937 | * can be sure to make progress even in edge cases. |
| 1938 | */ |
| 1939 | if (aggstate->hash_ngroups_current > 0 && |
| 1940 | (meta_mem + hashkey_mem > aggstate->hash_mem_limit || |
| 1941 | ngroups > aggstate->hash_ngroups_limit)) |
| 1942 | { |
| 1943 | hash_agg_enter_spill_mode(aggstate); |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | * Enter "spill mode", meaning that no new groups are added to any of the hash |
no test coverage detected