]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove hashagg_avoid_disk_plan GUC.
authorPeter Geoghegan <pg@bowt.ie>
Tue, 28 Jul 2020 00:53:17 +0000 (17:53 -0700)
committerPeter Geoghegan <pg@bowt.ie>
Tue, 28 Jul 2020 00:53:17 +0000 (17:53 -0700)
Note: This GUC was originally named enable_hashagg_disk when it appeared
in commit 1f39bce0, which added disk-based hash aggregation.  It was
subsequently renamed in commit 92c58fd9.

Author: Peter Geoghegan
Reviewed-By: Jeff Davis, Álvaro Herrera
Discussion: https://postgr.es/m/9d9d1e1252a52ea1bad84ea40dbebfd54e672a0f.camel%40j-davis.com
Backpatch: 13-, where disk-based hash aggregation was introduced.

doc/src/sgml/config.sgml
doc/src/sgml/release-13.sgml
src/backend/optimizer/path/costsize.c
src/backend/optimizer/plan/planner.c
src/backend/utils/misc/guc.c
src/include/optimizer/cost.h

index 6124142097aa6c9f278a1f482befec3a0ee8cd01..145306eec694f145d9c2d649216ac887479a88cb 100644 (file)
@@ -4813,23 +4813,6 @@ ANY <replaceable class="parameter">num_sync</replaceable> ( <replaceable class="
       </listitem>
      </varlistentry>
 
-     <varlistentry id="guc-hashagg-avoid-disk-plan" xreflabel="hashagg_avoid_disk_plan">
-      <term><varname>hashagg_avoid_disk_plan</varname> (<type>boolean</type>)
-      <indexterm>
-       <primary><varname>hashagg_avoid_disk_plan</varname> configuration parameter</primary>
-      </indexterm>
-      </term>
-      <listitem>
-       <para>
-        If set to <literal>on</literal>, causes the planner to avoid choosing
-        hashed aggregation plans that are expected to use the disk. If hashed
-        aggregation is chosen, it may still require the use of disk at
-        execution time, even if this parameter is enabled. The default is
-        <literal>off</literal>.
-       </para>
-      </listitem>
-     </varlistentry>
-
      </variablelist>
      </sect2>
      <sect2 id="runtime-config-query-constants">
index 22363a186bcb565343905238ee4f548f4149eb0f..95d6631faab813b18ae523c9ff8444496c4ddacc 100644 (file)
@@ -627,8 +627,7 @@ Author: Jeff Davis <jdavis@postgresql.org>
 
        <para>
         Previously, hash aggregation was avoided if it was expected to use
-        more than <xref linkend="guc-work-mem"/> memory.  This is controlled
-        by <xref linkend="guc-hashagg-avoid-disk-plan"/>.
+        more than <xref linkend="guc-work-mem"/> memory.
        </para>
       </listitem>
 
index 87c9b49ce147a1fd92b3bbff16bfdd747f1e1acb..e90e286d9b63a0a299806e45cc17b6cb7ea3a587 100644 (file)
@@ -130,7 +130,6 @@ bool                enable_tidscan = true;
 bool           enable_sort = true;
 bool           enable_incremental_sort = true;
 bool           enable_hashagg = true;
-bool           hashagg_avoid_disk_plan = true;
 bool           enable_nestloop = true;
 bool           enable_material = true;
 bool           enable_mergejoin = true;
index 14f3fd44e3615320fbb64c7dfe59cf9f7729541e..e53d1749be962434993daefc539208cbc7d86901 100644 (file)
@@ -4850,11 +4850,10 @@ create_distinct_paths(PlannerInfo *root,
         * Consider hash-based implementations of DISTINCT, if possible.
         *
         * If we were not able to make any other types of path, we *must* hash or
-        * die trying.  If we do have other choices, there are several things that
+        * die trying.  If we do have other choices, there are two things that
         * should prevent selection of hashing: if the query uses DISTINCT ON
         * (because it won't really have the expected behavior if we hash), or if
-        * enable_hashagg is off, or if it looks like the hashtable will exceed
-        * work_mem.
+        * enable_hashagg is off.
         *
         * Note: grouping_is_hashable() is much more expensive to check than the
         * other gating conditions, so we want to do it last.
@@ -4864,12 +4863,7 @@ create_distinct_paths(PlannerInfo *root,
        else if (parse->hasDistinctOn || !enable_hashagg)
                allow_hash = false;             /* policy-based decision not to hash */
        else
-       {
-               Size            hashentrysize = hash_agg_entry_size(0, cheapest_input_path->pathtarget->width, 0);
-
-               allow_hash = !hashagg_avoid_disk_plan ||
-                       (hashentrysize * numDistinctRows <= work_mem * 1024L);
-       }
+               allow_hash = true;              /* default */
 
        if (allow_hash && grouping_is_hashable(parse->distinctClause))
        {
@@ -6749,8 +6743,6 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
 
        if (can_hash)
        {
-               double          hashaggtablesize;
-
                if (parse->groupingSets)
                {
                        /*
@@ -6762,63 +6754,41 @@ add_paths_to_grouping_rel(PlannerInfo *root, RelOptInfo *input_rel,
                }
                else
                {
-                       hashaggtablesize = estimate_hashagg_tablesize(cheapest_path,
-                                                                                                                 agg_costs,
-                                                                                                                 dNumGroups);
-
                        /*
-                        * Provided that the estimated size of the hashtable does not
-                        * exceed work_mem, we'll generate a HashAgg Path, although if we
-                        * were unable to sort above, then we'd better generate a Path, so
-                        * that we at least have one.
+                        * Generate a HashAgg Path.  We just need an Agg over the
+                        * cheapest-total input path, since input order won't matter.
                         */
-                       if (!hashagg_avoid_disk_plan ||
-                               hashaggtablesize < work_mem * 1024L ||
-                               grouped_rel->pathlist == NIL)
-                       {
-                               /*
-                                * We just need an Agg over the cheapest-total input path,
-                                * since input order won't matter.
-                                */
-                               add_path(grouped_rel, (Path *)
-                                                create_agg_path(root, grouped_rel,
-                                                                                cheapest_path,
-                                                                                grouped_rel->reltarget,
-                                                                                AGG_HASHED,
-                                                                                AGGSPLIT_SIMPLE,
-                                                                                parse->groupClause,
-                                                                                havingQual,
-                                                                                agg_costs,
-                                                                                dNumGroups));
-                       }
+                       add_path(grouped_rel, (Path *)
+                                        create_agg_path(root, grouped_rel,
+                                                                        cheapest_path,
+                                                                        grouped_rel->reltarget,
+                                                                        AGG_HASHED,
+                                                                        AGGSPLIT_SIMPLE,
+                                                                        parse->groupClause,
+                                                                        havingQual,
+                                                                        agg_costs,
+                                                                        dNumGroups));
                }
 
                /*
                 * Generate a Finalize HashAgg Path atop of the cheapest partially
-                * grouped path, assuming there is one. Once again, we'll only do this
-                * if it looks as though the hash table won't exceed work_mem.
+                * grouped path, assuming there is one
                 */
                if (partially_grouped_rel && partially_grouped_rel->pathlist)
                {
                        Path       *path = partially_grouped_rel->cheapest_total_path;
 
-                       hashaggtablesize = estimate_hashagg_tablesize(path,
-                                                                                                                 agg_final_costs,
-                                                                                                                 dNumGroups);
-
-                       if (!hashagg_avoid_disk_plan ||
-                               hashaggtablesize < work_mem * 1024L)
-                               add_path(grouped_rel, (Path *)
-                                                create_agg_path(root,
-                                                                                grouped_rel,
-                                                                                path,
-                                                                                grouped_rel->reltarget,
-                                                                                AGG_HASHED,
-                                                                                AGGSPLIT_FINAL_DESERIAL,
-                                                                                parse->groupClause,
-                                                                                havingQual,
-                                                                                agg_final_costs,
-                                                                                dNumGroups));
+                       add_path(grouped_rel, (Path *)
+                                        create_agg_path(root,
+                                                                        grouped_rel,
+                                                                        path,
+                                                                        grouped_rel->reltarget,
+                                                                        AGG_HASHED,
+                                                                        AGGSPLIT_FINAL_DESERIAL,
+                                                                        parse->groupClause,
+                                                                        havingQual,
+                                                                        agg_final_costs,
+                                                                        dNumGroups));
                }
        }
 
@@ -7171,65 +7141,43 @@ create_partial_grouping_paths(PlannerInfo *root,
                }
        }
 
+       /*
+        * Add a partially-grouped HashAgg Path where possible
+        */
        if (can_hash && cheapest_total_path != NULL)
        {
-               double          hashaggtablesize;
-
                /* Checked above */
                Assert(parse->hasAggs || parse->groupClause);
 
-               hashaggtablesize =
-                       estimate_hashagg_tablesize(cheapest_total_path,
-                                                                          agg_partial_costs,
-                                                                          dNumPartialGroups);
-
-               /*
-                * Tentatively produce a partial HashAgg Path, depending on if it
-                * looks as if the hash table will fit in work_mem.
-                */
-               if ((!hashagg_avoid_disk_plan || hashaggtablesize < work_mem * 1024L) &&
-                       cheapest_total_path != NULL)
-               {
-                       add_path(partially_grouped_rel, (Path *)
-                                        create_agg_path(root,
-                                                                        partially_grouped_rel,
-                                                                        cheapest_total_path,
-                                                                        partially_grouped_rel->reltarget,
-                                                                        AGG_HASHED,
-                                                                        AGGSPLIT_INITIAL_SERIAL,
-                                                                        parse->groupClause,
-                                                                        NIL,
-                                                                        agg_partial_costs,
-                                                                        dNumPartialGroups));
-               }
+               add_path(partially_grouped_rel, (Path *)
+                                create_agg_path(root,
+                                                                partially_grouped_rel,
+                                                                cheapest_total_path,
+                                                                partially_grouped_rel->reltarget,
+                                                                AGG_HASHED,
+                                                                AGGSPLIT_INITIAL_SERIAL,
+                                                                parse->groupClause,
+                                                                NIL,
+                                                                agg_partial_costs,
+                                                                dNumPartialGroups));
        }
 
+       /*
+        * Now add a partially-grouped HashAgg partial Path where possible
+        */
        if (can_hash && cheapest_partial_path != NULL)
        {
-               double          hashaggtablesize;
-
-               hashaggtablesize =
-                       estimate_hashagg_tablesize(cheapest_partial_path,
-                                                                          agg_partial_costs,
-                                                                          dNumPartialPartialGroups);
-
-               /* Do the same for partial paths. */
-               if ((!hashagg_avoid_disk_plan ||
-                        hashaggtablesize < work_mem * 1024L) &&
-                       cheapest_partial_path != NULL)
-               {
-                       add_partial_path(partially_grouped_rel, (Path *)
-                                                        create_agg_path(root,
-                                                                                        partially_grouped_rel,
-                                                                                        cheapest_partial_path,
-                                                                                        partially_grouped_rel->reltarget,
-                                                                                        AGG_HASHED,
-                                                                                        AGGSPLIT_INITIAL_SERIAL,
-                                                                                        parse->groupClause,
-                                                                                        NIL,
-                                                                                        agg_partial_costs,
-                                                                                        dNumPartialPartialGroups));
-               }
+               add_partial_path(partially_grouped_rel, (Path *)
+                                                create_agg_path(root,
+                                                                                partially_grouped_rel,
+                                                                                cheapest_partial_path,
+                                                                                partially_grouped_rel->reltarget,
+                                                                                AGG_HASHED,
+                                                                                AGGSPLIT_INITIAL_SERIAL,
+                                                                                parse->groupClause,
+                                                                                NIL,
+                                                                                agg_partial_costs,
+                                                                                dNumPartialPartialGroups));
        }
 
        /*
index 40dfe6dcd697e6c77ca6b8c50fe5c057f269bda7..27804a2a9006319ca3bacd09cdf18fd788f8bac5 100644 (file)
@@ -1010,16 +1010,6 @@ static struct config_bool ConfigureNamesBool[] =
                true,
                NULL, NULL, NULL
        },
-       {
-               {"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
-               },
-               &hashagg_avoid_disk_plan,
-               false,
-               NULL, NULL, NULL
-       },
        {
                {"enable_material", PGC_USERSET, QUERY_TUNING_METHOD,
                        gettext_noop("Enables the planner's use of materialization."),
index 613db8eab6882d2c1398e3134ef34f53ce8baa82..6141654e4783a7d44c58e69959811629cfc5845f 100644 (file)
@@ -55,7 +55,6 @@ extern PGDLLIMPORT bool enable_tidscan;
 extern PGDLLIMPORT bool enable_sort;
 extern PGDLLIMPORT bool enable_incremental_sort;
 extern PGDLLIMPORT bool enable_hashagg;
-extern PGDLLIMPORT bool hashagg_avoid_disk_plan;
 extern PGDLLIMPORT bool enable_nestloop;
 extern PGDLLIMPORT bool enable_material;
 extern PGDLLIMPORT bool enable_mergejoin;