You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-11-02 06:13:16 +03:00
fix(rbo,rules,QA): SCs in AC->AggC->AC ParseTree are not updated with the corresponding derived table if needed.
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include "rulebased_optimizer.h"
|
#include "rulebased_optimizer.h"
|
||||||
|
|
||||||
|
#include "aggregatecolumn.h"
|
||||||
#include "constantcolumn.h"
|
#include "constantcolumn.h"
|
||||||
#include "execplan/calpontselectexecutionplan.h"
|
#include "execplan/calpontselectexecutionplan.h"
|
||||||
#include "execplan/simplecolumn.h"
|
#include "execplan/simplecolumn.h"
|
||||||
@@ -521,17 +522,46 @@ void tryToUpdateScToUseRewrittenDerived(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void extractExtraSCsFromGBOrOB(
|
void updateSCsUsingIteration(optimizer::TableAliasToNewAliasAndSCPositionsMap& tableAliasToSCPositionsMap,
|
||||||
optimizer::TableAliasToNewAliasAndSCPositionsMap& tableAliasToSCPositionsMap,
|
std::vector<execplan::SRCP>& rcs, const bool ignoreAgg)
|
||||||
const execplan::CalpontSelectExecutionPlan::GroupByColumnList& groupByOrOrderByCols)
|
|
||||||
{
|
{
|
||||||
for (auto& rc : groupByOrOrderByCols)
|
for (auto& rc : rcs)
|
||||||
{
|
{
|
||||||
rc->setSimpleColumnList();
|
rc->setSimpleColumnList();
|
||||||
for (auto* sc : rc->simpleColumnList())
|
for (auto* sc : rc->simpleColumnList())
|
||||||
{
|
{
|
||||||
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ignoreAgg && rc->hasAggregate())
|
||||||
|
{
|
||||||
|
for (auto* agc : rc->aggColumnList())
|
||||||
|
{
|
||||||
|
agc->setSimpleColumnList();
|
||||||
|
for (auto* sc : agc->simpleColumnList())
|
||||||
|
{
|
||||||
|
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateSCsUsingWalkers(optimizer::TableAliasToNewAliasAndSCPositionsMap& tableAliasToSCPositionsMap,
|
||||||
|
execplan::ParseTree* pt)
|
||||||
|
{
|
||||||
|
std::vector<execplan::SimpleColumn*> simpleColumns;
|
||||||
|
pt->walk(execplan::getSimpleCols, &simpleColumns);
|
||||||
|
for (auto* sc : simpleColumns)
|
||||||
|
{
|
||||||
|
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<execplan::SimpleColumn*> simpleColumnsFromAgg;
|
||||||
|
pt->walk(execplan::getAggCols, &simpleColumnsFromAgg);
|
||||||
|
for (auto* sc : simpleColumnsFromAgg)
|
||||||
|
{
|
||||||
|
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -592,11 +622,7 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, optimizer::RBO
|
|||||||
{
|
{
|
||||||
for (auto& rc : csep.returnedCols())
|
for (auto& rc : csep.returnedCols())
|
||||||
{
|
{
|
||||||
rc->setSimpleColumnList();
|
updateSCsUsingIteration(tableAliasToSCPositionsMap, csep.returnedCols(), false);
|
||||||
for (auto* sc : rc->simpleColumnList())
|
|
||||||
{
|
|
||||||
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
|
||||||
}
|
|
||||||
newReturnedColumns.push_back(rc);
|
newReturnedColumns.push_back(rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -607,37 +633,27 @@ bool applyParallelCES(execplan::CalpontSelectExecutionPlan& csep, optimizer::RBO
|
|||||||
// 3d pass over GROUP BY columns
|
// 3d pass over GROUP BY columns
|
||||||
if (!csep.groupByCols().empty())
|
if (!csep.groupByCols().empty())
|
||||||
{
|
{
|
||||||
extractExtraSCsFromGBOrOB(tableAliasToSCPositionsMap, csep.groupByCols());
|
updateSCsUsingIteration(tableAliasToSCPositionsMap, csep.groupByCols(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 4th pass over ORDER BY columns
|
// 4th pass over ORDER BY columns
|
||||||
if (!csep.orderByCols().empty())
|
if (!csep.orderByCols().empty())
|
||||||
{
|
{
|
||||||
extractExtraSCsFromGBOrOB(tableAliasToSCPositionsMap, csep.orderByCols());
|
updateSCsUsingIteration(tableAliasToSCPositionsMap, csep.orderByCols(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5th pass over filters to use derived table SCs in filters
|
// 5th pass over filters to use derived table SCs in filters
|
||||||
auto filters = csep.filters();
|
auto filters = csep.filters();
|
||||||
if (filters)
|
if (filters)
|
||||||
{
|
{
|
||||||
std::vector<execplan::SimpleColumn*> simpleColumns;
|
updateSCsUsingWalkers(tableAliasToSCPositionsMap, filters);
|
||||||
filters->walk(execplan::getSimpleCols, &simpleColumns);
|
|
||||||
for (auto* sc : simpleColumns)
|
|
||||||
{
|
|
||||||
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6th pass over filters to use derived table SCs in filters
|
// 6th pass over filters to use derived table SCs in filters
|
||||||
auto having = csep.having();
|
auto having = csep.having();
|
||||||
if (having)
|
if (having)
|
||||||
{
|
{
|
||||||
std::vector<execplan::SimpleColumn*> simpleColumns;
|
updateSCsUsingWalkers(tableAliasToSCPositionsMap, having);
|
||||||
having->walk(execplan::getSimpleCols, &simpleColumns);
|
|
||||||
for (auto* sc : simpleColumns)
|
|
||||||
{
|
|
||||||
tryToUpdateScToUseRewrittenDerived(sc, tableAliasToSCPositionsMap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6.5 pass: update correlated columns inside EXISTS subqueries
|
// 6.5 pass: update correlated columns inside EXISTS subqueries
|
||||||
|
|||||||
Reference in New Issue
Block a user