diff --git a/src/sql/rewrite/ob_transform_join_elimination.cpp b/src/sql/rewrite/ob_transform_join_elimination.cpp index e5097612bd..9b31cb732d 100644 --- a/src/sql/rewrite/ob_transform_join_elimination.cpp +++ b/src/sql/rewrite/ob_transform_join_elimination.cpp @@ -2074,22 +2074,20 @@ int ObTransformJoinElimination::trans_column_expr(ObDMLStmt* stmt, ObRawExpr* ex { int ret = OB_SUCCESS; new_expr = NULL; + bool is_nullable = false; if (OB_ISNULL(stmt) || OB_ISNULL(expr) || OB_ISNULL(ctx_)) { - LOG_WARN("param has null", K(ret)); + LOG_WARN("param has null", K(ret), K(stmt), K(expr), K(ctx_)); + } else if (OB_FAIL(ObTransformUtils::check_expr_nullable(stmt, expr, is_nullable, ObTransformUtils::NULLABLE_SCOPE::NS_FROM))) { + LOG_WARN("failed to check whether expr is nullable", K(ret)); + } else if (!is_nullable) { + if (OB_FAIL(ObRawExprUtils::build_const_bool_expr(ctx_->expr_factory_, new_expr, true))) { + LOG_WARN("build true expr failed", K(ret)); + } else { /*do nothing*/ + } } else { - bool is_nullable = false; - if (OB_FAIL(ObTransformUtils::check_expr_nullable(stmt, expr, is_nullable))) { - LOG_WARN("failed to check whether expr is nullable", K(ret)); - } else if (!is_nullable) { - if (OB_FAIL(ObRawExprUtils::build_const_bool_expr(ctx_->expr_factory_, new_expr, true))) { - LOG_WARN("build true expr failed", K(ret)); - } else { /*do nothing*/ - } - } else { - if (OB_FAIL(ObRawExprUtils::build_is_not_null_expr(*ctx_->expr_factory_, expr, new_expr))) { - LOG_WARN("build is not null expr failed", K(ret)); - } else { /*do nothing*/ - } + if (OB_FAIL(ObRawExprUtils::build_is_not_null_expr(*ctx_->expr_factory_, expr, new_expr))) { + LOG_WARN("build is not null expr failed", K(ret)); + } else { /*do nothing*/ } } return ret; diff --git a/src/sql/rewrite/ob_transform_utils.cpp b/src/sql/rewrite/ob_transform_utils.cpp index c4f9dfc734..b1951d83f9 100644 --- a/src/sql/rewrite/ob_transform_utils.cpp +++ b/src/sql/rewrite/ob_transform_utils.cpp @@ -1743,7 +1743,7 @@ int ObTransformUtils::find_not_null_expr(ObDMLStmt& stmt, ObRawExpr*& not_null_e // 1. check is there null rejecting condition // 2. check is nullable column, and is not the right table of outer join -int ObTransformUtils::check_expr_nullable(ObDMLStmt* stmt, ObRawExpr* expr, bool& is_nullable) +int ObTransformUtils::check_expr_nullable(ObDMLStmt* stmt, ObRawExpr* expr, bool& is_nullable, int nullable_scope /* = ObTransformUtils::NULLABLE_SCOPE::NS_WHERE */) { int ret = OB_SUCCESS; is_nullable = true; @@ -1757,12 +1757,14 @@ int ObTransformUtils::check_expr_nullable(ObDMLStmt* stmt, ObRawExpr* expr, bool LOG_WARN("failed to check is not null column", K(ret)); } else if (not_null_col) { is_nullable = false; - } else if (OB_FAIL(stmt->get_equal_set_conditions(valid_conds, true, SCOPE_WHERE))) { - LOG_WARN("failed to get equal set conditions", K(ret)); - } else if (OB_FAIL(has_null_reject_condition(valid_conds, expr, has_null_reject))) { - LOG_WARN("failed to check has null reject condition", K(ret)); - } else if (has_null_reject) { - is_nullable = false; + } else if (nullable_scope >= ObTransformUtils::NULLABLE_SCOPE::NS_WHERE) { + if (OB_FAIL(stmt->get_equal_set_conditions(valid_conds, true, SCOPE_WHERE))) { + LOG_WARN("failed to get equal set conditions", K(ret)); + } else if (OB_FAIL(has_null_reject_condition(valid_conds, expr, has_null_reject))) { + LOG_WARN("failed to check has null reject condition", K(ret)); + } else if (has_null_reject) { + is_nullable = false; + } } return ret; } diff --git a/src/sql/rewrite/ob_transform_utils.h b/src/sql/rewrite/ob_transform_utils.h index 3dd375dc4f..0a1d115cbc 100644 --- a/src/sql/rewrite/ob_transform_utils.h +++ b/src/sql/rewrite/ob_transform_utils.h @@ -242,7 +242,7 @@ public: static int find_not_null_expr(ObDMLStmt& stmt, ObRawExpr*& not_null_expr, bool& is_valid); - static int check_expr_nullable(ObDMLStmt* stmt, ObRawExpr* expr, bool& is_nullable); + static int check_expr_nullable(ObDMLStmt* stmt, ObRawExpr* expr, bool& is_nullable, int nullable_scope = ObTransformUtils::NULLABLE_SCOPE::NS_WHERE); static int check_is_not_null_column(const ObDMLStmt* stmt, const ObRawExpr* expr, bool& col_not_null);