Commit 567b771e authored by 甘仰发's avatar 甘仰发
Browse files

将连接条件和一般条件索引判断区分

Showing with 23 additions and 10 deletions
+23 -10
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -29,7 +29,7 @@ See the Mulan PSL v2 for more details. */
// 目前的索引匹配规则为:完全匹配索引字段,且全部为单点查询,不会自动调整where条件的顺序
bool Planner::get_index_cols(std::string tab_name, std::vector<Condition> curr_conds,
std::vector<std::string> &index_col_names) {
std::vector<std::string> &index_col_names, bool is_join_col) {
// 获取表的所有索引
auto &tab = sm_manager_->db_.get_table(tab_name);
auto &indexs = tab.indexes;
......@@ -53,13 +53,26 @@ bool Planner::get_index_cols(std::string tab_name, std::vector<Condition> curr_c
});
for (auto &cond : curr_conds) {
for (auto &col : index.cols) {
if ((cond.lhs_col.col_name.compare(col.name) == 0 && cond.is_rhs_val)
|| (!cond.is_rhs_val && cond.rhs_col.col_name.compare(col.name) == 0)) {
if (std::find(index_col_names.begin(), index_col_names.end(), col.name) != index_col_names.end()) {
continue;
/* 连接条件<col, col> */
if(is_join_col){
if ((cond.lhs_col.col_name.compare(col.name) == 0)
|| (!cond.is_rhs_val && cond.rhs_col.col_name.compare(col.name) == 0)) {
if (std::find(index_col_names.begin(), index_col_names.end(), col.name) != index_col_names.end()) {
continue;
}
index_col_names.push_back(col.name);
}
}
/* 一般条件<col, value> */
else{
if ((cond.lhs_col.col_name.compare(col.name) == 0 && cond.is_rhs_val)) {
if (std::find(index_col_names.begin(), index_col_names.end(), col.name) != index_col_names.end()) {
continue;
}
index_col_names.push_back(col.name);
}
index_col_names.push_back(col.name);
}
}
}
......@@ -250,8 +263,8 @@ std::shared_ptr<Plan> Planner::make_one_rel(std::shared_ptr<Query> query) {
std::vector<std::string> left_join_cols, right_join_cols;
auto left_tb = join_conds[0].lhs_col.tab_name;
auto right_tb = join_conds[0].rhs_col.tab_name;
bool left_index_exits = get_index_cols(left_tb, join_conds, left_join_cols);
bool right_index_exits = get_index_cols(right_tb, join_conds, right_join_cols);
bool left_index_exits = get_index_cols(left_tb, join_conds, left_join_cols, true);
bool right_index_exits = get_index_cols(right_tb, join_conds, right_join_cols, true);
if (left_index_exits && right_index_exits) {
// 两表的的连接字段均有索引。直接构造SortMergePlan
table_join_executors =
......
......@@ -61,8 +61,8 @@ private:
// int get_indexNo(std::string tab_name, std::vector<Condition> curr_conds);
bool get_index_cols(std::string tab_name, std::vector<Condition> curr_conds,
std::vector<std::string> &index_col_names);
bool get_index_cols(std::string tab_name, std::vector<Condition> curr_conds,
std::vector<std::string> &index_col_names, bool is_join_col = false);
ColType interp_sv_type(ast::SvType sv_type) {
std::map<ast::SvType, ColType> m = { { ast::SV_TYPE_INT, TYPE_INT },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment