Skip to content

Commit

Permalink
Enhancement
Browse files Browse the repository at this point in the history
  • Loading branch information
yixinglu committed Dec 3, 2022
1 parent f876e4f commit 332b6e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
10 changes: 1 addition & 9 deletions src/graph/optimizer/Optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,7 @@ Status rewriteArgumentInputVarInternal(PlanNode *root,
if (bpn->right() == path[i + 1]) {
// Argument is in the right side dependency of binary plan node, check the left child
// output columns
const auto &colNames = bpn->left()->colNames();
bool found = true;
for (const auto &col : root->colNames()) {
if (std::find(colNames.begin(), colNames.end(), col) == colNames.end()) {
found = false;
break;
}
}
if (found) {
if (root->isColumnsIncludedIn(bpn->left())) {
root->setInputVar(bpn->left()->outputVar());
break;
}
Expand Down
15 changes: 6 additions & 9 deletions src/graph/planner/plan/PlanNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,18 +354,15 @@ void PlanNode::setInputVar(const std::string& varname, size_t idx) {
}
}

Status PlanNode::isColumnsIncluded(const std::string& varname) const {
auto* refVar = qctx()->symTable()->getVar(varname);
// The referenced variable should have all columns used in current node
bool PlanNode::isColumnsIncludedIn(const PlanNode* other) const {
const auto& otherColNames = other->colNames();
for (auto& colName : colNames()) {
auto iter = std::find(refVar->colNames.begin(), refVar->colNames.end(), colName);
if (iter == refVar->colNames.end()) {
return Status::Error("the column referenced by Argument is not included in variable `%s': %s",
varname.c_str(),
colName.c_str());
auto iter = std::find(otherColNames.begin(), otherColNames.end(), colName);
if (iter == otherColNames.end()) {
return false;
}
}
return Status::OK();
return true;
}

std::unique_ptr<PlanNodeDescription> PlanNode::explain() const {
Expand Down
2 changes: 1 addition & 1 deletion src/graph/planner/plan/PlanNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ class PlanNode {
return static_cast<const T*>(this);
}

Status isColumnsIncluded(const std::string& varname) const;
bool isColumnsIncludedIn(const PlanNode* other) const;

protected:
PlanNode(QueryContext* qctx, Kind kind);
Expand Down

0 comments on commit 332b6e0

Please sign in to comment.