diff --git a/dbcon/mysql/ha_from_sub.cpp b/dbcon/mysql/ha_from_sub.cpp index 3fc987f82..95548e7fa 100644 --- a/dbcon/mysql/ha_from_sub.cpp +++ b/dbcon/mysql/ha_from_sub.cpp @@ -188,6 +188,12 @@ void derivedTableOptimization(gp_walk_info* gwip, SCSEP& csep) } } } + // recursively process the nested derived table + for (uint i = 0; i < csep->subSelectList().size(); i++) + { + SCSEP subselect(boost::dynamic_pointer_cast(csep->subSelectList()[i])); + derivedTableOptimization(gwip, subselect); + } } FromSubQuery::FromSubQuery(gp_walk_info& gwip) : SubQuery(gwip) diff --git a/dbcon/mysql/rulebased_optimizer.cpp b/dbcon/mysql/rulebased_optimizer.cpp index 8acfc6d98..3559ad9c6 100644 --- a/dbcon/mysql/rulebased_optimizer.cpp +++ b/dbcon/mysql/rulebased_optimizer.cpp @@ -76,7 +76,7 @@ bool Rule::apply(execplan::CalpontSelectExecutionPlan& root, optimizer::RBOptimi { changedThisRound = walk(root, ctx); hasBeenApplied |= changedThisRound; - if (ctx.logRules) + if (ctx.logRules && changedThisRound) { std::cout << "MCS RBO: " << name << " has been applied this round." << std::endl; } @@ -132,7 +132,7 @@ bool Rule::walk(execplan::CalpontSelectExecutionPlan& csep, optimizer::RBOptimiz if (mayApply(*current)) { - rewrite = applyRule(*current, ctx); + rewrite |= applyRule(*current, ctx); ++ctx.uniqueId; } }