1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-01 06:46:55 +03:00

feat(CSEP): CSEP printer with indentations to simplify reading + rewriter skeleton + some test binary to describe minimalistic CSEP localy

This commit is contained in:
drrtuy
2025-06-05 10:06:54 +00:00
parent 3a91cded27
commit 79008f4f69
7 changed files with 1046 additions and 843 deletions

View File

@ -47,3 +47,11 @@ set(execplan_LIB_SRCS
columnstore_library(execplan ${execplan_LIB_SRCS}) columnstore_library(execplan ${execplan_LIB_SRCS})
columnstore_link(execplan messageqcpp ${NETSNMP_LIBRARIES} ${ENGINE_DT_LIB} pron loggingcpp) columnstore_link(execplan messageqcpp ${NETSNMP_LIBRARIES} ${ENGINE_DT_LIB} pron loggingcpp)
columnstore_executable(csep_rewrite csep_rewrite.cpp)
columnstore_link(csep_rewrite
${ENGINE_LDFLAGS}
${NETSNMP_LIBRARIES}
${ENGINE_WRITE_LIBS}
loggingcpp
)

View File

@ -193,51 +193,64 @@ void CalpontSelectExecutionPlan::havingTokenList(const FilterTokenList& havingTo
having(parser.parse(tokens.begin(), tokens.end())); having(parser.parse(tokens.begin(), tokens.end()));
} }
string CalpontSelectExecutionPlan::toString() const std::string endlWithIndent(const size_t ident)
{
ostringstream output;
output << endl;
output << std::string(ident, ' ');
return output.str();
}
string CalpontSelectExecutionPlan::toString(const size_t ident) const
{ {
ostringstream output; ostringstream output;
output << ">SELECT "; output << std::string(ident, ' ') << "SELECT ";
if (distinct()) if (distinct())
{
output << "DISTINCT "; output << "DISTINCT ";
}
output << "limit: " << limitStart() << " - " << limitNum() << endl; output << "limit: " << limitStart() << " - " << limitNum() << endlWithIndent(ident);
switch (location()) switch (location())
{ {
case CalpontSelectExecutionPlan::MAIN: output << "MAIN" << endl; break; case CalpontSelectExecutionPlan::MAIN: output << "MAIN" << endlWithIndent(ident); break;
case CalpontSelectExecutionPlan::FROM: output << "FROM" << endl; break; case CalpontSelectExecutionPlan::FROM: output << "FROM" << endlWithIndent(ident); break;
case CalpontSelectExecutionPlan::WHERE: output << "WHERE" << endl; break; case CalpontSelectExecutionPlan::WHERE: output << "WHERE" << endlWithIndent(ident); break;
case CalpontSelectExecutionPlan::HAVING: output << "HAVING" << endl; break; case CalpontSelectExecutionPlan::HAVING: output << "HAVING" << endlWithIndent(ident); break;
} }
// Returned Column // Returned Column
CalpontSelectExecutionPlan::ReturnedColumnList retCols = returnedCols(); CalpontSelectExecutionPlan::ReturnedColumnList retCols = returnedCols();
output << ">>Returned Columns" << endl; output << ">>Returned Columns" << endlWithIndent(ident);
output << std::string(ident, ' ');
uint32_t seq = 0; uint32_t seq = 0;
for (unsigned int i = 0; i < retCols.size(); i++) for (unsigned int i = 0; i < retCols.size(); i++)
{ {
output << *retCols[i] << endl; output << *retCols[i] << endlWithIndent(ident);
if (retCols[i]->colSource() & SELECT_SUB) if (retCols[i]->colSource() & SELECT_SUB)
{ {
output << "select sub -- " << endl; output << "select sub -- " << endlWithIndent(ident);
CalpontSelectExecutionPlan* plan = CalpontSelectExecutionPlan* plan =
dynamic_cast<CalpontSelectExecutionPlan*>(fSelectSubList[seq++].get()); dynamic_cast<CalpontSelectExecutionPlan*>(fSelectSubList[seq++].get());
if (plan) if (plan)
output << "{" << *plan << "}" << endl; output << "{" << plan->toString(ident + 2) << "}" << endlWithIndent(ident);
} }
} }
// From Clause // From Clause
CalpontSelectExecutionPlan::TableList tables = tableList(); CalpontSelectExecutionPlan::TableList tables = tableList();
output << ">>From Tables" << endl; output << ">>From Tables" << endlWithIndent(ident);
output << std::string(ident, ' ');
seq = 0; seq = 0;
for (unsigned int i = 0; i < tables.size(); i++) for (unsigned int i = 0; i < tables.size(); i++)
@ -245,42 +258,55 @@ string CalpontSelectExecutionPlan::toString() const
// derived table // derived table
if (tables[i].schema.length() == 0 && tables[i].table.length() == 0) if (tables[i].schema.length() == 0 && tables[i].table.length() == 0)
{ {
output << "derived table - " << tables[i].alias << endl; output << "derived table - " << tables[i].alias << endlWithIndent(ident);
CalpontSelectExecutionPlan* plan = CalpontSelectExecutionPlan* plan =
dynamic_cast<CalpontSelectExecutionPlan*>(fDerivedTableList[seq++].get()); dynamic_cast<CalpontSelectExecutionPlan*>(fDerivedTableList[seq++].get());
if (plan) if (plan)
output << "{" << *plan << "}" << endl; {
output << "{" << plan->toString(ident + 2) << "}" << endlWithIndent(ident);
}
output << std::string(ident, ' ');
} }
else else
{ {
output << tables[i] << endl; output << tables[i] << endl;
output << std::string(ident, ' ');
} }
} }
// Filters // Filters
output << ">>Filters" << endl; output << ">>Filters" << endlWithIndent(ident);
output << std::string(ident, ' ');
if (filters() != nullptr) if (filters() != nullptr)
filters()->walk(ParseTree::print, output); filters()->walk(ParseTree::print, output);
else else
output << "empty filter tree" << endl; output << "empty filter tree" << endlWithIndent(ident);
output << std::string(ident, ' ');
// Group by columns // Group by columns
const CalpontSelectExecutionPlan::GroupByColumnList& gbc = groupByCols(); const CalpontSelectExecutionPlan::GroupByColumnList& gbc = groupByCols();
if (gbc.size() > 0) if (gbc.size() > 0)
{ {
output << ">>Group By Columns" << endl; output << ">>Group By Columns" << endlWithIndent(ident);
output << std::string(ident, ' ');
for (unsigned int i = 0; i < gbc.size(); i++) for (unsigned int i = 0; i < gbc.size(); i++)
output << *gbc[i] << endl; {
output << *gbc[i] << endlWithIndent(ident);
}
output << std::string(ident, ' ');
} }
// Having // Having
if (having() != nullptr) if (having() != nullptr)
{ {
output << ">>Having" << endl; output << ">>Having" << endlWithIndent(ident);
output << std::string(ident, ' ');
having()->walk(ParseTree::print, output); having()->walk(ParseTree::print, output);
} }
@ -289,39 +315,39 @@ string CalpontSelectExecutionPlan::toString() const
if (obc.size() > 0) if (obc.size() > 0)
{ {
output << ">>Order By Columns" << endl; output << ">>Order By Columns" << endlWithIndent(ident);
for (unsigned int i = 0; i < obc.size(); i++) for (unsigned int i = 0; i < obc.size(); i++)
output << *obc[i] << endl; output << *obc[i] << endlWithIndent(ident);
} }
output << "SessionID: " << fSessionID << endl; output << "SessionID: " << fSessionID << endlWithIndent(ident);
output << "TxnID: " << fTxnID << endl; output << "TxnID: " << fTxnID << endlWithIndent(ident);
output << "VerID: " << fVerID << endl; output << "VerID: " << fVerID << endlWithIndent(ident);
output << "TraceFlags: " << fTraceFlags << endl; output << "TraceFlags: " << fTraceFlags << endlWithIndent(ident);
output << "StatementID: " << fStatementID << endl; output << "StatementID: " << fStatementID << endlWithIndent(ident);
output << "DistUnionNum: " << (int)fDistinctUnionNum << endl; output << "DistUnionNum: " << (int)fDistinctUnionNum << endlWithIndent(ident);
output << "Limit: " << fLimitStart << " - " << fLimitNum << endl; output << "Limit: " << fLimitStart << " - " << fLimitNum << endlWithIndent(ident);
output << "String table threshold: " << fStringTableThreshold << endl; output << "String table threshold: " << fStringTableThreshold << endlWithIndent(ident);
output << "--- Column Map ---" << endl; output << "--- Column Map ---" << endlWithIndent(ident);
CalpontSelectExecutionPlan::ColumnMap::const_iterator iter; CalpontSelectExecutionPlan::ColumnMap::const_iterator iter;
for (iter = columnMap().begin(); iter != columnMap().end(); iter++) for (iter = columnMap().begin(); iter != columnMap().end(); iter++)
output << (*iter).first << " : " << (*iter).second << endl; output << (*iter).first << " : " << (*iter).second << endlWithIndent(ident);
output << "UUID: " << fUuid << endl; output << "UUID: " << fUuid << endlWithIndent(ident);
output << "QueryType: " << queryType() << endl; output << "QueryType: " << queryType() << endlWithIndent(ident);
if (!unionVec().empty()) if (!unionVec().empty())
output << "\n--- Union Unit ---" << endl; output << "\n--- Union Unit ---" << endlWithIndent(ident);
for (unsigned i = 0; i < unionVec().size(); i++) for (unsigned i = 0; i < unionVec().size(); i++)
{ {
CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(unionVec()[i].get()); CalpontSelectExecutionPlan* plan = dynamic_cast<CalpontSelectExecutionPlan*>(unionVec()[i].get());
if (plan) if (plan)
output << "{" << *plan << "}\n" << endl; output << "{" << *plan << "}\n" << endlWithIndent(ident);
} }
return output.str(); return output.str();

View File

@ -797,7 +797,7 @@ class CalpontSelectExecutionPlan : public CalpontExecutionPlan
* Return a string rep of the CSEP * Return a string rep of the CSEP
* @return a string * @return a string
*/ */
virtual std::string toString() const; virtual std::string toString(const size_t ident = 0) const;
/** @brief Is this an internal query? /** @brief Is this an internal query?
* *

View File

@ -458,8 +458,13 @@ class CalpontSystemCatalog : public datatypes::SystemCatalog
{ {
return !(*this == rhs); return !(*this == rhs);
} }
bool isColumnstore() const
{
return fisColumnStore;
}
void serialize(messageqcpp::ByteStream&) const; void serialize(messageqcpp::ByteStream&) const;
void unserialize(messageqcpp::ByteStream&); void unserialize(messageqcpp::ByteStream&);
friend std::ostream& operator<<(std::ostream& os, const TableAliasName& rhs); friend std::ostream& operator<<(std::ostream& os, const TableAliasName& rhs);
}; };

View File

@ -0,0 +1,87 @@
#include "execplan/calpontselectexecutionplan.h"
#include "simplecolumn.h"
#include "execplan/calpontsystemcatalog.h"
#include "simplefilter.h"
#include "constantcolumn.h"
using namespace execplan;
const SOP opeq(new Operator("="));
int main()
{
CalpontSelectExecutionPlan csep;
CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnList;
CalpontSelectExecutionPlan::ColumnMap colMap;
string columnlength = CALPONT_SCHEMA + "." + SYSCOLUMN_TABLE + "." + COLUMNLEN_COL;
SimpleColumn* col[1];
col[0] = new SimpleColumn(columnlength, 22222222);
SRCP srcp;
srcp.reset(col[0]);
colMap.insert({columnlength, srcp});
csep.columnMapNonStatic(colMap);
srcp.reset(col[0]->clone());
returnedColumnList.push_back(srcp);
csep.returnedCols(returnedColumnList);
{
SCSEP csepDerived(new CalpontSelectExecutionPlan());
CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnListLocal;
CalpontSelectExecutionPlan::ColumnMap colMapLocal;
string columnlength = CALPONT_SCHEMA + "." + SYSCOLUMN_TABLE + "." + COLUMNLEN_COL;
SimpleColumn* col[1];
col[0] = new SimpleColumn(columnlength, 22222222);
SRCP srcpLocal;
srcpLocal.reset(col[0]);
colMapLocal.insert({columnlength, srcpLocal});
csepDerived->columnMapNonStatic(colMapLocal);
srcp.reset(col[0]->clone());
returnedColumnListLocal.push_back(srcpLocal);
csepDerived->returnedCols(returnedColumnList);
CalpontSelectExecutionPlan::SelectList derivedTables;
derivedTables.push_back(csepDerived);
csep.derivedTableList(derivedTables);
}
CalpontSelectExecutionPlan::TableList tableList = {execplan::CalpontSystemCatalog::TableAliasName("", "", "alias")};
csep.tableList(tableList);
CalpontSelectExecutionPlan::SelectList unionVec;
for (size_t i = 0; i < 3; ++i)
{
SCSEP plan(new CalpontSelectExecutionPlan());
CalpontSelectExecutionPlan::ReturnedColumnList returnedColumnListLocal;
CalpontSelectExecutionPlan::ColumnMap colMapLocal;
SRCP srcpLocal;
srcpLocal.reset(col[0]);
colMapLocal.insert({columnlength, srcpLocal});
plan->columnMapNonStatic(colMapLocal);
srcpLocal.reset(col[0]->clone());
returnedColumnListLocal.push_back(srcpLocal);
plan->returnedCols(returnedColumnListLocal);
plan->txnID(csep.txnID());
plan->verID(csep.verID());
plan->sessionID(csep.sessionID());
plan->columnMapNonStatic(colMapLocal);
plan->returnedCols(returnedColumnListLocal);
unionVec.push_back(plan);
// std::cout << plan->toString() << std::endl;
}
csep.unionVec(unionVec);
std::cout << csep.toString() << std::endl;
}

View File

@ -79,9 +79,6 @@ SubQueryTransformer::~SubQueryTransformer()
SJSTEP& SubQueryTransformer::makeSubQueryStep(execplan::CalpontSelectExecutionPlan* csep, SJSTEP& SubQueryTransformer::makeSubQueryStep(execplan::CalpontSelectExecutionPlan* csep,
bool subInFromClause) bool subInFromClause)
{ {
if (fOutJobInfo->trace)
cout << (*csep) << endl;
// Setup job info, job list and error status relation. // Setup job info, job list and error status relation.
fSubJobInfo = new JobInfo(fOutJobInfo->rm); fSubJobInfo = new JobInfo(fOutJobInfo->rm);
fSubJobInfo->sessionId = fOutJobInfo->sessionId; fSubJobInfo->sessionId = fOutJobInfo->sessionId;

File diff suppressed because it is too large Load Diff