From 7bb33e0f235b24fa98f607790b6d38435b840d65 Mon Sep 17 00:00:00 2001 From: Andrey Kazachkov Date: Tue, 15 Sep 2026 13:42:04 +0300 Subject: [PATCH 1/2] Handle zero filter damping in ORCA conjunctions optimizer_damping_factor_filter accepts zero, but CStatisticsConfig asserts that the value is strictly positive. In assertion-enabled builds, this can trigger ORCA fallback during configuration creation. Zero damping represents full correlation between predicates, so retain the largest scale factor, corresponding to the smallest predicate selectivity. --- .../libgpopt/src/engine/CStatisticsConfig.cpp | 2 +- .../src/statistics/CScaleFactorUtils.cpp | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp b/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp index 885a809d5f0..7cc337c44f2 100644 --- a/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp +++ b/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp @@ -41,7 +41,7 @@ CStatisticsConfig::CStatisticsConfig(CMemoryPool *mp, m_max_stats_buckets(max_stats_buckets), m_phsmdidcolinfo(nullptr) { - GPOS_ASSERT(CDouble(0.0) < damping_factor_filter); + GPOS_ASSERT(CDouble(0.0) <= damping_factor_filter); GPOS_ASSERT(CDouble(0.0) <= damping_factor_join); GPOS_ASSERT(CDouble(0.0) < damping_factor_groupby); GPOS_ASSERT(0 < max_stats_buckets); diff --git a/src/backend/gporca/libnaucrates/src/statistics/CScaleFactorUtils.cpp b/src/backend/gporca/libnaucrates/src/statistics/CScaleFactorUtils.cpp index d6e078bd7e9..658eb68caf4 100644 --- a/src/backend/gporca/libnaucrates/src/statistics/CScaleFactorUtils.cpp +++ b/src/backend/gporca/libnaucrates/src/statistics/CScaleFactorUtils.cpp @@ -502,12 +502,25 @@ CScaleFactorUtils::CalcScaleFactorCumulativeConj( const ULONG num_cols = scale_factors->Size(); CDouble scale_factor(1.0); + if (0 == num_cols) + { + return scale_factor; + } + if (1 < num_cols) { // sort (in desc order) the scaling factor based on the selectivity of each column scale_factors->Sort(CScaleFactorUtils::DescendingOrderCmpFunc); } + if (CDouble(0.0) == stats_config->DDampingFactorFilter()) + { + // Maximum overlap: retain only the smallest selectivity, represented + // by the largest scale factor. Handle zero explicitly rather than + // relying on CDouble's minimum magnitude when computing powers. + return std::max(CStatistics::MinRows.Get(), (*scale_factors)[0]->Get()); + } + for (ULONG ul = 0; ul < num_cols; ul++) { // apply damping factor From 5e64fe771cf49474a642cde070c9b07919b2b459 Mon Sep 17 00:00:00 2001 From: Andrey Kazachkov Date: Fri, 18 Sep 2026 20:38:44 +0300 Subject: [PATCH 2/2] Allow damping_factor_groupby to be zero --- src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp b/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp index 7cc337c44f2..f26fd3025bd 100644 --- a/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp +++ b/src/backend/gporca/libgpopt/src/engine/CStatisticsConfig.cpp @@ -43,7 +43,7 @@ CStatisticsConfig::CStatisticsConfig(CMemoryPool *mp, { GPOS_ASSERT(CDouble(0.0) <= damping_factor_filter); GPOS_ASSERT(CDouble(0.0) <= damping_factor_join); - GPOS_ASSERT(CDouble(0.0) < damping_factor_groupby); + GPOS_ASSERT(CDouble(0.0) <= damping_factor_groupby); GPOS_ASSERT(0 < max_stats_buckets); //m_phmmdidcolinfo = New(m_mp) HMMDIdMissingstatscol(m_mp);