Skip to content

Commit

Permalink
修复负号解析的时候right_被使用的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
HuXin0817 committed Oct 12, 2024
1 parent 9b9ea84 commit 134e8b0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
22 changes: 13 additions & 9 deletions src/observer/sql/expr/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ RC ComparisonExpr::get_value(const Tuple &tuple, Value &value)
return rc;
}
DEFER(if (nullptr != left_subquery_expr) left_subquery_expr->close();
if (nullptr != right_subquery_expr) right_subquery_expr->close(););
if (nullptr != right_subquery_expr) right_subquery_expr->close(););

// Get the value of the left expression
rc = left_->get_value(tuple, left_value);
Expand Down Expand Up @@ -560,15 +560,19 @@ RC ArithmeticExpr::get_value(const Tuple &tuple, Value &value)
Value left_value;
Value right_value;

rc = left_->get_value(tuple, left_value);
if (rc != RC::SUCCESS) {
LOG_WARN("failed to get value of left expression. rc=%s", strrc(rc));
return rc;
if (left_) {
rc = left_->get_value(tuple, left_value);
if (rc != RC::SUCCESS) {
LOG_WARN("failed to get value of left expression. rc=%s", strrc(rc));
return rc;
}
}
rc = right_->get_value(tuple, right_value);
if (rc != RC::SUCCESS) {
LOG_WARN("failed to get value of right expression. rc=%s", strrc(rc));
return rc;
if (right_) {
rc = right_->get_value(tuple, right_value);
if (rc != RC::SUCCESS) {
LOG_WARN("failed to get value of right expression. rc=%s", strrc(rc));
return rc;
}
}
return calc_value(left_value, right_value, value);
}
Expand Down
26 changes: 10 additions & 16 deletions src/observer/sql/parser/expression_binder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,14 +300,11 @@ RC ExpressionBinder::bind_comparison_expression(
return rc;
}

if (child_bound_expressions.size() != 1) {
LOG_WARN("invalid right children number of comparison expression: %d", child_bound_expressions.size());
return RC::INVALID_ARGUMENT;
}

unique_ptr<Expression> &right = child_bound_expressions[0];
if (right.get() != right_expr.get()) {
right_expr = std::move(right);
if (child_bound_expressions.size() == 1) {
unique_ptr<Expression> &right = child_bound_expressions[0];
if (right.get() != right_expr.get()) {
right_expr = std::move(right);
}
}

bound_expressions.emplace_back(std::move(expr));
Expand Down Expand Up @@ -384,14 +381,11 @@ RC ExpressionBinder::bind_arithmetic_expression(
return rc;
}

if (child_bound_expressions.size() != 1) {
LOG_WARN("invalid right children number of comparison expression: %d", child_bound_expressions.size());
return RC::INVALID_ARGUMENT;
}

unique_ptr<Expression> &right = child_bound_expressions[0];
if (right.get() != right_expr.get()) {
right_expr = std::move(right);
if (child_bound_expressions.size() == 1) {
unique_ptr<Expression> &right = child_bound_expressions[0];
if (right.get() != right_expr.get()) {
right_expr = std::move(right);
}
}

bound_expressions.emplace_back(std::move(expr));
Expand Down

0 comments on commit 134e8b0

Please sign in to comment.