From 97b9bd12d57e433780b29a7e45415f19efb55234 Mon Sep 17 00:00:00 2001 From: RingsC Date: Wed, 19 Oct 2022 21:05:38 +0800 Subject: [PATCH] feat(tianmu): Improve Tianmu code (#11) Improve Tianmu code, including: compiled_query_term, TabID, etc. --- storage/tianmu/core/compiled_query.cpp | 215 +++++++++++------- storage/tianmu/core/compiled_query.h | 114 +++++----- .../{cq_term.cpp => compiled_query_term.cpp} | 0 .../core/{cq_term.h => compiled_query_term.h} | 13 +- storage/tianmu/core/condition.h | 4 +- storage/tianmu/core/condition_encoder.cpp | 2 +- storage/tianmu/core/descriptor.h | 2 +- storage/tianmu/core/just_a_table.cpp | 2 +- storage/tianmu/core/multi_index.h | 2 +- storage/tianmu/core/multi_index_builder.h | 2 +- storage/tianmu/core/parameterized_filter.h | 2 +- storage/tianmu/core/query.cpp | 44 ++-- storage/tianmu/core/query.h | 68 +++--- storage/tianmu/core/query_compile.cpp | 58 ++--- storage/tianmu/core/rcattr_exeq_rs.cpp | 2 +- storage/tianmu/core/rcattr_exqp.cpp | 2 +- storage/tianmu/core/rough_multi_index.h | 2 +- storage/tianmu/core/temp_table.cpp | 6 +- storage/tianmu/core/temp_table.h | 8 +- storage/tianmu/handler/ha_tianmu.cpp | 6 +- storage/tianmu/handler/ha_tianmu.h | 2 +- 21 files changed, 305 insertions(+), 251 deletions(-) rename storage/tianmu/core/{cq_term.cpp => compiled_query_term.cpp} (100%) rename storage/tianmu/core/{cq_term.h => compiled_query_term.h} (91%) diff --git a/storage/tianmu/core/compiled_query.cpp b/storage/tianmu/core/compiled_query.cpp index 3419ea5ed..077d1bd2e 100644 --- a/storage/tianmu/core/compiled_query.cpp +++ b/storage/tianmu/core/compiled_query.cpp @@ -22,6 +22,7 @@ namespace Tianmu { namespace core { + CompiledQuery::CompiledQuery() { no_tabs = 0; no_conds = 0; @@ -66,9 +67,10 @@ CompiledQuery::CQStep::CQStep(const CompiledQuery::CQStep &s) if (s.alias) { size_t alias_ct(std::strlen(s.alias) + 1); alias = new char[alias_ct]; + memset(alias, 0x0, alias_ct); std::strcpy(alias, s.alias); } else - alias = NULL; + alias = nullptr; } CompiledQuery::CQStep &CompiledQuery::CQStep::operator=(const CompiledQuery::CQStep &s) { @@ -76,8 +78,10 @@ CompiledQuery::CQStep &CompiledQuery::CQStep::operator=(const CompiledQuery::CQS CQStep tmp_step(s); swap(tmp_step); } + return *this; } + void CompiledQuery::CQStep::swap(CQStep &s) { if (&s != this) { std::swap(type, s.type); @@ -109,10 +113,10 @@ void CompiledQuery::CQStep::swap(CQStep &s) { void CompiledQuery::CQStep::Print(Query *query) { char buf[512] = ""; - char b1[100], b2[100], b3[100]; - b1[0] = b2[0] = b3[0] = '\0'; + char b1[128]{0x0}, b2[128]{0x0}, b3[128]{0x0}; + // b1[0] = b2[0] = b3[0] = '\0'; - char b_op[20]; + char b_op[16]{0x0}; switch (op) { case common::Operator::O_EQ: std::strcpy(b_op, "="); @@ -211,9 +215,8 @@ void CompiledQuery::CQStep::Print(Query *query) { std::strcpy(b_op, "?"); } - char b_cop[20]; // enum common::ColOperation {LIST, COUNT, COUNT_DISTINCT, - // SUM, MIN, MAX, AVG}; - + char b_cop[24]{0x0}; // enum common::ColOperation {LIST, COUNT, COUNT_DISTINCT, + // SUM, MIN, MAX, AVG}; switch (cop) { case common::ColOperation::LISTING: std::strcpy(b_cop, "LIST"); @@ -267,10 +270,9 @@ void CompiledQuery::CQStep::Print(Query *query) { std::strcpy(b_cop, "[no name yet]"); } - char b_tmpar[20]; // enum TMParameter { TMParameter::TM_DISTINCT, TMParameter::TM_TOP, - // TMParameter::TM_EXISTS, TM_COUNT }; - // // Table Mode - + char b_tmpar[24]{0x0}; // enum TMParameter { TMParameter::TM_DISTINCT, TMParameter::TM_TOP, + // TMParameter::TM_EXISTS, TM_COUNT }; + // // Table Mode switch (tmpar) { case TMParameter::TM_DISTINCT: std::strcpy(b_tmpar, "DISTINCT"); @@ -297,10 +299,9 @@ void CompiledQuery::CQStep::Print(Query *query) { std::sprintf(buf, "C:%d = CREATE_%sCONDS(T:%d,%s,%s,%s,%s)", N(c1.n), n1 == static_cast(CondType::OR_SUBTREE) ? "TREE_" : "", N(t1.n), e1.ToString(b1, _countof(b1), t1.n), b_op, e2.ToString(b2, _countof(b2), t1.n), - e3.ToString(b3, _countof(b3), t1.n) - // n1 == 0 ? "WHERE" : (n1 == 1 ? "HAVING" : (n1 == 2 ? "ON - // INNER" : (n1==3 ? "ON LEFT" : "ON RIGHT"))), n2 - ); + e3.ToString(b3, _countof(b3), t1.n)); + // n1 == 0 ? "WHERE" : (n1 == 1 ? "HAVING" : (n1 == 2 ? "ON + // INNER" : (n1==3 ? "ON LEFT" : "ON RIGHT"))), n2 } else std::sprintf(buf, "C:%d = CREATE_CONDS(T:%d, C:%d)", N(c1.n), N(t1.n), N(c2.n)); break; @@ -326,19 +327,16 @@ void CompiledQuery::CQStep::Print(Query *query) { break; case StepType::TMP_TABLE: { std::sprintf(buf, "T:%d = TMP_TABLE(", N(t1.n)); - unsigned int i = 0; - for (; i < tables1.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables1[i].n)); - std::sprintf(buf + std::strlen(buf), "T:%u)", N(tables1[i].n)); - break; - } + for (auto ele : tables1) std::sprintf(buf + std::strlen(buf), "T:%d,", N(ele.n)); + } break; case StepType::CREATE_VC: if (mysql_expr.size() == 1) { - char s1[200]; + char s1[200]{0x0}; std::strncpy(s1, query->GetItemName(mysql_expr[0]->GetItem()).c_str(), 199); s1[199] = '\0'; std::sprintf(buf, "VC:%d.%d = CREATE_VC(T:%d,EXPR(\"%s\"))", N(t1.n), N(a1.n), N(t1.n), s1); } else if (mysql_expr.size() > 1) { - char s1[200], s2[200]; + char s1[200]{0x0}, s2[200]{0x0}; std::strncpy(s1, query->GetItemName(mysql_expr[0]->GetItem()).c_str(), 199); std::strncpy(s2, query->GetItemName(mysql_expr[mysql_expr.size() - 1]->GetItem()).c_str(), 199); s1[199] = '\0'; @@ -362,21 +360,19 @@ void CompiledQuery::CQStep::Print(Query *query) { return; case StepType::LEFT_JOIN_ON: { std::sprintf(buf, "T:%d.LEFT_JOIN_ON({", N(t1.n)); - int i = 0; - for (; i < (int)tables1.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables1[i].n)); - std::sprintf(buf + std::strlen(buf), "T:%d},{", N(tables1[i].n)); - i = 0; - for (; i < (int)tables2.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables2[i].n)); - std::sprintf(buf + std::strlen(buf), "T:%d},C:%d)", N(tables2[i].n), N(c1.n)); - break; - } + for (auto ele : tables1) std::sprintf(buf + std::strlen(buf), "T:%d,", N(ele.n)); + std::sprintf(buf + std::strlen(buf), "%s", "}"); + + std::sprintf(buf + std::strlen(buf), "%s", "{"); + for (auto ele : tables2) std::sprintf(buf + std::strlen(buf), "T:%d,", N(ele.n)); + std::sprintf(buf + std::strlen(buf), "}, C:%d", N(c1.n)); + } break; case StepType::INNER_JOIN_ON: { std::sprintf(buf, "T:%d.INNER_JOIN_ON({", N(t1.n)); - unsigned int i = 0; - for (; i < tables1.size() - 1; i++) std::sprintf(buf + std::strlen(buf), "T:%d,", N(tables1[i].n)); - std::sprintf(buf + std::strlen(buf), "T:%d},C:%d)", N(tables1[i].n), N(c1.n)); - break; - } + for (auto ele : tables1) std::sprintf(buf + std::strlen(buf), "T:%d,", N(ele.n)); + + std::sprintf(buf + std::strlen(buf), "},C:%d)", N(c1.n)); + } break; case StepType::ADD_CONDS: std::sprintf(buf, "T:%d.ADD_CONDS(C:%d,%s)", N(t1.n), N(c1.n), n1 == 0 ? "WHERE" : (n1 == 1 ? "HAVING" : "?!?")); break; @@ -402,25 +398,29 @@ void CompiledQuery::CQStep::Print(Query *query) { TIANMU_LOG(LogCtl_Level::DEBUG, "%s", buf); } -void CompiledQuery::TableAlias(TabID &t_out, const TabID &n, const char *name, [[maybe_unused]] int id) { +void CompiledQuery::TableAlias(TableID &t_out, const TableID &n, const char *name, [[maybe_unused]] int id) { CompiledQuery::CQStep s; s.type = StepType::TABLE_ALIAS; s.t1 = t_out = NextTabID(); s.t2 = n; + if (name) { s.alias = new char[std::strlen(name) + 1]; + memset(s.alias, 0x0, std::strlen(name) + 1); std::strcpy(s.alias, name); } steps.push_back(s); } -void CompiledQuery::TmpTable(TabID &t_out, const TabID &t1, bool for_subq_in_where) { +void CompiledQuery::TmpTable(TableID &t_out, const TableID &t1, bool for_subq_in_where) { CompiledQuery::CQStep s; if (for_subq_in_where) s.n1 = 1; else s.n1 = 0; + DEBUG_ASSERT(t1.n < 0 && NumOfTabs() > 0); + s.type = StepType::TMP_TABLE; s.t1 = t_out = NextTabID(); // was s.t2!!! s.tables1.push_back(t1); @@ -428,7 +428,7 @@ void CompiledQuery::TmpTable(TabID &t_out, const TabID &t1, bool for_subq_in_whe steps.push_back(s); } -void CompiledQuery::CreateConds(CondID &c_out, const TabID &t1, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3, +void CompiledQuery::CreateConds(CondID &c_out, const TableID &t1, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3, bool is_or_subtree, char like_esc) { CompiledQuery::CQStep s; s.type = StepType::CREATE_CONDS; @@ -443,7 +443,7 @@ void CompiledQuery::CreateConds(CondID &c_out, const TabID &t1, CQTerm e1, commo steps.push_back(s); } -void CompiledQuery::CreateConds(CondID &c_out, const TabID &t1, const CondID &c1, bool is_or_subtree) { +void CompiledQuery::CreateConds(CondID &c_out, const TableID &t1, const CondID &c1, bool is_or_subtree) { CompiledQuery::CQStep s; s.type = StepType::CREATE_CONDS; s.c2 = c1; @@ -453,10 +453,11 @@ void CompiledQuery::CreateConds(CondID &c_out, const TabID &t1, const CondID &c1 steps.push_back(s); } -void CompiledQuery::And(const CondID &c1, const TabID &t, const CondID &c2) { +void CompiledQuery::And(const CondID &c1, const TableID &t, const CondID &c2) { if (c1.IsNull()) { return; } + CompiledQuery::CQStep s; s.type = StepType::AND_F; s.c1 = c1; @@ -465,10 +466,11 @@ void CompiledQuery::And(const CondID &c1, const TabID &t, const CondID &c2) { steps.push_back(s); } -void CompiledQuery::Or(const CondID &c1, const TabID &t, const CondID &c2) { +void CompiledQuery::Or(const CondID &c1, const TableID &t, const CondID &c2) { if (c1.IsNull()) { return; } + CompiledQuery::CQStep s; s.type = StepType::OR_F; s.c1 = c1; @@ -477,7 +479,7 @@ void CompiledQuery::Or(const CondID &c1, const TabID &t, const CondID &c2) { steps.push_back(s); } -void CompiledQuery::And(const CondID &c1, const TabID &t, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3) { +void CompiledQuery::And(const CondID &c1, const TableID &t, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3) { CompiledQuery::CQStep s; s.type = StepType::AND_DESC; s.t1 = t; @@ -489,7 +491,7 @@ void CompiledQuery::And(const CondID &c1, const TabID &t, CQTerm e1, common::Ope steps.push_back(s); } -void CompiledQuery::Or(const CondID &c1, const TabID &t, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3) { +void CompiledQuery::Or(const CondID &c1, const TableID &t, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3) { CompiledQuery::CQStep s; s.type = StepType::OR_DESC; s.t1 = t; @@ -501,15 +503,17 @@ void CompiledQuery::Or(const CondID &c1, const TabID &t, CQTerm e1, common::Oper steps.push_back(s); } -void CompiledQuery::Mode(const TabID &t1, TMParameter mode, int64_t n1, int64_t n2) { +void CompiledQuery::Mode(const TableID &t1, TMParameter mode, int64_t n1, int64_t n2) { CompiledQuery::CQStep s; if (s.t1.n >= 0) { size_t const alias_ct(100); s.type = StepType::STEP_ERROR; s.alias = new char[alias_ct]; + memset(s.alias, 0x0, alias_ct); std::strcpy(s.alias, "T_MODE: can't be applied to RCTable"); return; } + s.type = StepType::T_MODE; s.t1 = t1; s.tmpar = mode; @@ -518,8 +522,8 @@ void CompiledQuery::Mode(const TabID &t1, TMParameter mode, int64_t n1, int64_t steps.push_back(s); } -void CompiledQuery::Join(const TabID &t1, const TabID &t2) { - for (auto &step : steps) +void CompiledQuery::Join(const TableID &t1, const TableID &t2) { + for (auto &step : steps) { if (step.type == StepType::TMP_TABLE && step.t1 == t1) { step.tables1.push_back(t2); for (auto &it : steps_tmp_tables) { @@ -530,6 +534,8 @@ void CompiledQuery::Join(const TabID &t1, const TabID &t2) { } break; } + } + CompiledQuery::CQStep s; s.type = StepType::JOIN_T; s.t1 = t1; @@ -537,8 +543,8 @@ void CompiledQuery::Join(const TabID &t1, const TabID &t2) { steps.push_back(s); } -void CompiledQuery::LeftJoinOn(const TabID &temp_table, std::vector &left_tables, - std::vector &right_tables, const CondID &cond_id) { +void CompiledQuery::LeftJoinOn(const TableID &temp_table, std::vector &left_tables, + std::vector &right_tables, const CondID &cond_id) { CompiledQuery::CQStep s; s.type = StepType::LEFT_JOIN_ON; s.t1 = temp_table; @@ -548,8 +554,8 @@ void CompiledQuery::LeftJoinOn(const TabID &temp_table, std::vector &left steps.push_back(s); } -void CompiledQuery::InnerJoinOn(const TabID &temp_table, std::vector &left_tables, - std::vector &right_tables, const CondID &cond_id) { +void CompiledQuery::InnerJoinOn(const TableID &temp_table, std::vector &left_tables, + std::vector &right_tables, const CondID &cond_id) { CompiledQuery::CQStep s; s.type = StepType::INNER_JOIN_ON; s.t1 = temp_table; @@ -559,8 +565,9 @@ void CompiledQuery::InnerJoinOn(const TabID &temp_table, std::vector &lef steps.push_back(s); } -void CompiledQuery::AddConds(const TabID &t1, const CondID &c1, CondType cond_type) { +void CompiledQuery::AddConds(const TableID &t1, const CondID &c1, CondType cond_type) { if (c1.IsNull()) return; + CompiledQuery::CQStep s; s.type = StepType::ADD_CONDS; s.t1 = t1; @@ -569,14 +576,14 @@ void CompiledQuery::AddConds(const TabID &t1, const CondID &c1, CondType cond_ty steps.push_back(s); } -void CompiledQuery::ApplyConds(const TabID &t1) { +void CompiledQuery::ApplyConds(const TableID &t1) { CompiledQuery::CQStep s; s.type = StepType::APPLY_CONDS; s.t1 = t1; steps.push_back(s); } -void CompiledQuery::AddColumn(AttrID &a_out, const TabID &t1, CQTerm e1, common::ColOperation op, char const alias[], +void CompiledQuery::AddColumn(AttrID &a_out, const TableID &t1, CQTerm e1, common::ColOperation op, char const alias[], bool distinct, SI *si) { DEBUG_ASSERT(t1.n < 0 && NumOfTabs() > 0); CompiledQuery::CQStep s; @@ -585,20 +592,25 @@ void CompiledQuery::AddColumn(AttrID &a_out, const TabID &t1, CQTerm e1, common: s.t1 = t1; s.e1 = e1; s.cop = op; + if (op == common::ColOperation::GROUP_CONCAT && si != NULL) s.si = *si; + if (alias) { size_t const alias_ct(std::strlen(alias) + 1); s.alias = new char[alias_ct]; std::strcpy(s.alias, alias); } else - s.alias = NULL; + s.alias = nullptr; + s.n1 = distinct ? 1 : 0; steps.push_back(s); if (op == common::ColOperation::GROUP_BY) steps_group_by_cols.push_back(s); } -void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, MysqlExpression *expr, const TabID &src_tab) { +void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TableID &t1, MysqlExpression *expr, + const TableID &src_tab) { DEBUG_ASSERT(t1.n < 0 && NumOfTabs() > 0); + CompiledQuery::CQStep s; s.type = StepType::CREATE_VC; s.a1 = a_out = NextVCID(t1); @@ -608,8 +620,9 @@ void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, MysqlExp steps.push_back(s); } -void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, const TabID &subquery, bool on_result) { +void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TableID &t1, const TableID &subquery, bool on_result) { DEBUG_ASSERT(t1.n < 0 && NumOfTabs() > 0); + CompiledQuery::CQStep s; s.type = StepType::CREATE_VC; s.a1 = a_out = NextVCID(t1); @@ -619,8 +632,9 @@ void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, const Ta steps.push_back(s); } -void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, std::vector &vcs, const AttrID &vc_id) { +void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TableID &t1, std::vector &vcs, const AttrID &vc_id) { DEBUG_ASSERT(t1.n < 0 && NumOfTabs() > 0); + CompiledQuery::CQStep s; s.type = StepType::CREATE_VC; s.a1 = a_out = NextVCID(t1); @@ -630,9 +644,10 @@ void CompiledQuery::CreateVirtualColumn(AttrID &a_out, const TabID &t1, std::vec steps.push_back(s); } -void CompiledQuery::CreateVirtualColumn(int &a_out, const TabID &t1, const TabID &table_alias, +void CompiledQuery::CreateVirtualColumn(int &a_out, const TableID &t1, const TableID &table_alias, const AttrID &col_number) { DEBUG_ASSERT(t1.n < 0 && NumOfTabs() > 0); + CompiledQuery::CQStep s; s.type = StepType::CREATE_VC; s.a1 = NextVCID(t1); @@ -643,7 +658,7 @@ void CompiledQuery::CreateVirtualColumn(int &a_out, const TabID &t1, const TabID steps.push_back(s); } -void CompiledQuery::Add_Order(const TabID &t1, const AttrID &vc, +void CompiledQuery::Add_Order(const TableID &t1, const AttrID &vc, int d) // d=1 for descending { CompiledQuery::CQStep s; @@ -654,20 +669,22 @@ void CompiledQuery::Add_Order(const TabID &t1, const AttrID &vc, steps.push_back(s); } -void CompiledQuery::Union(TabID &t_out, const TabID &t2, const TabID &t3, int all) { +void CompiledQuery::Union(TableID &t_out, const TableID &t2, const TableID &t3, int all) { CompiledQuery::CQStep s; s.type = StepType::UNION; + if (t_out.n != t2.n) s.t1 = t_out = NextTabID(); else s.t1 = t2; + s.t2 = t2; s.t3 = t3; s.n1 = all; steps.push_back(s); } -void CompiledQuery::Result(const TabID &t1) { +void CompiledQuery::Result(const TableID &t1) { CompiledQuery::CQStep s; s.type = StepType::RESULT; s.t1 = t1; @@ -675,12 +692,13 @@ void CompiledQuery::Result(const TabID &t1) { } void CompiledQuery::Print(Query *query) { - for (size_t i = 0; i < steps.size(); i++) steps[i].Print(query); + for (auto ele : steps) ele.Print(query); } -bool CompiledQuery::CountColumnOnly(const TabID &table) { +bool CompiledQuery::CountColumnOnly(const TableID &table) { CompiledQuery::CQStep step; bool count_only = false; + for (int i = 0; i < NumOfSteps(); i++) { step = Step(i); if (step.type == CompiledQuery::StepType::ADD_COLUMN && step.t1 == table && @@ -692,11 +710,13 @@ bool CompiledQuery::CountColumnOnly(const TabID &table) { break; } } + return count_only; } bool CompiledQuery::NoAggregationOrderingAndDistinct(int table) { CompiledQuery::CQStep step; + for (int i = 0; i < NumOfSteps(); i++) { step = Step(i); if (step.type == CompiledQuery::StepType::ADD_ORDER && step.t1.n == table) return false; // exclude ordering @@ -706,33 +726,39 @@ bool CompiledQuery::NoAggregationOrderingAndDistinct(int table) { if (step.type == CompiledQuery::StepType::T_MODE && step.t1.n == table && step.tmpar == TMParameter::TM_DISTINCT) return false; // exclude DISTINCT } + return true; } int64_t CompiledQuery::FindLimit(int table) { CompiledQuery::CQStep step; + for (int i = 0; i < NumOfSteps(); i++) { step = Step(i); if (step.type == CompiledQuery::StepType::T_MODE && step.t1.n == table && step.tmpar == TMParameter::TM_TOP) return step.n1 + step.n2; // n1 - omitted, n2 - displayed, i.e. either // ...LIMIT n2; or ...LIMIT n1, n2; } + return -1; } bool CompiledQuery::FindDistinct(int table) { CompiledQuery::CQStep step; + for (int i = 0; i < NumOfSteps(); i++) { step = Step(i); if (step.type == CompiledQuery::StepType::T_MODE && step.t1.n == table && step.tmpar == TMParameter::TM_DISTINCT) return true; } + return false; } -std::set CompiledQuery::GetUsedDims(const TabID &table_id, std::vector> &ta) { +std::set CompiledQuery::GetUsedDims(const TableID &table_id, std::vector> &ta) { std::set result; auto itsteps = TabIDSteps.equal_range(table_id); + for (auto it = itsteps.first; it != itsteps.second; ++it) { CompiledQuery::CQStep step = it->second; if (step.type == CompiledQuery::StepType::ADD_COLUMN && step.t1 == table_id && @@ -766,27 +792,32 @@ std::set CompiledQuery::GetUsedDims(const TabID &table_id, std::vector CompiledQuery::GetGlobalLimit() { break; } } + DEBUG_ASSERT(i < NumOfSteps()); - TabID res = Step(i).t1; + + TableID res = Step(i).t1; if (i > 0 && Step(i - 1).type == CompiledQuery::StepType::T_MODE && Step(i - 1).t1 == res) { return std::pair(Step(i - 1).n1, Step(i - 1).n2); } + return std::pair(0, -1); } -int CompiledQuery::GetNumOfDimens(const TabID &tab_id) { - for (int i = 0; i < NumOfSteps(); i++) { - if (Step(i).type == CompiledQuery::StepType::TMP_TABLE && Step(i).t1 == tab_id) { - return int(Step(i).tables1.size()); - } +int CompiledQuery::GetNumOfDimens(const TableID &tab_id) { + for (auto ele : steps) { + if (ele.type == CompiledQuery::StepType::TMP_TABLE && ele.t1 == tab_id) return int(ele.tables1.size()); } + return -1; } -TabID CompiledQuery::GetTableOfCond(const CondID &cond_id) { - for (int i = 0; i < NumOfSteps(); i++) { - if (Step(i).type == CompiledQuery::StepType::CREATE_CONDS && Step(i).c1 == cond_id) return Step(i).t1; - } - return TabID(); +TableID CompiledQuery::GetTableOfCond(const CondID &cond_id) { + for (auto ele : steps) + if (ele.type == CompiledQuery::StepType::CREATE_CONDS && ele.c1 == cond_id) return ele.t1; + + return TableID(); } + } // namespace core } // namespace Tianmu diff --git a/storage/tianmu/core/compiled_query.h b/storage/tianmu/core/compiled_query.h index 749a3da5c..d8d8649f9 100644 --- a/storage/tianmu/core/compiled_query.h +++ b/storage/tianmu/core/compiled_query.h @@ -21,14 +21,15 @@ #include #include "common/common_definitions.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/just_a_table.h" #include "core/temp_table.h" namespace Tianmu { namespace core { + /* - CompiledQuery - for storing execution plan of a query (sequence of + CompiledQuery - for storing execution plan of a query (sequence of primitive operations) and output data definition */ class MysqlExpression; @@ -61,9 +62,9 @@ class CompiledQuery final { class CQStep { public: StepType type; - TabID t1; - TabID t2; - TabID t3; + TableID t1; + TableID t2; + TableID t3; AttrID a1, a2; CondID c1, c2, c3; CQTerm e1, e2, e3; @@ -74,8 +75,8 @@ class CompiledQuery final { char *alias; std::vector mysql_expr; std::vector virt_cols; - std::vector tables1; - std::vector tables2; + std::vector tables1; + std::vector tables2; int64_t n1, n2; // additional parameter (e.g. descending order, TOP n, // LIMIT n1..n2) SI si; @@ -104,7 +105,11 @@ class CompiledQuery final { CQStep(const CQStep &); - ~CQStep() { delete[] alias; } + ~CQStep() { + delete[] alias; + alias = nullptr; + } + CQStep &operator=(const CQStep &); /*! \brief Swap contents with another instance of CQStep. * \param s - another instance of CQStep. @@ -120,34 +125,34 @@ class CompiledQuery final { return x; } }; - // Initialization + // Initialization CompiledQuery(); CompiledQuery(CompiledQuery const &); CompiledQuery &operator=(CompiledQuery const &) = delete; ~CompiledQuery() = default; // Add a new step to the execution plan - - void TableAlias(TabID &t_out, const TabID &n, const char *tab_name = NULL, int id = -1); - void TmpTable(TabID &t_out, const TabID &t1, bool for_subq = false); - void CreateConds(CondID &c_out, const TabID &t1, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3 = CQTerm(), + void TableAlias(TableID &t_out, const TableID &n, const char *tab_name = NULL, int id = -1); + void TmpTable(TableID &t_out, const TableID &t1, bool for_subq = false); + void CreateConds(CondID &c_out, const TableID &t1, CQTerm e1, common::Operator pr, CQTerm e2, CQTerm e3 = CQTerm(), bool is_or_subtree = false, char like_esc = '\\'); - void CreateConds(CondID &c_out, const TabID &t1, const CondID &c1, bool is_or_subtree = false); - void And(const CondID &c1, const TabID &t, const CondID &c2); - void Or(const CondID &c1, const TabID &t, const CondID &c2); - void And(const CondID &c1, const TabID &t, CQTerm e1, common::Operator pr, CQTerm e2 = CQTerm(), + void CreateConds(CondID &c_out, const TableID &t1, const CondID &c1, bool is_or_subtree = false); + void And(const CondID &c1, const TableID &t, const CondID &c2); + void Or(const CondID &c1, const TableID &t, const CondID &c2); + void And(const CondID &c1, const TableID &t, CQTerm e1, common::Operator pr, CQTerm e2 = CQTerm(), CQTerm e3 = CQTerm()); - void Or(const CondID &c1, const TabID &t, CQTerm e1, common::Operator pr, CQTerm e2 = CQTerm(), CQTerm e3 = CQTerm()); - void Mode(const TabID &t1, TMParameter mode, int64_t n1 = 0, int64_t n2 = 0); - void Join(const TabID &t1, const TabID &t2); - void LeftJoinOn(const TabID &temp_table, std::vector &left_tables, std::vector &right_tables, + void Or(const CondID &c1, const TableID &t, CQTerm e1, common::Operator pr, CQTerm e2 = CQTerm(), + CQTerm e3 = CQTerm()); + void Mode(const TableID &t1, TMParameter mode, int64_t n1 = 0, int64_t n2 = 0); + void Join(const TableID &t1, const TableID &t2); + void LeftJoinOn(const TableID &temp_table, std::vector &left_tables, std::vector &right_tables, const CondID &cond_id); - void InnerJoinOn(const TabID &temp_table, std::vector &left_tables, std::vector &right_tables, + void InnerJoinOn(const TableID &temp_table, std::vector &left_tables, std::vector &right_tables, const CondID &cond_id); - void AddConds(const TabID &t1, const CondID &c1, CondType cond_type); - void ApplyConds(const TabID &t1); - void AddColumn(AttrID &a_out, const TabID &t1, CQTerm e1, common::ColOperation op, char const alias[] = 0, + void AddConds(const TableID &t1, const CondID &c1, CondType cond_type); + void ApplyConds(const TableID &t1); + void AddColumn(AttrID &a_out, const TableID &t1, CQTerm e1, common::ColOperation op, char const alias[] = 0, bool distinct = false, SI *si = NULL); /*! \brief Create compilation step CREATE_VC for mysql expression @@ -157,8 +162,8 @@ class CompiledQuery final { * \param src_table - src_table == t1 if expression works on aggregation * results, == common::NULL_VALUE_32 otherwise \return void */ - void CreateVirtualColumn(AttrID &a_out, const TabID &t1, MysqlExpression *expr, - const TabID &src_table = TabID(common::NULL_VALUE_32)); + void CreateVirtualColumn(AttrID &a_out, const TableID &t1, MysqlExpression *expr, + const TableID &src_table = TableID(common::NULL_VALUE_32)); /*! \brief Create compilation step CREATE_VC for subquery * \param a_out - id of created virtual column @@ -169,24 +174,24 @@ class CompiledQuery final { * representing output columns of t1 (\e true), e.g. in case of subquery in * HAVING \return void */ - void CreateVirtualColumn(AttrID &a_out, const TabID &t1, const TabID &subquery, bool on_result); - void CreateVirtualColumn(AttrID &a_out, const TabID &t1, std::vector &vcs, const AttrID &vc_id); - void CreateVirtualColumn(int &a_out, const TabID &t1, const TabID &table_alias, const AttrID &col_number); - void Add_Order(const TabID &t1, const AttrID &a1, + void CreateVirtualColumn(AttrID &a_out, const TableID &t1, const TableID &subquery, bool on_result); + void CreateVirtualColumn(AttrID &a_out, const TableID &t1, std::vector &vcs, const AttrID &vc_id); + void CreateVirtualColumn(int &a_out, const TableID &t1, const TableID &table_alias, const AttrID &col_number); + void Add_Order(const TableID &t1, const AttrID &a1, int d = 0); // d=1 for descending - void Add_Order(const TabID &p_t, ptrdiff_t p_c) { + void Add_Order(const TableID &p_t, ptrdiff_t p_c) { int a_c(static_cast(p_c)); if (p_c == a_c) this->Add_Order(p_t, AttrID(-abs(a_c)), a_c < 0); } - void Union(TabID &t_out, const TabID &t2, const TabID &t3, int all = 0); - void Result(const TabID &t1); + void Union(TableID &t_out, const TableID &t2, const TableID &t3, int all = 0); + void Result(const TableID &t1); // Informations int NumOfTabs() { return no_tabs; } - int NumOfAttrs(const TabID &tab) { return no_attrs[-tab.n - 1]; } + int NumOfAttrs(const TableID &tab) { return no_attrs[-tab.n - 1]; } int NumOfConds() { return no_conds; } - int NumOfVirtualColumns(const TabID &tt) { + int NumOfVirtualColumns(const TableID &tt) { if (no_virt_cols.find(tt) != no_virt_cols.end()) return no_virt_cols[tt]; return 0; } @@ -194,21 +199,21 @@ class CompiledQuery final { int NumOfSteps() { return (int)steps.size(); } CQStep &Step(int i) { return steps[i]; } - bool CountColumnOnly(const TabID &table); + bool CountColumnOnly(const TableID &table); /*! \brief verify is given table alias is used in the query defined by a temp * table \param tab_id alias of a searched table \param tmp_table alias of the * temp table to be searched through returns true if tab_id == tmp_table or * tab_id is one of the source tables used in tmp_table */ - bool ExistsInTempTable(const TabID &tab_id, const TabID &tmp_table); + bool ExistsInTempTable(const TableID &tab_id, const TableID &tmp_table); /*! \brief Returns set of all dimensions used by output columns (ADD_COLUMN * step) for a given TempTable. \param table_id - id of given TempTable \param * ta - vector of pointers to JustATables necessary to get access to virtual * column inside relevant TempTable \return set */ - std::set GetUsedDims(const TabID &table_id, std::vector> &ta); + std::set GetUsedDims(const TableID &table_id, std::vector> &ta); /*! \brief Finds the first TempTable in compilation steps that contains given * table as source table \param tab_id - id of search table \param tmp_table - @@ -216,22 +221,22 @@ class CompiledQuery final { * if searched table (one that is returned) represents GROUP BY query \return * returns id of TempTable containing tab_id as source table */ - TabID FindSourceOfParameter(const TabID &tab_id, const TabID &tmp_table, bool &is_group_by); + TableID FindSourceOfParameter(const TableID &tab_id, const TableID &tmp_table, bool &is_group_by); /*! \brief Finds if TempTable represents query with GroupBy clause * \param tab_id - TempTable to be checked * \return true if it is GroupBy query, false otherwise */ - bool IsGroupByQuery(const TabID &tab_id); - bool IsResultTable(const TabID &t); - bool IsOrderedBy(const TabID &t); + bool IsGroupByQuery(const TableID &tab_id); + bool IsResultTable(const TableID &t); + bool IsOrderedBy(const TableID &t); int64_t FindLimit(int table); // return LIMIT value for table, or -1 bool FindDistinct(int table); // return true if there is DISTINCT flag for this query bool NoAggregationOrderingAndDistinct(int table); std::pair GetGlobalLimit(); - int GetNumOfDimens(const TabID &tab_id); - TabID GetTableOfCond(const CondID &cond_id); + int GetNumOfDimens(const TableID &tab_id); + TableID GetTableOfCond(const CondID &cond_id); void BuildTableIDStepsMap(); void AddGroupByStep(CQStep s) { steps_group_by_cols.push_back(s); } @@ -239,29 +244,29 @@ class CompiledQuery final { private: // NOTE: new objects' IDs (e.g. while declaring new aliases, filters etc.) are // reserved and obtained by these functions. - TabID NextTabID() { + TableID NextTabID() { no_tabs++; no_attrs.push_back(0); - return TabID(-no_tabs); + return TableID(-no_tabs); } - AttrID NextVCID(const TabID &tt) { return AttrID(no_virt_cols[tt]++); } - AttrID NextAttrID(const TabID &tab) { + AttrID NextVCID(const TableID &tt) { return AttrID(no_virt_cols[tt]++); } + AttrID NextAttrID(const TableID &tab) { no_attrs[-tab.n - 1]++; return AttrID(-no_attrs[-tab.n - 1]); } CondID NextCondID() { return CondID(no_conds++); } // IDs of tables and attributes start with -1 and decrease; - /*! \brief Checks if given TabID represents TempTable or just some table alias - * \param t - TabID of table to be checked + /*! \brief Checks if given TableID represents TempTable or just some table alias + * \param t - TableID of table to be checked * \return true if t is an alias of TempTable, false otherwise */ - bool IsTempTable(const TabID &t); + bool IsTempTable(const TableID &t); int FindRootTempTable(int x); // IDs of params and filters start with 0 and increase. int no_tabs; // counters: which IDs are not in use? int no_conds; // counters: which IDs are not in use? - std::map no_virt_cols; + std::map no_virt_cols; std::vector no_attrs; // repository of attr_ids for each table std::vector steps; // repository of steps to be executed @@ -271,8 +276,9 @@ class CompiledQuery final { // container (steps). std::vector steps_tmp_tables; std::vector steps_group_by_cols; - std::multimap TabIDSteps; + std::multimap TabIDSteps; }; + } // namespace core } // namespace Tianmu diff --git a/storage/tianmu/core/cq_term.cpp b/storage/tianmu/core/compiled_query_term.cpp similarity index 100% rename from storage/tianmu/core/cq_term.cpp rename to storage/tianmu/core/compiled_query_term.cpp diff --git a/storage/tianmu/core/cq_term.h b/storage/tianmu/core/compiled_query_term.h similarity index 91% rename from storage/tianmu/core/cq_term.h rename to storage/tianmu/core/compiled_query_term.h index b3309fc13..b20ffe02b 100644 --- a/storage/tianmu/core/cq_term.h +++ b/storage/tianmu/core/compiled_query_term.h @@ -32,20 +32,21 @@ class Hash64; } // namespace utils namespace core { + struct AttrID { int n; AttrID() : n(common::NULL_VALUE_32) {} explicit AttrID(int _n) : n(_n) {} }; -struct TabID { +struct TableID { int n; - TabID() : n(common::NULL_VALUE_32) {} - explicit TabID(int _n) : n(_n) {} + TableID() : n(common::NULL_VALUE_32) {} + explicit TableID(int _n) : n(_n) {} bool IsNullID() const { return (n == common::NULL_VALUE_32); } - bool operator==(const TabID &other) const { return (n == other.n) && (!IsNullID()); } - bool operator<(const TabID &other) const { return (n < other.n) && (!IsNullID()); } - bool operator!=(const TabID &other) const { return !(operator==(other)); } + bool operator==(const TableID &other) const { return (n == other.n) && (!IsNullID()); } + bool operator<(const TableID &other) const { return (n < other.n) && (!IsNullID()); } + bool operator!=(const TableID &other) const { return !(operator==(other)); } }; struct CondID { diff --git a/storage/tianmu/core/condition.h b/storage/tianmu/core/condition.h index fe967dbb5..0b9ac1015 100644 --- a/storage/tianmu/core/condition.h +++ b/storage/tianmu/core/condition.h @@ -20,11 +20,12 @@ #include -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/descriptor.h" namespace Tianmu { namespace core { + class Condition { protected: std::vector descriptors; @@ -59,6 +60,7 @@ class SingleTreeCondition : public Condition { DescTree *GetTree() { return tree; } bool IsType_Tree() override { return true; } }; + } // namespace core } // namespace Tianmu diff --git a/storage/tianmu/core/condition_encoder.cpp b/storage/tianmu/core/condition_encoder.cpp index 6847680dd..ef7cab05f 100644 --- a/storage/tianmu/core/condition_encoder.cpp +++ b/storage/tianmu/core/condition_encoder.cpp @@ -16,7 +16,7 @@ */ #include "condition_encoder.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/descriptor.h" #include "core/just_a_table.h" #include "core/query.h" diff --git a/storage/tianmu/core/descriptor.h b/storage/tianmu/core/descriptor.h index 77fa7cafe..68629d6d3 100644 --- a/storage/tianmu/core/descriptor.h +++ b/storage/tianmu/core/descriptor.h @@ -22,7 +22,7 @@ #include #include "common/common_definitions.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/dimension_group.h" namespace Tianmu { diff --git a/storage/tianmu/core/just_a_table.cpp b/storage/tianmu/core/just_a_table.cpp index 2f2435ff5..4bba8496f 100644 --- a/storage/tianmu/core/just_a_table.cpp +++ b/storage/tianmu/core/just_a_table.cpp @@ -18,7 +18,7 @@ #include "just_a_table.h" #include "common/assert.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/filter.h" #include "core/temp_table.h" diff --git a/storage/tianmu/core/multi_index.h b/storage/tianmu/core/multi_index.h index ad343ab30..0efe79312 100644 --- a/storage/tianmu/core/multi_index.h +++ b/storage/tianmu/core/multi_index.h @@ -19,7 +19,7 @@ #pragma once #include "core/bin_tools.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/dimension_group.h" #include "core/filter.h" #include "core/index_table.h" diff --git a/storage/tianmu/core/multi_index_builder.h b/storage/tianmu/core/multi_index_builder.h index 302ced291..d00bae017 100644 --- a/storage/tianmu/core/multi_index_builder.h +++ b/storage/tianmu/core/multi_index_builder.h @@ -23,7 +23,7 @@ #include #include "core/bin_tools.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/dimension_group.h" #include "core/filter.h" #include "core/index_table.h" diff --git a/storage/tianmu/core/parameterized_filter.h b/storage/tianmu/core/parameterized_filter.h index bd881396a..e2bc1be8a 100644 --- a/storage/tianmu/core/parameterized_filter.h +++ b/storage/tianmu/core/parameterized_filter.h @@ -18,8 +18,8 @@ #define TIANMU_CORE_PARAMETERIZED_FILTER_H_ #pragma once +#include "core/compiled_query_term.h" #include "core/condition.h" -#include "core/cq_term.h" #include "core/joiner.h" #include "core/multi_index.h" diff --git a/storage/tianmu/core/query.cpp b/storage/tianmu/core/query.cpp index 0f6c9b422..19d096029 100644 --- a/storage/tianmu/core/query.cpp +++ b/storage/tianmu/core/query.cpp @@ -20,7 +20,7 @@ #include "common/common_definitions.h" #include "compiled_query.h" #include "core/compilation_tools.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/engine.h" #include "core/mysql_expression.h" #include "core/parameterized_filter.h" @@ -132,7 +132,7 @@ bool Query::HasAggregation(Item *item) { return has; } -int Query::VirtualColumnAlreadyExists(const TabID &tmp_table, MysqlExpression *expression) { +int Query::VirtualColumnAlreadyExists(const TableID &tmp_table, MysqlExpression *expression) { int exists = common::NULL_VALUE_32; for (auto it = tab_id2expression.lower_bound(tmp_table), end = tab_id2expression.upper_bound(tmp_table); it != end; ++it) { @@ -144,7 +144,7 @@ int Query::VirtualColumnAlreadyExists(const TabID &tmp_table, MysqlExpression *e return exists; } -int Query::VirtualColumnAlreadyExists(const TabID &tmp_table, const TabID &subselect) { +int Query::VirtualColumnAlreadyExists(const TableID &tmp_table, const TableID &subselect) { int exists = common::NULL_VALUE_32; for (auto it = tab_id2subselect.lower_bound(tmp_table), end = tab_id2subselect.upper_bound(tmp_table); it != end; ++it) { @@ -156,7 +156,7 @@ int Query::VirtualColumnAlreadyExists(const TabID &tmp_table, const TabID &subse return exists; } -int Query::VirtualColumnAlreadyExists(const TabID &tmp_table, const std::vector &vcs, const AttrID &at) { +int Query::VirtualColumnAlreadyExists(const TableID &tmp_table, const std::vector &vcs, const AttrID &at) { int exists = common::NULL_VALUE_32; for (auto it = tab_id2inset.lower_bound(tmp_table), end = tab_id2inset.upper_bound(tmp_table); it != end; ++it) { if (it->second.second.second.n == at.n) { @@ -172,7 +172,7 @@ int Query::VirtualColumnAlreadyExists(const TabID &tmp_table, const std::vector< return exists; } -std::pair Query::VirtualColumnAlreadyExists(const TabID &tmp_table, const TabID &tab, const AttrID &at) { +std::pair Query::VirtualColumnAlreadyExists(const TableID &tmp_table, const TableID &tab, const AttrID &at) { for (auto it = phys2virt.lower_bound(std::make_pair(tab.n, at.n)), end = phys2virt.upper_bound(std::make_pair(tab.n, at.n)); it != end; ++it) { @@ -269,7 +269,7 @@ const std::string Query::GetItemName(Item *item) { return "UNKNOWN"; } -int Query::GetAddColumnId(const AttrID &vc, const TabID &tmp_table, const common::ColOperation oper, +int Query::GetAddColumnId(const AttrID &vc, const TableID &tmp_table, const common::ColOperation oper, const bool distinct) { for (int i = 0; i < cq->NumOfSteps(); i++) { CompiledQuery::CQStep *step = &cq->Step(i); @@ -281,7 +281,7 @@ int Query::GetAddColumnId(const AttrID &vc, const TabID &tmp_table, const common return common::NULL_VALUE_32; } -void Query::CQChangeAddColumnLIST2GROUP_BY(const TabID &tmp_table, int attr) { +void Query::CQChangeAddColumnLIST2GROUP_BY(const TableID &tmp_table, int attr) { for (int i = 0; i < cq->NumOfSteps(); i++) { CompiledQuery::CQStep *step = &cq->Step(i); if (step->type == CompiledQuery::StepType::ADD_COLUMN && step->t1 == tmp_table && step->a1.n == attr && @@ -470,7 +470,7 @@ vcolumn::VirtualColumn *Query::CreateColumnFromExpression(std::vectorGetVars().begin()->tab; col.n = exprs[0]->GetVars().begin()->col; @@ -507,15 +507,15 @@ vcolumn::VirtualColumn *Query::CreateColumnFromExpression(std::vectorExistsInTempTable(TabID(iter.tab), t); + res |= cq->ExistsInTempTable(TableID(iter.tab), t); } return !res; } -bool Query::IsParameterFromWhere(const TabID ¶ms_table) { +bool Query::IsParameterFromWhere(const TableID ¶ms_table) { for (auto &it : subqueries_in_where) { if (it.first == params_table) return it.second; } @@ -899,7 +899,7 @@ TempTable *Query::Preexecute(CompiledQuery &qu, ResultSender *sender, [[maybe_un return output_table; } -Query_route_to Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondType filter_type, +Query_route_to Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TableID &tmp_table, CondType filter_type, bool negative, Item *left_expr_for_subselect, common::Operator *oper_for_subselect) { an_arg = UnRef(an_arg); if (an_arg->type() == Item::SUBSELECT_ITEM) { @@ -924,7 +924,7 @@ Query_route_to Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_t // subqueries. Once subquery is compiled we can get rid of its aliases since // they are not needed any longer and stay with aliases of outer query only auto outer_map_copy = table_alias2index_ptr; - TabID subselect; + TableID subselect; Query_route_to res = Compile(cq, select_unit->first_query_block(), select_unit->union_distinct, &subselect, ignore_limit, left_expr_for_subselect, oper_for_subselect, ignore_minmax, true); // restore outer query aliases @@ -974,7 +974,7 @@ Query_route_to Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_t return Query_route_to::TO_MYSQL; AttrID col, vc; - TabID tab; + TableID tab; if ((IsFieldItem(an_arg) || IsAggregationOverFieldItem(an_arg)) && !FieldUnmysterify(an_arg, tab, col)) return Query_route_to::TO_MYSQL; if (IsAggregationItem(an_arg) && HasAggregation(((Item_sum *)an_arg)->get_arg(0))) return Query_route_to::TO_MYSQL; @@ -1060,7 +1060,7 @@ Query_route_to Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_t AttrID vc; AttrID col; - TabID tab; + TableID tab; if (IsFieldItem(an_arg) && !FieldUnmysterify(an_arg, tab, col)) return Query_route_to::TO_MYSQL; if (IsFieldItem(an_arg) && cq->ExistsInTempTable(tab, tmp_table)) { auto phys_vc = VirtualColumnAlreadyExists(tmp_table, tab, col); @@ -1106,7 +1106,7 @@ Query_route_to Query::Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_t return Query_route_to::TO_MYSQL; } -CondID Query::ConditionNumberFromMultipleEquality(Item_equal *conds, const TabID &tmp_table, CondType filter_type, +CondID Query::ConditionNumberFromMultipleEquality(Item_equal *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter, bool is_or_subtree) { CQTerm zero_term, first_term, next_term; Item_field *ifield{nullptr}; @@ -1178,7 +1178,7 @@ Item *Query::FindOutAboutNot(Item *it, bool &is_there_not) { return it; } -CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, CondType filter_type, +CondID Query::ConditionNumberFromComparison(Item *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter, bool is_or_subtree, bool negative) { CondID filter; common::Operator op; /*{ common::Operator::O_EQ, common::Operator::O_NOT_EQ, common::Operator::O_LESS, @@ -1337,8 +1337,8 @@ CondID Query::ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, return filter; } -CondID Query::ConditionNumberFromNaked(Item *conds, const TabID &tmp_table, CondType filter_type, CondID *and_me_filter, - bool is_or_subtree) { +CondID Query::ConditionNumberFromNaked(Item *conds, const TableID &tmp_table, CondType filter_type, + CondID *and_me_filter, bool is_or_subtree) { CondID filter; CQTerm naked_col; if (Item2CQTerm(conds, naked_col, tmp_table, filter_type, @@ -1379,7 +1379,7 @@ struct ItemFieldCompare { bool operator()(Item_field *const &f1, Item_field *const &f2) const { return f1->field < f2->field; } }; -CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filter_type, CondID *and_me_filter, +CondID Query::ConditionNumber(Item *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter, bool is_or_subtree) { // we know, that conds != 0 // returns -1 on error @@ -1561,7 +1561,7 @@ CondID Query::ConditionNumber(Item *conds, const TabID &tmp_table, CondType filt return cond_id; } -Query_route_to Query::BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, const TabID &tmp_table, +Query_route_to Query::BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, const TableID &tmp_table, CondType filter_type, bool is_zero_result, [[maybe_unused]] JoinType join_type) { conds = UnRef(conds); PrintItemTree("BuildFiler(), item tree passed in 'conds':", conds); @@ -1817,7 +1817,7 @@ Table_Status Query::PrefixCheck(Item *conds) { return Table_Status::TALE_SEEN_INVOLVED; } -Query_route_to Query::BuildCondsIfPossible(Item *conds, CondID &cond_id, const TabID &tmp_table, JoinType join_type) { +Query_route_to Query::BuildCondsIfPossible(Item *conds, CondID &cond_id, const TableID &tmp_table, JoinType join_type) { conds = UnRef(conds); if (conds) { CondType filter_type = CondType::ON_LEFT_FILTER; diff --git a/storage/tianmu/core/query.h b/storage/tianmu/core/query.h index 713789aa9..1fd270779 100644 --- a/storage/tianmu/core/query.h +++ b/storage/tianmu/core/query.h @@ -64,11 +64,11 @@ class Query final { void SetRoughQuery(bool set_rough) { rough_query = set_rough; } bool IsRoughQuery() { return rough_query; } Query_route_to Compile(CompiledQuery *compiled_query, Query_block *selects_list, Query_block *last_distinct, - TabID *res_tab = NULL, bool ignore_limit = false, Item *left_expr_for_subselect = NULL, + TableID *res_tab = NULL, bool ignore_limit = false, Item *left_expr_for_subselect = NULL, common::Operator *oper_for_subselect = NULL, bool ignore_minmax = false, bool for_subq_in_where = false); TempTable *Preexecute(CompiledQuery &qu, ResultSender *sender, bool display_now = true); - Query_route_to BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, const TabID &tmp_table, + Query_route_to BuildConditions(Item *conds, CondID &cond_id, CompiledQuery *cq, const TableID &tmp_table, CondType filter_type, bool is_zero_result = false, JoinType join_type = JoinType::JO_INNER); @@ -76,18 +76,18 @@ class Query final { private: CompiledQuery *cq = nullptr; - std::vector> subqueries_in_where; + std::vector> subqueries_in_where; using TabIDColAlias = std::pair; std::map field_alias2num; std::map path2num; // all expression based virtual columns for a given table - std::multimap> tab_id2expression; - std::multimap, AttrID>>> tab_id2inset; + std::multimap> tab_id2expression; + std::multimap, AttrID>>> tab_id2inset; std::vector gc_expressions; std::multimap, std::pair> phys2virt; - std::multimap> tab_id2subselect; + std::multimap> tab_id2subselect; std::map tianmuitems_cur_var_ids; std::vector> ta; // table aliases - sometimes point to TempTables (maybe to the @@ -96,7 +96,7 @@ class Query final { bool rough_query = false; // set as true to enable rough execution - bool FieldUnmysterify(Item *item, TabID &tab, AttrID &col); + bool FieldUnmysterify(Item *item, TableID &tab, AttrID &col); Query_route_to FieldUnmysterify(Item *item, const char *&database_name, const char *&table_name, const char *&table_alias, const char *&table_path, const TABLE *&table_ptr, const char *&field_name, const char *&field_alias); @@ -111,7 +111,7 @@ class Query final { * \return table id and number of virtual column if it exists or * common::NULL_VALUE_32 otherwise */ - std::pair VirtualColumnAlreadyExists(const TabID &tmp_table, const TabID &tab, const AttrID &col); + std::pair VirtualColumnAlreadyExists(const TableID &tmp_table, const TableID &tab, const AttrID &col); /*! \brief Checks if exists virtual column defined by expression: * \param tmp_table - id of table for which column is supposed to be created @@ -119,7 +119,7 @@ class Query final { * \return number of virtual column if it exists or common::NULL_VALUE_32 * otherwise */ - int VirtualColumnAlreadyExists(const TabID &tmp_table, MysqlExpression *expression); + int VirtualColumnAlreadyExists(const TableID &tmp_table, MysqlExpression *expression); /*! \brief Checks if exists virtual column defined by subquery * \param tmp_table - id of table for which column is supposed to be created @@ -127,15 +127,15 @@ class Query final { * \return number of virtual column if it exists or common::NULL_VALUE_32 * otherwise */ - int VirtualColumnAlreadyExists(const TabID &tmp_table, const TabID &subquery); + int VirtualColumnAlreadyExists(const TableID &tmp_table, const TableID &subquery); - int VirtualColumnAlreadyExists(const TabID &tmp_table, const std::vector &vcs, const AttrID &at); + int VirtualColumnAlreadyExists(const TableID &tmp_table, const std::vector &vcs, const AttrID &at); - Query_route_to Item2CQTerm(Item *an_arg, CQTerm &term, const TabID &tmp_table, CondType filter_type, + Query_route_to Item2CQTerm(Item *an_arg, CQTerm &term, const TableID &tmp_table, CondType filter_type, bool negative = false, Item *left_expr_for_subselect = NULL, common::Operator *oper_for_subselect = NULL); - // int FilterNotSubselect(Item *conds, const TabID& tmp_table, FilterType + // int FilterNotSubselect(Item *conds, const TableID& tmp_table, FilterType // filter_type, FilterID *and_me_filter = 0); /*! \brief Create filter from field or function that has no condition @@ -144,11 +144,11 @@ class Query final { * (WHERE, HAVING). \param and_me_filter - ? \return filter number * (non-negative) or error indication (negative) */ - CondID ConditionNumberFromNaked(Item *conds, const TabID &tmp_table, CondType filter_type, CondID *and_me_filter, + CondID ConditionNumberFromNaked(Item *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter, bool is_or_subtree = false); - CondID ConditionNumberFromMultipleEquality(Item_equal *conds, const TabID &tmp_table, CondType filter_type, + CondID ConditionNumberFromMultipleEquality(Item_equal *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter = 0, bool is_or_subtree = false); - CondID ConditionNumberFromComparison(Item *conds, const TabID &tmp_table, CondType filter_type, + CondID ConditionNumberFromComparison(Item *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter = 0, bool is_or_subtree = false, bool negative = false); /*! \brief Checks type of operator involved in condition @@ -172,9 +172,9 @@ class Query final { */ static void MarkWithAll(common::Operator &op); - CondID ConditionNumber(Item *conds, const TabID &tmp_table, CondType filter_type, CondID *and_me_filter = 0, + CondID ConditionNumber(Item *conds, const TableID &tmp_table, CondType filter_type, CondID *and_me_filter = 0, bool is_or_subtree = false); - Query_route_to BuildCondsIfPossible(Item *conds, CondID &cond_id, const TabID &tmp_table, JoinType join_type); + Query_route_to BuildCondsIfPossible(Item *conds, CondID &cond_id, const TableID &tmp_table, JoinType join_type); public: /*! \brief Removes ALL/ANY modifier from an operator @@ -247,7 +247,7 @@ class Query final { * \param group_by - indicates if it is column for group by query * \return column number */ - int AddColumnForPhysColumn(Item *item, const TabID &tmp_table, const common::ColOperation oper, const bool distinct, + int AddColumnForPhysColumn(Item *item, const TableID &tmp_table, const common::ColOperation oper, const bool distinct, bool group_by, const char *alias = NULL); /*! \brief Creates AddColumn step in compilation by creating, if does not @@ -257,7 +257,7 @@ class Query final { * distinct - flag for AddColumn operation \param group_by - indicates if it * is column for group by query \return column number */ - int AddColumnForMysqlExpression(MysqlExpression *mysql_expression, const TabID &tmp_table, const char *alias, + int AddColumnForMysqlExpression(MysqlExpression *mysql_expression, const TableID &tmp_table, const char *alias, const common::ColOperation oper, const bool distinct, bool group_by = false); /*! \brief Computes identifier of a column created by AddColumn operation @@ -267,13 +267,13 @@ class Query final { * \param distinct - modifier of AddColumn * \return column number if it exists or common::NULL_VALUE_32 otherwise */ - int GetAddColumnId(const AttrID &vc, const TabID &tmp_table, const common::ColOperation oper, const bool distinct); + int GetAddColumnId(const AttrID &vc, const TableID &tmp_table, const common::ColOperation oper, const bool distinct); /*! \brief Changes type of AddColumn step in compilation from LISTING to * GROUP_BY \param tmp_table - for which TempTable \param attr - for which * column */ - void CQChangeAddColumnLIST2GROUP_BY(const TabID &tmp_table, int attr); + void CQChangeAddColumnLIST2GROUP_BY(const TableID &tmp_table, int attr); /*! \brief Creates MysqlExpression object that wraps expression tree of MySQL * not containing aggregations. All Item_field items are substituted with @@ -287,7 +287,7 @@ class Query final { * there was any problem with wrapping, e.g., not acceptable type of * expression */ - WrapStatus WrapMysqlExpression(Item *item, const TabID &tmp_table, MysqlExpression *&expr, bool in_where, + WrapStatus WrapMysqlExpression(Item *item, const TableID &tmp_table, MysqlExpression *&expr, bool in_where, bool aggr_used); // // /*! \brief Creates MysqlExpression object that wraps full expression @@ -313,7 +313,7 @@ class Query final { // wrapping, // * e.g., not acceptable type of expression // */ - // WrapStatus WrapMysqlExpressionWithAggregations(Item *item, const TabID& + // WrapStatus WrapMysqlExpressionWithAggregations(Item *item, const TableID& // tmp_table, MysqlExpression*& expr, bool* is_const_or_aggr = NULL); /*! \brief Generates AddColumn compilation steps for every field on SELECT @@ -324,7 +324,7 @@ class Query final { * Query_route_to::to_mysql in case of any problem and Query_route_to::to_tianmu * otherwise */ - Query_route_to AddFields(mem_root_deque &fields, const TabID &tmp_table, const bool group_by_clause, + Query_route_to AddFields(mem_root_deque &fields, const TableID &tmp_table, const bool group_by_clause, int &num_of_added_fields, bool ignore_minmax, bool &aggr_used); /*! \brief Generates AddColumn compilation steps for every field on GROUP BY @@ -333,17 +333,18 @@ class Query final { * Query_route_to::to_mysql in case of any problem and Query_route_to::to_tianmu * otherwise */ - Query_route_to AddGroupByFields(ORDER *group_by, const TabID &tmp_table); + Query_route_to AddGroupByFields(ORDER *group_by, const TableID &tmp_table); //! is this item representing a column local to the temp table (not a //! parameter) - bool IsLocalColumn(Item *item, const TabID &tmp_table); - Query_route_to AddOrderByFields(ORDER *order_by, TabID const &tmp_table, int const group_by_clause); - Query_route_to AddGlobalOrderByFields(SQL_I_List *global_order, const TabID &tmp_table, int max_col); + bool IsLocalColumn(Item *item, const TableID &tmp_table); + Query_route_to AddOrderByFields(ORDER *order_by, TableID const &tmp_table, int const group_by_clause); + Query_route_to AddGlobalOrderByFields(SQL_I_List *global_order, const TableID &tmp_table, int max_col); // stonedb8 List -> mem_root_deque - Query_route_to AddJoins(const mem_root_deque join, TabID &tmp_table, std::vector &left_tables, - std::vector &right_tables, bool in_subquery, bool &first_table, bool for_subq = false); + Query_route_to AddJoins(const mem_root_deque join, TableID &tmp_table, + std::vector &left_tables, std::vector &right_tables, bool in_subquery, + bool &first_table, bool for_subq = false); static bool ClearSubselectTransformation(common::Operator &oper_for_subselect, Item *&field_for_subselect, Item *&conds, Item *&having, Item *&cond_removed, @@ -353,7 +354,7 @@ class Query final { * \brief Are the variables constant (i.e. they are parameters) in the context * of the query represented by TempTable t */ - bool IsConstExpr(MysqlExpression::SetOfVars &vars, const TabID &t); + bool IsConstExpr(MysqlExpression::SetOfVars &vars, const TableID &t); Transaction *m_conn; @@ -378,8 +379,9 @@ class Query final { vcolumn::VirtualColumn *CreateColumnFromExpression(std::vector const &exprs, TempTable *temp_table, int temp_table_alias, MultiIndex *mind); - bool IsParameterFromWhere(const TabID ¶ms_table); + bool IsParameterFromWhere(const TableID ¶ms_table); }; + } // namespace core } // namespace Tianmu diff --git a/storage/tianmu/core/query_compile.cpp b/storage/tianmu/core/query_compile.cpp index 778e686ae..90f579c59 100644 --- a/storage/tianmu/core/query_compile.cpp +++ b/storage/tianmu/core/query_compile.cpp @@ -194,7 +194,7 @@ Query_route_to Query::FieldUnmysterify(Item *item, const char *&database_name, c return Query_route_to::TO_TIANMU; } -bool Query::FieldUnmysterify(Item *item, TabID &tab, AttrID &col) { +bool Query::FieldUnmysterify(Item *item, TableID &tab, AttrID &col) { Item_field *ifield; if (item->type() == Item_tianmufield::get_tianmuitem_type()) { ifield = dynamic_cast(item)->OriginalItem(); @@ -259,7 +259,7 @@ bool Query::FieldUnmysterify(Item *item, TabID &tab, AttrID &col) { if (it == table_alias2index_ptr.end()) return false; for (; it != it_end; it++) { TABLE *mysql_table = it->second.second; - tab = TabID(it->second.first); + tab = TableID(it->second.first); if (ifield->field->table != mysql_table) continue; // FIXME: is this correct? @@ -283,8 +283,8 @@ bool Query::FieldUnmysterify(Item *item, TabID &tab, AttrID &col) { } // stonedb8 start fix List to mem_root_deque #49 TODO -Query_route_to Query::AddJoins(mem_root_deque join, /*List &join,*/ TabID &tmp_table, - std::vector &left_tables, std::vector &right_tables, bool in_subquery, +Query_route_to Query::AddJoins(mem_root_deque join, /*List &join,*/ TableID &tmp_table, + std::vector &left_tables, std::vector &right_tables, bool in_subquery, bool &first_table /*= true*/, bool for_subq_in_where /*false*/) { // on first call first_table = true. It indicates if it is the first table to // be added is_left is true iff it is nested left join which needs to be @@ -309,7 +309,7 @@ Query_route_to Query::AddJoins(mem_root_deque join, /*Listnested_join) { - std::vector local_left, local_right; + std::vector local_left, local_right; if (AddJoins(join_ptr->nested_join->join_list, tmp_table, local_left, local_right, in_subquery, first_table, for_subq_in_where) == Query_route_to::TO_MYSQL) return Query_route_to::TO_MYSQL; @@ -338,7 +338,7 @@ Query_route_to Query::AddJoins(mem_root_deque join, /*Listis_view_or_derived()) { if (Compile(cq, join_ptr->derived_query_expression()->first_query_block(), @@ -353,7 +353,7 @@ Query_route_to Query::AddJoins(mem_root_deque join, /*ListGetID(); - cq->TableAlias(tab, TabID(tab_num), table_name, id); + cq->TableAlias(tab, TableID(tab_num), table_name, id); } std::string ext_alias = std::string(table_name ? table_name : "") + std::string(":") + std::string(table_alias); @@ -392,7 +392,7 @@ Query_route_to Query::AddJoins(mem_root_deque join, /*List &fields, TabID const &tmp_table, bool const group_by_clause, +Query_route_to Query::AddFields(mem_root_deque &fields, TableID const &tmp_table, bool const group_by_clause, int &num_of_added_fields, bool ignore_minmax, bool &aggregation_used) { Item *item; int added = 0; @@ -481,7 +481,7 @@ Query_route_to Query::AddFields(mem_root_deque &fields, TabID const &tmp return Query_route_to::TO_TIANMU; } -Query_route_to Query::AddGroupByFields(ORDER *group_by, const TabID &tmp_table) { +Query_route_to Query::AddGroupByFields(ORDER *group_by, const TableID &tmp_table) { for (; group_by; group_by = group_by->next) { if (group_by->direction != ORDER_NOT_RELEVANT) { my_message(ER_SYNTAX_ERROR, @@ -517,7 +517,7 @@ Query_route_to Query::AddGroupByFields(ORDER *group_by, const TabID &tmp_table) return Query_route_to::TO_TIANMU; } -Query_route_to Query::AddOrderByFields(ORDER *order_by, TabID const &tmp_table, int const group_by_clause) { +Query_route_to Query::AddOrderByFields(ORDER *order_by, TableID const &tmp_table, int const group_by_clause) { for (; order_by; order_by = order_by->next) { std::pair vc; Item *item = *(order_by->item); @@ -592,7 +592,7 @@ Query_route_to Query::AddOrderByFields(ORDER *order_by, TabID const &tmp_table, return Query_route_to::TO_TIANMU; } -Query_route_to Query::AddGlobalOrderByFields(SQL_I_List *global_order, const TabID &tmp_table, int max_col) { +Query_route_to Query::AddGlobalOrderByFields(SQL_I_List *global_order, const TableID &tmp_table, int max_col) { if (!global_order) return Query_route_to::TO_TIANMU; ORDER *order_by; @@ -631,8 +631,8 @@ Query_route_to Query::AddGlobalOrderByFields(SQL_I_List *global_order, co return Query_route_to::TO_TIANMU; } -Query::WrapStatus Query::WrapMysqlExpression(Item *item, const TabID &tmp_table, MysqlExpression *&expr, bool in_where, - bool aggr_used) { +Query::WrapStatus Query::WrapMysqlExpression(Item *item, const TableID &tmp_table, MysqlExpression *&expr, + bool in_where, bool aggr_used) { // Check if the expression doesn't contain any strange items that we don't // want to see. By the way, collect references to all Item_field objects. std::set ifields; @@ -652,12 +652,12 @@ Query::WrapStatus Query::WrapMysqlExpression(Item *item, const TabID &tmp_table, return WrapStatus::FAILURE; } AttrID col, at; - TabID tab; + TableID tab; // find [tab] and [col] which identify column in TIANMU if (!FieldUnmysterify(it, tab, col)) return WrapStatus::FAILURE; if (!cq->ExistsInTempTable(tab, tmp_table)) { bool is_group_by; - TabID params_table = cq->FindSourceOfParameter(tab, tmp_table, is_group_by); + TableID params_table = cq->FindSourceOfParameter(tab, tmp_table, is_group_by); common::ColOperation oper; bool distinct; if (OperationUnmysterify(it, oper, distinct, true) == Query_route_to::TO_MYSQL) return WrapStatus::FAILURE; @@ -690,7 +690,7 @@ Query::WrapStatus Query::WrapMysqlExpression(Item *item, const TabID &tmp_table, if (OperationUnmysterify(aggregation, oper, distinct, true) == Query_route_to::TO_MYSQL) return WrapStatus::FAILURE; AttrID col; - TabID tab; + TableID tab; if (IsFieldItem(aggregation->get_arg(0)) && FieldUnmysterify(aggregation, tab, col) && cq->ExistsInTempTable(tab, tmp_table)) { // PHYSICAL COLUMN @@ -705,11 +705,11 @@ Query::WrapStatus Query::WrapMysqlExpression(Item *item, const TabID &tmp_table, item2varid[it] = VarID(tmp_table.n, at.n); } else if (IsFieldItem(it)) { AttrID col; - TabID tab; + TableID tab; if (!FieldUnmysterify(it, tab, col)) return WrapStatus::FAILURE; if (!cq->ExistsInTempTable(tab, tmp_table)) { bool is_group_by; - TabID params_table = cq->FindSourceOfParameter(tab, tmp_table, is_group_by); + TableID params_table = cq->FindSourceOfParameter(tab, tmp_table, is_group_by); common::ColOperation oper; bool distinct; if (OperationUnmysterify(it, oper, distinct, true) == Query_route_to::TO_MYSQL) return WrapStatus::FAILURE; @@ -735,11 +735,11 @@ Query::WrapStatus Query::WrapMysqlExpression(Item *item, const TabID &tmp_table, return WrapStatus::SUCCESS; } -int Query::AddColumnForPhysColumn(Item *item, const TabID &tmp_table, const common::ColOperation oper, +int Query::AddColumnForPhysColumn(Item *item, const TableID &tmp_table, const common::ColOperation oper, const bool distinct, bool group_by, const char *alias) { std::pair vc; AttrID col, at; - TabID tab; + TableID tab; if (!FieldUnmysterify(item, tab, col)) return common::NULL_VALUE_32; if (tab.n == common::NULL_VALUE_32) tab = tmp_table; // table name not contained in item - must be the result @@ -794,14 +794,14 @@ int Query::AddColumnForPhysColumn(Item *item, const TabID &tmp_table, const comm return at.n; } -int Query::AddColumnForMysqlExpression(MysqlExpression *mysql_expression, const TabID &tmp_table, const char *alias, +int Query::AddColumnForMysqlExpression(MysqlExpression *mysql_expression, const TableID &tmp_table, const char *alias, const common::ColOperation oper, const bool distinct, bool group_by /*= false*/) { AttrID at, vc; vc.n = VirtualColumnAlreadyExists(tmp_table, mysql_expression); if (vc.n == common::NULL_VALUE_32) { cq->CreateVirtualColumn(vc, tmp_table, mysql_expression, - (oper == common::ColOperation::DELAYED ? tmp_table : TabID(common::NULL_VALUE_32))); + (oper == common::ColOperation::DELAYED ? tmp_table : TableID(common::NULL_VALUE_32))); tab_id2expression.insert(std::make_pair(tmp_table, std::make_pair(vc.n, mysql_expression))); } else { mysql_expression->RemoveUnusedVarID(); @@ -833,16 +833,16 @@ int Query::AddColumnForMysqlExpression(MysqlExpression *mysql_expression, const return at.n; } -bool Query::IsLocalColumn(Item *item, const TabID &tmp_table) { +bool Query::IsLocalColumn(Item *item, const TableID &tmp_table) { DEBUG_ASSERT(IsFieldItem(item) || IsAggregationItem(item)); AttrID col; - TabID tab; + TableID tab; if (!FieldUnmysterify(item, tab, col)) return false; return cq->ExistsInTempTable(tab, tmp_table); } Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *selects_list, Query_block *last_distinct, - TabID *res_tab, bool ignore_limit, Item *left_expr_for_subselect, + TableID *res_tab, bool ignore_limit, Item *left_expr_for_subselect, common::Operator *oper_for_subselect, bool ignore_minmax, bool for_subq_in_where) { MEASURE_FET("Query::Compile(...)"); // at this point all tables are in RCBase engine, so we can proceed with the @@ -907,7 +907,7 @@ Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *select */ bool union_all = (last_distinct == NULL); - TabID prev_result; + TableID prev_result; SQL_I_List *global_order = NULL; int col_count = 0; @@ -957,7 +957,7 @@ Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *select Item *cond_to_reinsert = NULL; List *list_to_reinsert = NULL; - TabID tmp_table; + TableID tmp_table; try { // partial optimization of LOJ conditions, JOIN::optimize(part=3) // necessary due to already done basic transformation of conditions @@ -986,7 +986,7 @@ Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *select } } - std::vector left_tables, right_tables; + std::vector left_tables, right_tables; bool first_table = true; // stonedb8 if (AddJoins(*sl->join_list, tmp_table, left_tables, right_tables, (res_tab != NULL && res_tab->n != 0), @@ -1034,7 +1034,7 @@ Query_route_to Query::Compile(CompiledQuery *compiled_query, Query_block *select prev_result = tmp_table; if (global_order && !selects_list->next_query_block()) { // trivial union with one select and // ext. order by - tmp_table = TabID(); + tmp_table = TableID(); cq->Union(prev_result, prev_result, tmp_table, true); } } else diff --git a/storage/tianmu/core/rcattr_exeq_rs.cpp b/storage/tianmu/core/rcattr_exeq_rs.cpp index 4e96070f1..b05786c0f 100644 --- a/storage/tianmu/core/rcattr_exeq_rs.cpp +++ b/storage/tianmu/core/rcattr_exeq_rs.cpp @@ -16,7 +16,7 @@ */ // This is a part of RCAttr implementation concerned with the KNs and its usage -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/engine.h" #include "core/pack.h" #include "core/pack_guardian.h" diff --git a/storage/tianmu/core/rcattr_exqp.cpp b/storage/tianmu/core/rcattr_exqp.cpp index 9cfc532f3..7759c6d94 100644 --- a/storage/tianmu/core/rcattr_exqp.cpp +++ b/storage/tianmu/core/rcattr_exqp.cpp @@ -21,7 +21,7 @@ */ #include "common/assert.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/pack_guardian.h" #include "core/pack_str.h" #include "core/rc_attr.h" diff --git a/storage/tianmu/core/rough_multi_index.h b/storage/tianmu/core/rough_multi_index.h index ce2a21a1e..1223a8fff 100644 --- a/storage/tianmu/core/rough_multi_index.h +++ b/storage/tianmu/core/rough_multi_index.h @@ -19,7 +19,7 @@ #pragma once #include "core/bin_tools.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/filter.h" namespace Tianmu { diff --git a/storage/tianmu/core/temp_table.cpp b/storage/tianmu/core/temp_table.cpp index 846ce0d60..ce3f02b52 100644 --- a/storage/tianmu/core/temp_table.cpp +++ b/storage/tianmu/core/temp_table.cpp @@ -1106,13 +1106,13 @@ void TempTable::AddConds(Condition *cond, CondType type) { DEBUG_ASSERT(0); } -void TempTable::AddInnerConds(Condition *cond, std::vector &dim_aliases) { +void TempTable::AddInnerConds(Condition *cond, std::vector &dim_aliases) { for (uint i = 0; i < cond->Size(); i++) for (uint j = 0; j < dim_aliases.size(); j++) (*cond)[i].left_dims[GetDimension(dim_aliases[j])] = true; filter.AddConditions(cond); } -void TempTable::AddLeftConds(Condition *cond, std::vector &left_aliases, std::vector &right_aliases) { +void TempTable::AddLeftConds(Condition *cond, std::vector &left_aliases, std::vector &right_aliases) { for (uint i = 0; i < cond->Size(); i++) { for (int d = 0; d < (*cond)[i].left_dims.Size(); d++) (*cond)[i].left_dims[d] = (*cond)[i].right_dims[d] = false; for (uint j = 0; j < left_aliases.size(); j++) (*cond)[i].left_dims[GetDimension(left_aliases[j])] = true; @@ -1536,7 +1536,7 @@ void TempTable::Display(std::ostream &out) { out << "-----------" << system::endl; } -int TempTable::GetDimension(TabID alias) { +int TempTable::GetDimension(TableID alias) { for (uint i = 0; i < aliases.size(); i++) { if (aliases[i] == alias.n) return i; } diff --git a/storage/tianmu/core/temp_table.h b/storage/tianmu/core/temp_table.h index 8bab2ba3e..92cce907d 100644 --- a/storage/tianmu/core/temp_table.h +++ b/storage/tianmu/core/temp_table.h @@ -21,7 +21,7 @@ #include #include "common/common_definitions.h" -#include "core/cq_term.h" +#include "core/compiled_query_term.h" #include "core/descriptor.h" #include "core/just_a_table.h" #include "core/mi_updating_iterator.h" @@ -201,8 +201,8 @@ class TempTable : public JustATable { void TranslateBackVCs(); // Query execution (CompiledQuery language implementation) void AddConds(Condition *cond, CondType type); - void AddInnerConds(Condition *cond, std::vector &dims); - void AddLeftConds(Condition *cond, std::vector &dims1, std::vector &dims2); + void AddInnerConds(Condition *cond, std::vector &dims); + void AddLeftConds(Condition *cond, std::vector &dims1, std::vector &dims2); void SetMode(TMParameter mode, int64_t mode_param1 = 0, int64_t mode_param2 = -1); void JoinT(JustATable *t, int alias, JoinType jt); int AddColumn(CQTerm, common::ColOperation, char *alias, bool distinct, SI si); @@ -274,7 +274,7 @@ class TempTable : public JustATable { } uint NumOfDimensions() { return filter.mind ? (uint)filter.mind->NumOfDimensions() : 1; } - int GetDimension(TabID alias); + int GetDimension(TableID alias); std::vector GetATIs(bool orig = false) override; int GetAttrScale(int a) { DEBUG_ASSERT(a >= 0 && (uint)a < NumOfAttrs()); diff --git a/storage/tianmu/handler/ha_tianmu.cpp b/storage/tianmu/handler/ha_tianmu.cpp index 15d207b55..2a8bb6fce 100644 --- a/storage/tianmu/handler/ha_tianmu.cpp +++ b/storage/tianmu/handler/ha_tianmu.cpp @@ -1376,9 +1376,9 @@ const Item *TianmuHandler::cond_push(const Item *a_cond) { m_result = false; m_query->AddTable(rctp); - core::TabID t_out; + core::TableID t_out; m_cq->TableAlias(t_out, - core::TabID(0)); // we apply it to the only table in this query + core::TableID(0)); // we apply it to the only table in this query m_cq->TmpTable(m_tmp_table, t_out); std::string ext_alias; @@ -1391,7 +1391,7 @@ const Item *TianmuHandler::cond_push(const Item *a_cond) { int col_no = 0; core::AttrID col, vc; - core::TabID tab(m_tmp_table); + core::TableID tab(m_tmp_table); my_bitmap_map *org_bitmap = dbug_tmp_use_all_columns(table, table->read_set); for (Field **field = table->field; *field; field++) { diff --git a/storage/tianmu/handler/ha_tianmu.h b/storage/tianmu/handler/ha_tianmu.h index 6813a7225..74ee38de1 100644 --- a/storage/tianmu/handler/ha_tianmu.h +++ b/storage/tianmu/handler/ha_tianmu.h @@ -184,7 +184,7 @@ class TianmuHandler final : public handler { core::RCTable::Iterator table_new_iter_end; std::unique_ptr m_query; - core::TabID m_tmp_table; + core::TableID m_tmp_table; std::unique_ptr m_cq; bool m_result = false; std::vector> blob_buffers;