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

oppenheimer01 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git

commit 4087e15b601cacbbdaaa627fc8eb0ca4438d2e1c
Author: Jianghua.yjh <[email protected]>
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 50ff4194684..4312c86ad15 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 354bca248f5..4f6401fb43f 100644
--- a/src/include/utils/guc.h
+++ b/src/include/utils/guc.h
@@ -301,6 +301,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 e74955d0360..e9d5c7eb05b 100644
--- a/src/include/utils/unsync_guc_name.h
+++ b/src/include/utils/unsync_guc_name.h
@@ -511,6 +511,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: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to