diff options
author | Jeff Davis | 2020-06-11 18:58:16 +0000 |
---|---|---|
committer | Jeff Davis | 2020-06-11 19:57:43 +0000 |
commit | 92c58fd94801dd5c81ee20e26c5bb71ad64552a8 (patch) | |
tree | 9bcddd92b5d49527ff0cbf4af561e2ca9a0cd7c3 /src/backend | |
parent | 5940ffb221316ab73e6fdc780dfe9a07d4221ebb (diff) |
Rework HashAgg GUCs.
Eliminate enable_groupingsets_hash_disk, which was primarily useful
for testing grouping sets that use HashAgg and spill. Instead, hack
the table stats to convince the planner to choose hashed aggregation
for grouping sets that will spill to disk. Suggested by Melanie
Plageman.
Rename enable_hashagg_disk to hashagg_avoid_disk_plan, and invert the
meaning of on/off. The new name indicates more strongly that it only
affects the planner. Also, the word "avoid" is less definite, which
should avoid surprises when HashAgg still needs to use the
disk. Change suggested by Justin Pryzby, though I chose a different
GUC name.
Discussion: https://postgr.es/m/CAAKRu_aisiENMsPM2gC4oUY1hHG3yrCwY-fXUg22C6_MJUwQdA%40mail.gmail.com
Discussion: https://postgr.es/m/20200610021544.GA14879@telsasoft.com
Backpatch-through: 13
Diffstat (limited to 'src/backend')
-rw-r--r-- | src/backend/optimizer/path/costsize.c | 3 | ||||
-rw-r--r-- | src/backend/optimizer/plan/planner.c | 20 | ||||
-rw-r--r-- | src/backend/utils/misc/guc.c | 16 |
3 files changed, 14 insertions, 25 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index b976afb69df..4ff3c7a2fd3 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -130,8 +130,7 @@ bool enable_tidscan = true; bool enable_sort = true; bool enable_incrementalsort = true; bool enable_hashagg = true; -bool enable_hashagg_disk = true; -bool enable_groupingsets_hash_disk = false; +bool hashagg_avoid_disk_plan = true; bool enable_nestloop = true; bool enable_material = true; bool enable_mergejoin = true; diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c index 5ac7fed6a4d..4131019fc98 100644 --- a/src/backend/optimizer/plan/planner.c +++ b/src/backend/optimizer/plan/planner.c @@ -4256,12 +4256,11 @@ consider_groupingsets_paths(PlannerInfo *root, dNumGroups - exclude_groups); /* - * If we have sortable columns to work with (gd->rollups is non-empty) - * and enable_groupingsets_hash_disk is disabled, don't generate - * hash-based paths that will exceed work_mem. + * gd->rollups is empty if we have only unsortable columns to work + * with. Override work_mem in that case; otherwise, we'll rely on the + * sorted-input case to generate usable mixed paths. */ - if (!enable_groupingsets_hash_disk && - hashsize > work_mem * 1024L && gd->rollups) + if (hashsize > work_mem * 1024L && gd->rollups) return; /* nope, won't fit */ /* @@ -4868,7 +4867,7 @@ create_distinct_paths(PlannerInfo *root, { Size hashentrysize = hash_agg_entry_size(0, cheapest_input_path->pathtarget->width, 0); - allow_hash = enable_hashagg_disk || + allow_hash = !hashagg_avoid_disk_plan || (hashentrysize * numDistinctRows <= work_mem * 1024L); } @@ -6773,7 +6772,7 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel, * were unable to sort above, then we'd better generate a Path, so * that we at least have one. */ - if (enable_hashagg_disk || + if (!hashagg_avoid_disk_plan || hashaggtablesize < work_mem * 1024L || grouped_rel->pathlist == NIL) { @@ -6807,7 +6806,7 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel, agg_final_costs, dNumGroups); - if (enable_hashagg_disk || + if (!hashagg_avoid_disk_plan || hashaggtablesize < work_mem * 1024L) add_path(grouped_rel, (Path *) create_agg_path(root, @@ -7188,7 +7187,7 @@ create_partial_grouping_paths(PlannerInfo *root, * Tentatively produce a partial HashAgg Path, depending on if it * looks as if the hash table will fit in work_mem. */ - if ((enable_hashagg_disk || hashaggtablesize < work_mem * 1024L) && + if ((!hashagg_avoid_disk_plan || hashaggtablesize < work_mem * 1024L) && cheapest_total_path != NULL) { add_path(partially_grouped_rel, (Path *) @@ -7215,7 +7214,8 @@ create_partial_grouping_paths(PlannerInfo *root, dNumPartialPartialGroups); /* Do the same for partial paths. */ - if ((enable_hashagg_disk || hashaggtablesize < work_mem * 1024L) && + if ((!hashagg_avoid_disk_plan || + hashaggtablesize < work_mem * 1024L) && cheapest_partial_path != NULL) { add_partial_path(partially_grouped_rel, (Path *) diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 28b2fc72d64..75fc6f11d6a 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -1002,22 +1002,12 @@ static struct config_bool ConfigureNamesBool[] = NULL, NULL, NULL }, { - {"enable_hashagg_disk", PGC_USERSET, QUERY_TUNING_METHOD, - gettext_noop("Enables the planner's use of hashed aggregation plans that are expected to exceed work_mem."), + {"hashagg_avoid_disk_plan", PGC_USERSET, QUERY_TUNING_METHOD, + gettext_noop("Causes the planner to avoid hashed aggregation plans that are expected to use the disk."), NULL, GUC_EXPLAIN }, - &enable_hashagg_disk, - true, - NULL, NULL, NULL - }, - { - {"enable_groupingsets_hash_disk", PGC_USERSET, QUERY_TUNING_METHOD, - gettext_noop("Enables the planner's use of hashed aggregation plans for groupingsets when the total size of the hash tables is expected to exceed work_mem."), - NULL, - GUC_EXPLAIN - }, - &enable_groupingsets_hash_disk, + &hashagg_avoid_disk_plan, false, NULL, NULL, NULL }, |