feat: add the rule to use-das when has variable assignments in sql

Co-authored-by: leslieyuchen <leslieyuchen@gmail.com>
This commit is contained in:
obdev
2023-10-23 09:14:02 +00:00
committed by ob-robot
parent a46ee110fb
commit bacc417957
23 changed files with 170 additions and 18 deletions

View File

@ -39,7 +39,17 @@ int ObRawExprInfoExtractor::visit(ObConstRawExpr &expr)
int ret = OB_SUCCESS;
ObItemType type = expr.get_expr_type();
switch (type) {
//case T_USER_VARIABLE_IDENTIFIER:
case T_USER_VARIABLE_IDENTIFIER: {
ObUserVarIdentRawExpr &var_expr = static_cast<ObUserVarIdentRawExpr&>(expr);
if (var_expr.get_is_contain_assign() || var_expr.get_query_has_udf()) {
if (OB_FAIL(var_expr.add_flag(IS_DYNAMIC_USER_VARIABLE))) {
LOG_WARN("add flag to user var ident raw expr failed", KR(ret));
}
} else if (OB_FAIL(var_expr.add_flag(IS_CONST))) {
LOG_WARN("failed to add flag IS_CONST", K(ret));
}
break;
}
case T_SYSTEM_VARIABLE:
case T_QUESTIONMARK: {
if (OB_FAIL(expr.add_flag(IS_STATIC_PARAM))) {
@ -58,10 +68,8 @@ int ObRawExprInfoExtractor::visit(ObConstRawExpr &expr)
default:
break;
}
if (OB_SUCC(ret)) {
if (OB_FAIL(ret)) {
// do nothing
} else if (OB_FAIL(expr.add_flag(IS_CONST))) {
if (OB_SUCC(ret) && T_USER_VARIABLE_IDENTIFIER != type) {
if (OB_FAIL(expr.add_flag(IS_CONST))) {
LOG_WARN("failed to add flag IS_CONST", K(ret));
}
}

View File

@ -3340,6 +3340,29 @@ int ObRawExprUtils::extract_set_op_exprs(const ObRawExpr *raw_expr,
return ret;
}
int ObRawExprUtils::extract_var_assign_exprs(const ObRawExpr *raw_expr,
ObIArray<ObRawExpr*> &assign_exprs)
{
int ret = OB_SUCCESS;
if (OB_ISNULL(raw_expr)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid raw expr", K(ret), K(raw_expr));
} else if (raw_expr->has_flag(IS_ASSIGN_EXPR) && raw_expr->get_relation_ids().is_empty()) {
if (OB_FAIL(add_var_to_array_no_dup(assign_exprs, const_cast<ObRawExpr*>(raw_expr)))) {
LOG_WARN("failed to append expr", K(ret));
}
} else {
int64_t N = raw_expr->get_param_count();
for (int64_t i = 0; OB_SUCC(ret) && i < N; ++i) {
if (OB_FAIL(SMART_CALL(extract_var_assign_exprs(raw_expr->get_param_expr(i),
assign_exprs)))) {
LOG_WARN("failed to extract var assign op exprs", K(ret));
}
}
}
return ret;
}
int ObRawExprUtils::extract_set_op_exprs(const ObIArray<ObRawExpr*> &exprs,
common::ObIArray<ObRawExpr*> &set_op_exprs)
{

View File

@ -385,6 +385,8 @@ public:
static bool is_all_column_exprs(const common::ObIArray<ObRawExpr*> &exprs);
static int extract_set_op_exprs(const ObRawExpr *raw_expr,
common::ObIArray<ObRawExpr*> &set_op_exprs);
static int extract_var_assign_exprs(const ObRawExpr *raw_expr,
common::ObIArray<ObRawExpr*> &assign_exprs);
static int extract_set_op_exprs(const ObIArray<ObRawExpr*> &exprs,
common::ObIArray<ObRawExpr*> &set_op_exprs);
/// extract column exprs from the raw expr