From 96fc875255b4733a76584798a7b60b67a84b172e Mon Sep 17 00:00:00 2001 From: drrtuy Date: Mon, 1 Sep 2025 15:13:17 +0000 Subject: [PATCH] fix(rbo,rules,QA): ExistsFilter::transform merges statistics to enable QA for EXISTS expressions. --- dbcon/execplan/calpontselectexecutionplan.cpp | 11 ++++++++--- dbcon/mysql/ha_exists_sub.cpp | 3 +++ dbcon/rbo/rbo_apply_parallel_ces.cpp | 2 ++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dbcon/execplan/calpontselectexecutionplan.cpp b/dbcon/execplan/calpontselectexecutionplan.cpp index 38e072d2f..f3a0c4311 100644 --- a/dbcon/execplan/calpontselectexecutionplan.cpp +++ b/dbcon/execplan/calpontselectexecutionplan.cpp @@ -1182,10 +1182,15 @@ execplan::SCSEP CalpontSelectExecutionPlan::cloneForTableWORecursiveSelectsGbObH // Deep copy of column map for (const auto& entry : fColumnMap) { - // WIP only relevant RCs must be copied - if (entry.second) + auto tableAlias = entry.second->singleTable(); + // TODO We insert multiple times if there are multiple SCs for the same RC. + if (tableAlias && targetTableAlias.weakerEq(*tableAlias)) { - newColumnMap.insert({entry.first, SRCP(entry.second->clone())}); + auto it = fColumnMap.find(entry.first); + if (it == fColumnMap.end()) + { + newColumnMap.insert({entry.first, SRCP(entry.second->clone())}); + } } } diff --git a/dbcon/mysql/ha_exists_sub.cpp b/dbcon/mysql/ha_exists_sub.cpp index 181d1c83c..c6d649322 100644 --- a/dbcon/mysql/ha_exists_sub.cpp +++ b/dbcon/mysql/ha_exists_sub.cpp @@ -127,6 +127,9 @@ execplan::ParseTree* ExistsSub::transform() return NULL; } + // Insert column statistics + fGwip.mergeTableStatistics(gwi.tableStatisticsMap); + // remove outer query tables CalpontSelectExecutionPlan::TableList tblist; diff --git a/dbcon/rbo/rbo_apply_parallel_ces.cpp b/dbcon/rbo/rbo_apply_parallel_ces.cpp index 84752c0f3..86cfd9e72 100644 --- a/dbcon/rbo/rbo_apply_parallel_ces.cpp +++ b/dbcon/rbo/rbo_apply_parallel_ces.cpp @@ -441,6 +441,8 @@ execplan::SCSEP createDerivedTableFromTable(execplan::CalpontSelectExecutionPlan } { + derivedCSEP->tableAlias(tableAlias, true); + auto additionalUnionVec = makeUnionFromTable( *derivedCSEP, const_cast(table), ctx);