Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/optimizer/path/costsize.c1
-rw-r--r--src/backend/optimizer/plan/planner.c3
-rw-r--r--src/backend/utils/misc/guc_tables.c15
-rw-r--r--src/backend/utils/misc/postgresql.conf.sample1
4 files changed, 19 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c
index 0f0bcfb7e50..89d3c4352ce 100644
--- a/src/backend/optimizer/path/costsize.c
+++ b/src/backend/optimizer/path/costsize.c
@@ -151,6 +151,7 @@ bool enable_partitionwise_aggregate = false;
bool enable_parallel_append = true;
bool enable_parallel_hash = true;
bool enable_partition_pruning = true;
+bool enable_presorted_aggregate = true;
bool enable_async_append = true;
typedef struct
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index dfda251d956..e21e72eb870 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -3191,7 +3191,8 @@ make_pathkeys_for_groupagg(PlannerInfo *root, List *groupClause, List *tlist,
* sets. All handling specific to ordered aggregates must be done by the
* executor in that case.
*/
- if (root->numOrderedAggs == 0 || root->parse->groupingSets != NIL)
+ if (root->numOrderedAggs == 0 || root->parse->groupingSets != NIL ||
+ !enable_presorted_aggregate)
return grouppathkeys;
/*
diff --git a/src/backend/utils/misc/guc_tables.c b/src/backend/utils/misc/guc_tables.c
index 1bf14eec661..436afe1d215 100644
--- a/src/backend/utils/misc/guc_tables.c
+++ b/src/backend/utils/misc/guc_tables.c
@@ -972,6 +972,21 @@ struct config_bool ConfigureNamesBool[] =
NULL, NULL, NULL
},
{
+ {"enable_presorted_aggregate", PGC_USERSET, QUERY_TUNING_METHOD,
+ gettext_noop("Enables the planner's ability to produce plans which "
+ "provide presorted input for ORDER BY / DISTINCT aggregate "
+ "functions."),
+ gettext_noop("Allows the query planner to build plans which provide "
+ "presorted input for aggregate functions with an ORDER BY / "
+ "DISTINCT clause. When disabled, implicit sorts are always "
+ "performed during execution."),
+ GUC_EXPLAIN
+ },
+ &enable_presorted_aggregate,
+ true,
+ NULL, NULL, NULL
+ },
+ {
{"enable_async_append", PGC_USERSET, QUERY_TUNING_METHOD,
gettext_noop("Enables the planner's use of async append plans."),
NULL,
diff --git a/src/backend/utils/misc/postgresql.conf.sample b/src/backend/utils/misc/postgresql.conf.sample
index 043864597f8..5afdeb04de8 100644
--- a/src/backend/utils/misc/postgresql.conf.sample
+++ b/src/backend/utils/misc/postgresql.conf.sample
@@ -384,6 +384,7 @@
#enable_partition_pruning = on
#enable_partitionwise_join = off
#enable_partitionwise_aggregate = off
+#enable_presorted_aggregate = on
#enable_seqscan = on
#enable_sort = on
#enable_tidscan = on