diff --git a/src/sql/engine/expr/ob_expr_operator.cpp b/src/sql/engine/expr/ob_expr_operator.cpp index 3c872c5d5..5b1af73b9 100644 --- a/src/sql/engine/expr/ob_expr_operator.cpp +++ b/src/sql/engine/expr/ob_expr_operator.cpp @@ -2125,13 +2125,16 @@ int ObRelationalExprOperator::deduce_cmp_type(const ObExprOperator &expr, // to be compatiable with mysql: // if c1 is date or datetime, convert 'c1 = c2+1'to cast (c1 as double) = cast (c2+1 as double) const ObRawExpr* cmp_expr = type_ctx.get_raw_expr(); - const ObRawExpr* date_expr = cmp_expr->get_param_expr(0); - const ObRawExpr* other_expr = cmp_expr->get_param_expr(1); + const ObRawExpr* date_expr = NULL; + const ObRawExpr* other_expr = NULL; ObObjType other_expr_type = ObMaxType; bool is_date_op_other = false; - if (OB_ISNULL(cmp_expr) || OB_ISNULL(date_expr) || OB_ISNULL(other_expr) ) { + if (OB_ISNULL(cmp_expr)) { ret = OB_ERR_UNEXPECTED; - LOG_WARN("unexpected null", K(ret), K(cmp_expr), K(date_expr), K(other_expr)); + LOG_WARN("unexpected null", K(ret), K(cmp_expr)); + } else if (OB_ISNULL(date_expr = cmp_expr->get_param_expr(0)) || OB_ISNULL(other_expr = cmp_expr->get_param_expr(1))) { + ret = OB_ERR_UNEXPECTED; + LOG_WARN("unexpected null", K(ret), K(date_expr), K(other_expr)); } else { if (T_REF_QUERY == other_expr->get_expr_type()) { const ObQueryRefRawExpr *ref_expr = static_cast(other_expr); diff --git a/src/sql/optimizer/ob_opt_est_utils.cpp b/src/sql/optimizer/ob_opt_est_utils.cpp index cd5230533..7c435ffd5 100644 --- a/src/sql/optimizer/ob_opt_est_utils.cpp +++ b/src/sql/optimizer/ob_opt_est_utils.cpp @@ -313,6 +313,8 @@ int ObOptEstUtils::if_expr_value_equal(ObOptimizerContext &opt_ctx, ObExprResType result_type; ObExprResType first_type = first_expr.get_result_type(); ObExprResType second_type = second_expr.get_result_type(); + ObOpRawExpr equal_expr(const_cast(&first_expr), const_cast(&second_expr), T_OP_EQ); + type_ctx.set_raw_expr(&equal_expr); if (OB_FAIL(ObSQLUtils::wrap_expr_ctx(stmt->get_stmt_type(), *exec_ctx, allocator, expr_ctx))) { LOG_WARN("Failed to wrap expr ctx", K(ret)); } else if (OB_FAIL(equal_op.calc_result_type2(result_type, first_type, second_type, type_ctx))) {