You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-4589 Follow up on MCOL-4543 to optimize out non-referenced
columns from a subquery involving UNIONs.
This commit is contained in:
@ -57,7 +57,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
|
||||
for (uint i = 0; i < derivedTbList.size(); i++)
|
||||
{
|
||||
CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(derivedTbList[i].get());
|
||||
CalpontSelectExecutionPlan* plan = reinterpret_cast<CalpontSelectExecutionPlan*>(derivedTbList[i].get());
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList cols = plan->returnedCols();
|
||||
vector<CalpontSelectExecutionPlan::ReturnedColumnList> unionColVec;
|
||||
|
||||
@ -73,7 +73,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
for (uint j = 0; j < plan->unionVec().size(); j++)
|
||||
{
|
||||
unionColVec.push_back(
|
||||
dynamic_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get())->returnedCols());
|
||||
reinterpret_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get())->returnedCols());
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,7 +82,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
|
||||
for (uint j = 0; j < plan->unionVec().size(); j++)
|
||||
{
|
||||
if (dynamic_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get())->tableList().empty())
|
||||
if (reinterpret_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get())->tableList().empty())
|
||||
{
|
||||
horizontalOptimization = false;
|
||||
break;
|
||||
@ -111,6 +111,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
// of the subquery in ExeMgr.
|
||||
// This will be addressed in future.
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList nonConstCols;
|
||||
vector<CalpontSelectExecutionPlan::ReturnedColumnList> nonConstUnionColVec(unionColVec.size());
|
||||
|
||||
int64_t lastNonConstIndex = -1;
|
||||
|
||||
@ -122,7 +123,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
if (cols[i]->derivedRefCol())
|
||||
cols[i]->derivedRefCol()->decRefCount();
|
||||
|
||||
if ((lastNonConstIndex == -1) && unionColVec.empty())
|
||||
if (lastNonConstIndex == -1)
|
||||
{
|
||||
SimpleColumn* sc = dynamic_cast<SimpleColumn*>(cols[i].get());
|
||||
|
||||
@ -134,13 +135,28 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
else
|
||||
{
|
||||
cols[i].reset(new ConstantColumn(val));
|
||||
(dynamic_cast<ConstantColumn*>(cols[i].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
(reinterpret_cast<ConstantColumn*>(cols[i].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
}
|
||||
|
||||
for (uint j = 0; j < unionColVec.size(); j++)
|
||||
{
|
||||
unionColVec[j][i].reset(new ConstantColumn(val));
|
||||
(dynamic_cast<ConstantColumn*>(unionColVec[j][i].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
if (lastNonConstIndex == -1)
|
||||
{
|
||||
CalpontSelectExecutionPlan* unionSubPlan =
|
||||
reinterpret_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get());
|
||||
|
||||
SimpleColumn* sc = dynamic_cast<SimpleColumn*>(unionSubPlan->returnedCols()[i].get());
|
||||
|
||||
if (sc && (unionSubPlan->columnMap().count(sc->columnName()) == 1))
|
||||
{
|
||||
unionSubPlan->columnMap().erase(sc->columnName());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unionColVec[j][i].reset(new ConstantColumn(val));
|
||||
(reinterpret_cast<ConstantColumn*>(unionColVec[j][i].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (lastNonConstIndex == -1)
|
||||
@ -155,27 +171,36 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
if (!cols.empty())
|
||||
{
|
||||
cols[0].reset(new ConstantColumn(val));
|
||||
(dynamic_cast<ConstantColumn*>(cols[0].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
(reinterpret_cast<ConstantColumn*>(cols[0].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
nonConstCols.push_back(cols[0]);
|
||||
|
||||
for (uint j = 0; j < unionColVec.size(); j++)
|
||||
{
|
||||
unionColVec[j][0].reset(new ConstantColumn(val));
|
||||
(reinterpret_cast<ConstantColumn*>(unionColVec[j][0].get()))->timeZone(thd->variables.time_zone->get_name()->ptr());
|
||||
nonConstUnionColVec[j].push_back(unionColVec[j][0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
nonConstCols.assign(cols.begin(), cols.begin() + lastNonConstIndex + 1);
|
||||
|
||||
for (uint j = 0; j < unionColVec.size(); j++)
|
||||
{
|
||||
nonConstUnionColVec[j].assign(unionColVec[j].begin(), unionColVec[j].begin() + lastNonConstIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
// set back
|
||||
if (unionColVec.empty())
|
||||
{
|
||||
plan->returnedCols(nonConstCols);
|
||||
}
|
||||
else
|
||||
{
|
||||
plan->returnedCols(cols);
|
||||
}
|
||||
plan->returnedCols(nonConstCols);
|
||||
|
||||
for (uint j = 0; j < unionColVec.size(); j++)
|
||||
dynamic_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get())->returnedCols(unionColVec[j]);
|
||||
{
|
||||
CalpontSelectExecutionPlan* unionSubPlan =
|
||||
reinterpret_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get());
|
||||
unionSubPlan->returnedCols(nonConstUnionColVec[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -210,7 +235,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
|
||||
for (uint i = 0; i < derivedTbList.size(); i++)
|
||||
{
|
||||
CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(derivedTbList[i].get());
|
||||
CalpontSelectExecutionPlan* plan = reinterpret_cast<CalpontSelectExecutionPlan*>(derivedTbList[i].get());
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList derivedColList = plan->returnedCols();
|
||||
mapIt = derivedTbFilterMap.find(plan->derivedTbAlias());
|
||||
|
||||
@ -240,7 +265,7 @@ void derivedTableOptimization(THD* thd, SCSEP& csep)
|
||||
for (uint j = 0; j < plan->unionVec().size(); j++)
|
||||
{
|
||||
CalpontSelectExecutionPlan* unionPlan =
|
||||
dynamic_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get());
|
||||
reinterpret_cast<CalpontSelectExecutionPlan*>(plan->unionVec()[j].get());
|
||||
CalpontSelectExecutionPlan::ReturnedColumnList unionColList = unionPlan->returnedCols();
|
||||
ParseTree* mainFilterForUnion = new ParseTree();
|
||||
mainFilterForUnion->copyTree(*(mapIt->second));
|
||||
|
Reference in New Issue
Block a user