Consider disk-based hash aggregation to implement DISTINCT.
authorJeff Davis <jdavis@postgresql.org>
Wed, 25 Mar 2020 01:19:51 +0000 (18:19 -0700)
committerJeff Davis <jdavis@postgresql.org>
Wed, 25 Mar 2020 01:30:04 +0000 (18:30 -0700)
Correct oversight in 1f39bce0. If enable_hashagg_disk=true, we should
consider hash aggregation for DISTINCT when applicable.

src/backend/optimizer/plan/planner.c

index 5da05283822fc70ce062184d7b2bb1c3aabbc698..b65abf6046d419f37043d0e3de7ca9111834238e 100644 (file)
@@ -4868,8 +4868,8 @@ create_distinct_paths(PlannerInfo *root,
                Size            hashentrysize = hash_agg_entry_size(
                        0, cheapest_input_path->pathtarget->width, 0);
 
-               /* Allow hashing only if hashtable is predicted to fit in work_mem */
-               allow_hash = (hashentrysize * numDistinctRows <= work_mem * 1024L);
+               allow_hash = enable_hashagg_disk ||
+                       (hashentrysize * numDistinctRows <= work_mem * 1024L);
        }
 
        if (allow_hash && grouping_is_hashable(parse->distinctClause))