You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by yj...@apache.org on 2026/04/21 04:43:36 UTC

(cloudberry) branch main updated: ORCA: add optimizer_use_streaming_hashagg GUC (#1681)

This is an automated email from the ASF dual-hosted git repository.

yjhjstz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new c9100df0745 ORCA: add optimizer_use_streaming_hashagg GUC (#1681)
c9100df0745 is described below

commit c9100df0745c591f74be7ce19914ac923061ee06
Author: Jianghua.yjh <yj...@gmail.com>
AuthorDate: Mon Apr 20 21:43:32 2026 -0700

    ORCA: add optimizer_use_streaming_hashagg GUC (#1681)
    
    ORCA unconditionally sets stream_safe=true for all local HashAggs in
    FLocalHashAggStreamSafe, so the existing gp_use_streaming_hashagg GUC
    (which is only read by the Postgres planner path in cdbgroupingpaths.c)
    has no effect when optimizer=on. There was no way to disable streaming
    hash agg for ORCA plans.
    
    Introduce optimizer_use_streaming_hashagg (default on) and wire it
    through the standard CConfigParamMapping path: map it (negated) to a
    new EopttraceDisableStreamingHashAgg traceflag, and check that
    traceflag in FLocalHashAggStreamSafe. When the GUC is off, ORCA emits
    a non-streaming Partial HashAggregate that spills to disk and fully
    deduplicates.
---
 src/backend/gpopt/config/CConfigParamMapping.cpp              |  7 ++++++-
 .../libgpopt/src/translate/CTranslatorExprToDXLUtils.cpp      |  3 ++-
 .../libnaucrates/include/naucrates/traceflags/traceflags.h    |  3 +++
 src/backend/utils/misc/guc_gp.c                               | 11 +++++++++++
 src/include/utils/guc.h                                       |  1 +
 src/include/utils/unsync_guc_name.h                           |  1 +
 6 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/src/backend/gpopt/config/CConfigParamMapping.cpp b/src/backend/gpopt/config/CConfigParamMapping.cpp
index 603855c50ec..62255364ba8 100644
--- a/src/backend/gpopt/config/CConfigParamMapping.cpp
+++ b/src/backend/gpopt/config/CConfigParamMapping.cpp
@@ -331,7 +331,12 @@ CConfigParamMapping::SConfigMappingElem CConfigParamMapping::m_elements[] = {
 	 false,	 // m_negate_param
 	 GPOS_WSZ_LIT(
 		 "Enable create window hash agg")},
-	
+
+	{EopttraceDisableStreamingHashAgg, &optimizer_use_streaming_hashagg,
+	 true,	// m_negate_param
+	 GPOS_WSZ_LIT(
+		 "Disable streaming hash agg in ORCA-generated local partial aggregations.")},
+
 };
 
 //---------------------------------------------------------------------------
diff --git a/src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXLUtils.cpp b/src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXLUtils.cpp
index 27f5cb688fe..cf497223553 100644
--- a/src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXLUtils.cpp
+++ b/src/backend/gporca/libgpopt/src/translate/CTranslatorExprToDXLUtils.cpp
@@ -1296,7 +1296,8 @@ CTranslatorExprToDXLUtils::FLocalHashAggStreamSafe(CExpression *pexprAgg)
 
 	// is a local hash aggregate and it generates duplicates (therefore safe to stream)
 	return (COperator::EgbaggtypeLocal == popAgg->Egbaggtype()) &&
-		   popAgg->FGeneratesDuplicates();
+		   popAgg->FGeneratesDuplicates() &&
+		   !GPOS_FTRACE(EopttraceDisableStreamingHashAgg);
 }
 
 //---------------------------------------------------------------------------
diff --git a/src/backend/gporca/libnaucrates/include/naucrates/traceflags/traceflags.h b/src/backend/gporca/libnaucrates/include/naucrates/traceflags/traceflags.h
index 2e489f214e5..8a18ace986a 100644
--- a/src/backend/gporca/libnaucrates/include/naucrates/traceflags/traceflags.h
+++ b/src/backend/gporca/libnaucrates/include/naucrates/traceflags/traceflags.h
@@ -250,6 +250,9 @@ enum EOptTraceFlag
 	// Use the all key exclude the non-fixed key in AGG pds
 	EopttraceAggRRSExcludeNonFixedKey = 103053,
 
+	// Disable streaming hash agg in ORCA-generated local partial aggregations
+	EopttraceDisableStreamingHashAgg = 103054,
+
 	///////////////////////////////////////////////////////
 	///////////////////// statistics flags ////////////////
 	//////////////////////////////////////////////////////
diff --git a/src/backend/utils/misc/guc_gp.c b/src/backend/utils/misc/guc_gp.c
index f846cc24aa3..7a4433cfa98 100644
--- a/src/backend/utils/misc/guc_gp.c
+++ b/src/backend/utils/misc/guc_gp.c
@@ -154,6 +154,7 @@ bool		enable_parallel_dedup_semi_join = true;
 bool		enable_parallel_dedup_semi_reverse_join = true;
 bool		parallel_query_use_streaming_hashagg = false;
 bool		gp_use_streaming_hashagg = true;
+bool		optimizer_use_streaming_hashagg = true;
 int			gp_appendonly_insert_files = 0;
 int			gp_appendonly_insert_files_tuples_range = 0;
 int			gp_random_insert_segments = 0;
@@ -1909,6 +1910,16 @@ struct config_bool ConfigureNamesBool_gp[] =
 		true, NULL, NULL
 	},
 
+	{
+		{"optimizer_use_streaming_hashagg", PGC_USERSET, DEVELOPER_OPTIONS,
+			gettext_noop("Use streaming hash agg in ORCA-generated local partial hash aggregations."),
+			NULL,
+			GUC_NO_SHOW_ALL | GUC_NOT_IN_SAMPLE
+		},
+		&optimizer_use_streaming_hashagg,
+		true, NULL, NULL
+	},
+
 	{
 		{"gp_force_random_redistribution", PGC_USERSET, CUSTOM_OPTIONS,
 			gettext_noop("Force redistribution of insert for randomly-distributed."),
diff --git a/src/include/utils/guc.h b/src/include/utils/guc.h
index aa34138a4b5..652e0b451f3 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -295,6 +295,7 @@ extern bool enable_parallel_dedup_semi_join;
 extern bool enable_parallel_dedup_semi_reverse_join;
 extern bool	parallel_query_use_streaming_hashagg;
 extern bool gp_use_streaming_hashagg;
+extern bool optimizer_use_streaming_hashagg;
 extern int  gp_appendonly_insert_files;
 extern int  gp_appendonly_insert_files_tuples_range;
 extern int  gp_random_insert_segments;
diff --git a/src/include/utils/unsync_guc_name.h b/src/include/utils/unsync_guc_name.h
index 55a81df5bae..85ecb3548e6 100644
--- a/src/include/utils/unsync_guc_name.h
+++ b/src/include/utils/unsync_guc_name.h
@@ -501,6 +501,7 @@
 		"optimizer_skew_factor",
 		"optimizer_use_external_constant_expression_evaluation_for_ints",
 		"optimizer_use_gpdb_allocators",
+		"optimizer_use_streaming_hashagg",
 		"optimizer_xform_bind_threshold",
 		"parallel_leader_participation",
 		"parallel_query_use_streaming_hashagg",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org