From b80fe7dba149a1c28309d47f9bde223b63e1cb93 Mon Sep 17 00:00:00 2001 From: wym <1057857414@qq.com> Date: Sun, 25 Jun 2023 07:18:57 -0700 Subject: [PATCH 1/2] 1 --- src/execution/executor_projection.h | 43 +++++++++++++++++------------ 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/src/execution/executor_projection.h b/src/execution/executor_projection.h index 7610136..e4b8177 100755 --- a/src/execution/executor_projection.h +++ b/src/execution/executor_projection.h @@ -15,9 +15,10 @@ See the Mulan PSL v2 for more details. */ #include "index/ix.h" #include "system/sm.h" -class ProjectionExecutor : public AbstractExecutor { - private: - std::unique_ptr<AbstractExecutor> prev_; // 投影节点的儿å节点 +class ProjectionExecutor : public AbstractExecutor +{ +private: + std::unique_ptr<AbstractExecutor> prev_; // 投影节点的儿å节点 /* 在查询执行计划ä¸ï¼ŒæŠ•å½±æ“作通常是ä½äºŽæŸ¥è¯¢è®¡åˆ’的顶层,它的作用是选择和投影出特定的列或å—段。 å节点是指在查询计划ä¸ä½äºŽæŠ•å½±æ“作之å‰çš„其他æ“作节点,它们的输出结果将作为投影æ“作的输入。 @@ -25,18 +26,20 @@ class ProjectionExecutor : public AbstractExecutor { å节点å¯ä»¥æ˜¯æ‰«ææ“作(如表扫æ或索引扫æ)ã€è¿‡æ»¤æ“作(如谓è¯è¿‡æ»¤ï¼‰æˆ–其他转æ¢æ“作(如连接ã€èšåˆç‰ï¼‰ã€‚ å节点的输出将作为投影æ“作的输入,投影æ“作将从å节点的输出ä¸é€‰æ‹©æŒ‡å®šçš„列,并进行投影æ“作,生æˆæœ€ç»ˆçš„结果。 */ - std::vector<ColMeta> cols_; // 需è¦æŠ•å½±çš„å—段 - size_t len_; // å—段总长度 + std::vector<ColMeta> cols_; // 需è¦æŠ•å½±çš„å—段 + size_t len_; // å—段总长度 std::vector<size_t> sel_idxs_; - std::unique_ptr<RmRecord> curr_record_; + std::unique_ptr<RmRecord> curr_record_; - public: - ProjectionExecutor(std::unique_ptr<AbstractExecutor> prev, const std::vector<TabCol> &sel_cols) { +public: + ProjectionExecutor(std::unique_ptr<AbstractExecutor> prev, const std::vector<TabCol> &sel_cols) + { prev_ = std::move(prev); size_t curr_offset = 0; auto &prev_cols = prev_->cols(); - for (auto &sel_col : sel_cols) { + for (auto &sel_col : sel_cols) + { auto pos = get_col(prev_cols, sel_col); sel_idxs_.push_back(pos - prev_cols.begin()); auto col = *pos; @@ -47,36 +50,42 @@ class ProjectionExecutor : public AbstractExecutor { len_ = curr_offset; } - void beginTuple() override { + void beginTuple() override + { prev_->beginTuple(); } - void nextTuple() override { + void nextTuple() override + { prev_->nextTuple(); curr_record_ = Next(); } - std::unique_ptr<RmRecord> Next() override { + std::unique_ptr<RmRecord> Next() override + { - if (curr_record_) { + if (curr_record_) + { return std::move(curr_record_); } std::unique_ptr<RmRecord> record = prev_->Next(); - if (record) { + if (record) + { // 创建一个å‘é‡æ¥å˜å‚¨æŠ•å½±åŽçš„è®°å½•æ•°æ® - char* data = new char[len_]; // 分é…å†…å˜ + char *data = new char[len_]; // 分é…å†…å˜ // é历选定的列,并å¤åˆ¶å¯¹åº”çš„æ•°æ® - for (size_t i = 0; i < sel_idxs_.size(); ++i) { + for (size_t i = 0; i < sel_idxs_.size(); ++i) + { size_t sel_idx = sel_idxs_[i]; size_t offset = cols_[i].offset; std::memcpy(data + offset, record->data + prev_->cols()[sel_idx].offset, cols_[i].len); } // 使用投影åŽçš„æ•°æ®åˆ›å»ºä¸€ä¸ªæ–°çš„ RmRecord,并返回它 - return std::make_unique<RmRecord>(len_,data); + return std::make_unique<RmRecord>(len_, data); } return nullptr; } -- GitLab From b027e8d67209b5f7746085b780e25561fa562f8e Mon Sep 17 00:00:00 2001 From: wym <1057857414@qq.com> Date: Sun, 25 Jun 2023 07:22:38 -0700 Subject: [PATCH 2/2] 111 --- src/execution/executor_seq_scan.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/execution/executor_seq_scan.h b/src/execution/executor_seq_scan.h index bf987d3..f1ed70a 100755 --- a/src/execution/executor_seq_scan.h +++ b/src/execution/executor_seq_scan.h @@ -108,6 +108,7 @@ class SeqScanExecutor : public AbstractExecutor { SmManager *sm_manager_; std::vector<ColMeta> cols_check_; // æ¡ä»¶è¯å¥ä¸æ‰€æœ‰ç”¨åˆ°åˆ—的列的元数æ®ä¿¡æ¯ + std::unordered_map<std::string, ColMeta> ColName_to_ColMeta_; public: SeqScanExecutor(SmManager *sm_manager, std::string tab_name, std::vector<Condition> conds, Context *context) { @@ -119,27 +120,26 @@ class SeqScanExecutor : public AbstractExecutor { cols_ = tab.cols; len_ = cols_.back().offset + cols_.back().len; //hashmap - std::unordered_map<std::string, ColMeta> ColName_to_ColMeta_=tab.ColName_to_ColMeta; + ColName_to_ColMeta_=tab.ColName_to_ColMeta; context_ = context; fed_conds_ = conds_;//åŽç»æŸ¥è¯¢ä¼˜åŒ–å¯ä»¥ä»Žfedcond入手!!!!!!!!!!!!!!!!!!! - //åˆå§‹åŒ–æ¡ä»¶è¯å¥ä¸æ‰€æœ‰ç”¨åˆ°åˆ—的列的元数æ®ä¿¡æ¯ - int i=0; - for (const auto& condition : fed_conds_) { + int con_size=fed_conds_.size(); + for (int loop=0;loop<con_size;loop++) { + auto temp_con=fed_conds_[loop]; // 检查左æ“作数是å¦ä¸ºåˆ—æ“作数 - if (!condition.lhs_col.tab_name.empty() && !condition.lhs_col.col_name.empty()) { + if (!temp_con.lhs_col.tab_name.empty() && !temp_con.lhs_col.col_name.empty()) { // 查找colmeta - ColMeta temp=ColName_to_ColMeta_[condition.lhs_col.col_name]; + ColMeta temp=ColName_to_ColMeta_[temp_con.lhs_col.col_name]; // 将元数æ®å¯¹è±¡æ·»åŠ 到列的元数æ®å‘é‡ä¸ cols_check_.push_back(temp); - } - + } // 检查å³æ“作数是å¦ä¸ºåˆ—æ“作数 - if (!condition.is_rhs_val && !condition.rhs_col.tab_name.empty() && !condition.rhs_col.col_name.empty()) { + if (!temp_con.is_rhs_val && !temp_con.rhs_col.tab_name.empty() && !temp_con.rhs_col.col_name.empty()) { // 查找colmeta - ColMeta temp=ColName_to_ColMeta_[condition.rhs_col.col_name]; + ColMeta temp=ColName_to_ColMeta_[temp_con.rhs_col.col_name]; // 将元数æ®å¯¹è±¡æ·»åŠ 到列的元数æ®å‘é‡ä¸ cols_check_.push_back(temp); } -- GitLab