fix illegal constraints added by simplify_case_when under oracle mode
This commit is contained in:
@ -146,6 +146,7 @@ struct ObGlobalHint {
|
|||||||
//#define COMPAT_VERSION_4_2_1_BP3 (oceanbase::common::cal_version(4, 2, 1, 3))
|
//#define COMPAT_VERSION_4_2_1_BP3 (oceanbase::common::cal_version(4, 2, 1, 3))
|
||||||
#define COMPAT_VERSION_4_2_1_BP4 (oceanbase::common::cal_version(4, 2, 1, 4))
|
#define COMPAT_VERSION_4_2_1_BP4 (oceanbase::common::cal_version(4, 2, 1, 4))
|
||||||
#define COMPAT_VERSION_4_2_2 (oceanbase::common::cal_version(4, 2, 2, 0))
|
#define COMPAT_VERSION_4_2_2 (oceanbase::common::cal_version(4, 2, 2, 0))
|
||||||
|
#define COMPAT_VERSION_4_2_3 (oceanbase::common::cal_version(4, 2, 3, 0))
|
||||||
#define COMPAT_VERSION_4_3_0 (oceanbase::common::cal_version(4, 3, 0, 0))
|
#define COMPAT_VERSION_4_3_0 (oceanbase::common::cal_version(4, 3, 0, 0))
|
||||||
#define LASTED_COMPAT_VERSION COMPAT_VERSION_4_3_0
|
#define LASTED_COMPAT_VERSION COMPAT_VERSION_4_3_0
|
||||||
static bool is_valid_opt_features_version(uint64_t version)
|
static bool is_valid_opt_features_version(uint64_t version)
|
||||||
|
@ -28,18 +28,26 @@ int ObTransformSimplifyExpr::transform_one_stmt(common::ObIArray<ObParentDMLStmt
|
|||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
bool is_happened = false;
|
bool is_happened = false;
|
||||||
UNUSED(parent_stmts);
|
UNUSED(parent_stmts);
|
||||||
if (OB_FAIL(flatten_stmt_exprs(stmt, is_happened))) {
|
if (OB_ISNULL(stmt) || OB_ISNULL(stmt->get_query_ctx())) {
|
||||||
LOG_WARN("failed to flatten stmt exprs", K(is_happened));
|
ret = OB_ERR_UNEXPECTED;
|
||||||
} else {
|
LOG_WARN("unexpected null pointer", K(ret), K(stmt));
|
||||||
trans_happened |= is_happened;
|
|
||||||
LOG_TRACE("succeed to flatten stmt exprs", K(is_happened));
|
|
||||||
}
|
}
|
||||||
if (OB_FAIL(replace_is_null_condition(stmt, is_happened))) {
|
if (OB_SUCC(ret)) {
|
||||||
LOG_WARN("failed to replace is null condition", K(is_happened));
|
if (OB_FAIL(flatten_stmt_exprs(stmt, is_happened))) {
|
||||||
} else {
|
LOG_WARN("failed to flatten stmt exprs", K(is_happened));
|
||||||
trans_happened |= is_happened;
|
} else {
|
||||||
OPT_TRACE("replace is null condition:", is_happened);
|
trans_happened |= is_happened;
|
||||||
LOG_TRACE("succeed to replace is null condition", K(is_happened));
|
LOG_TRACE("succeed to flatten stmt exprs", K(is_happened));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (OB_SUCC(ret)) {
|
||||||
|
if (OB_FAIL(replace_is_null_condition(stmt, is_happened))) {
|
||||||
|
LOG_WARN("failed to replace is null condition", K(is_happened));
|
||||||
|
} else {
|
||||||
|
trans_happened |= is_happened;
|
||||||
|
OPT_TRACE("replace is null condition:", is_happened);
|
||||||
|
LOG_TRACE("succeed to replace is null condition", K(is_happened));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (OB_SUCC(ret)) {
|
if (OB_SUCC(ret)) {
|
||||||
if (OB_FAIL(replace_op_null_condition(stmt, is_happened))) {
|
if (OB_FAIL(replace_op_null_condition(stmt, is_happened))) {
|
||||||
@ -113,7 +121,8 @@ int ObTransformSimplifyExpr::transform_one_stmt(common::ObIArray<ObParentDMLStmt
|
|||||||
LOG_TRACE("succeed to remove subquery when filter is false", K(is_happened));
|
LOG_TRACE("succeed to remove subquery when filter is false", K(is_happened));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (OB_SUCC(ret)) {
|
if (OB_SUCC(ret) &&
|
||||||
|
stmt->get_query_ctx()->optimizer_features_enable_version_ >= COMPAT_VERSION_4_2_3) {
|
||||||
if (OB_FAIL(convert_case_when_predicate(stmt, is_happened))) {
|
if (OB_FAIL(convert_case_when_predicate(stmt, is_happened))) {
|
||||||
LOG_WARN("failed to convert case when predicate", K(ret));
|
LOG_WARN("failed to convert case when predicate", K(ret));
|
||||||
} else {
|
} else {
|
||||||
@ -3842,23 +3851,27 @@ int ObTransformSimplifyExpr::add_constraint_for_convert_case_when_by_then(ObIArr
|
|||||||
if (OB_ISNULL(ctx_)) {
|
if (OB_ISNULL(ctx_)) {
|
||||||
ret = OB_ERR_UNEXPECTED;
|
ret = OB_ERR_UNEXPECTED;
|
||||||
LOG_WARN("unexpected param is NULL",K(ret));
|
LOG_WARN("unexpected param is NULL",K(ret));
|
||||||
} else if (false_null_exprs.count() == 0) {
|
}
|
||||||
// do nothing
|
|
||||||
} else if (OB_FAIL(build_nvl_bool_exprs(false_null_exprs, false))) {
|
for (int64_t i = 0; OB_SUCC(ret) && i < false_null_exprs.count(); i++) {
|
||||||
LOG_WARN("failed to build nvl bool exprs",K(ret));
|
ObRawExpr *lnnvl_expr = NULL;
|
||||||
} else if (OB_FAIL(ObRawExprUtils::build_or_exprs(*ctx_->expr_factory_,
|
if (OB_ISNULL(false_null_exprs.at(i))) {
|
||||||
false_null_exprs,
|
ret = OB_ERR_UNEXPECTED;
|
||||||
false_cons_expr))) {
|
LOG_WARN("unexpected null expr", K(ret));
|
||||||
LOG_WARN("failed to build or expr", K(ret));
|
} else if (OB_FAIL(ObRawExprUtils::build_lnnvl_expr(*ctx_->expr_factory_,
|
||||||
} else if (OB_ISNULL(false_cons_expr)) {
|
false_null_exprs.at(i),
|
||||||
ret = OB_ERR_UNEXPECTED;
|
lnnvl_expr))) {
|
||||||
LOG_WARN("unexpected null expr", K(ret));
|
LOG_WARN("failed to build lnnvl expr", K(ret));
|
||||||
} else if (OB_FAIL(false_cons_expr->formalize(ctx_->session_info_))) {
|
} else if (OB_ISNULL(lnnvl_expr)) {
|
||||||
LOG_WARN("failed to formalize expr", K(ret), K(false_cons_expr));
|
ret = OB_ERR_UNEXPECTED;
|
||||||
} else {
|
LOG_WARN("unexpected null expr", K(ret));
|
||||||
ObExprConstraint false_cons(false_cons_expr, PreCalcExprExpectResult::PRE_CALC_RESULT_FALSE);
|
} else if (OB_FAIL(lnnvl_expr->formalize(ctx_->session_info_))) {
|
||||||
if (OB_FAIL(ctx_->expr_constraints_.push_back(false_cons))) {
|
LOG_WARN("failed to formalize expr", K(ret), K(lnnvl_expr));
|
||||||
LOG_WARN("failed to push back constraints");
|
} else {
|
||||||
|
ObExprConstraint true_cons(lnnvl_expr, PreCalcExprExpectResult::PRE_CALC_RESULT_TRUE);
|
||||||
|
if (OB_FAIL(ctx_->expr_constraints_.push_back(true_cons))) {
|
||||||
|
LOG_WARN("failed to push back expr constraints", K(ret));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3875,49 +3888,3 @@ int ObTransformSimplifyExpr::add_constraint_for_convert_case_when_by_then(ObIArr
|
|||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ObTransformSimplifyExpr::build_nvl_bool_exprs(ObIArray<ObRawExpr*> &exprs,
|
|
||||||
const bool boolean) {
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
ObRawExpr *nvl_bool_expr = NULL;
|
|
||||||
ObSEArray<ObRawExpr *, 4> tmp_exprs;
|
|
||||||
for (int64_t i = 0; OB_SUCC(ret) && i < exprs.count(); ++i) {
|
|
||||||
if (OB_FAIL(build_nvl_bool_expr(exprs.at(i), boolean, nvl_bool_expr))) {
|
|
||||||
LOG_WARN("failed to build nvl bool expr", K(ret));
|
|
||||||
} else if (OB_FAIL(tmp_exprs.push_back(nvl_bool_expr))) {
|
|
||||||
LOG_WARN("failed to push back nvl bool expr", K(ret));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (OB_FAIL(ret)) {
|
|
||||||
} else if (OB_FAIL(exprs.assign(tmp_exprs))) {
|
|
||||||
LOG_WARN("failed to assign exprs", K(ret));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int ObTransformSimplifyExpr::build_nvl_bool_expr(ObRawExpr *expr,
|
|
||||||
const bool is_true,
|
|
||||||
ObRawExpr *&nvl_expr) {
|
|
||||||
int ret = OB_SUCCESS;
|
|
||||||
ObRawExpr *true_false_expr = NULL;
|
|
||||||
nvl_expr = NULL;
|
|
||||||
if (OB_ISNULL(expr) || OB_ISNULL(ctx_)) {
|
|
||||||
ret = OB_ERR_UNEXPECTED;
|
|
||||||
LOG_WARN("unexpected param is NULL", K(ret));
|
|
||||||
} else if (OB_FAIL(ObRawExprUtils::build_const_bool_expr(
|
|
||||||
ctx_->expr_factory_,
|
|
||||||
true_false_expr, is_true))) {
|
|
||||||
LOG_WARN("failed to build const bool expr", K(ret));
|
|
||||||
} else if (OB_FAIL(ObRawExprUtils::build_nvl_expr(*ctx_->expr_factory_,
|
|
||||||
expr,
|
|
||||||
true_false_expr,
|
|
||||||
nvl_expr))) {
|
|
||||||
LOG_WARN("failed to build nvl expr", K(ret));
|
|
||||||
} else if (OB_ISNULL(nvl_expr)) {
|
|
||||||
ret = OB_ERR_UNEXPECTED;
|
|
||||||
LOG_WARN("unexpected nvl expr is NULL", K(ret));
|
|
||||||
} else if (OB_FAIL(nvl_expr->formalize(ctx_->session_info_))) {
|
|
||||||
LOG_WARN("failed to formalize nvl expr", K(ret));
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
@ -224,8 +224,6 @@ private:
|
|||||||
ObIArray<ObRawExpr*> &extracted_preds);
|
ObIArray<ObRawExpr*> &extracted_preds);
|
||||||
int add_constraint_for_convert_case_when_by_then(ObIArray<ObRawExpr *> &false_null_exprs,
|
int add_constraint_for_convert_case_when_by_then(ObIArray<ObRawExpr *> &false_null_exprs,
|
||||||
ObIArray<ObRawExpr *> &true_exprs);
|
ObIArray<ObRawExpr *> &true_exprs);
|
||||||
int build_nvl_bool_exprs(ObIArray<ObRawExpr *> &exprs, const bool boolean);
|
|
||||||
int build_nvl_bool_expr(ObRawExpr *expr, const bool boolean, ObRawExpr *&nvl_expr);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user