diff --git a/src/observer/mysql/obmp_base.cpp b/src/observer/mysql/obmp_base.cpp index 82eae6919d..aa6d5c7d16 100644 --- a/src/observer/mysql/obmp_base.cpp +++ b/src/observer/mysql/obmp_base.cpp @@ -528,6 +528,9 @@ int ObMPBase::response_row(ObSQLSessionInfo &session, // need at ps mode if (!is_packed && value.get_type() != fields->at(i).type_.get_type()) { ObCastCtx cast_ctx(&allocator, NULL, CM_WARN_ON_FAIL, fields->at(i).type_.get_collation_type()); + if (ObDecimalIntType == fields->at(i).type_.get_type()) { + cast_ctx.res_accuracy_ = const_cast(&fields->at(i).accuracy_); + } if (OB_FAIL(common::ObObjCaster::to_type(fields->at(i).type_.get_type(), cast_ctx, value, diff --git a/src/sql/engine/expr/ob_expr_mod.cpp b/src/sql/engine/expr/ob_expr_mod.cpp index cc9fa3ef66..7b52fad649 100644 --- a/src/sql/engine/expr/ob_expr_mod.cpp +++ b/src/sql/engine/expr/ob_expr_mod.cpp @@ -62,7 +62,10 @@ int ObExprMod::calc_result_type2(ObExprResType &type, // In mysql mode, precision of int(255) is 255, more than OB_MAX_DECIMAL_POSSIBLE_PRECISION // So precision deduced just now may be larger than 81 while res type is decimal_int // TODO:@xiaofeng.lby, use a more generic method to solve this problem - type.set_precision(MIN(type.get_precision(), OB_MAX_DECIMAL_POSSIBLE_PRECISION)); + const int64_t int_part1 = type1.get_precision() - type1.get_scale(); + const int64_t int_part2 = type2.get_precision() - type2.get_scale(); + const int64_t precision = MAX(int_part1, int_part2) + type.get_scale(); + type.set_precision(MIN(precision, OB_MAX_DECIMAL_POSSIBLE_PRECISION)); type1.set_calc_accuracy(type.get_accuracy()); type2.set_calc_accuracy(type.get_accuracy()); } diff --git a/src/sql/engine/expr/ob_expr_relational_cmp_type.map b/src/sql/engine/expr/ob_expr_relational_cmp_type.map index 16afd559e7..0309e8782e 100644 --- a/src/sql/engine/expr/ob_expr_relational_cmp_type.map +++ b/src/sql/engine/expr/ob_expr_relational_cmp_type.map @@ -879,8 +879,8 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /*MediumTextType*/ ObNumberType, /*LongTextType*/ ObNumberType, /*BitType*/ - ObNumberType, /*EnumType*/ - ObNumberType, /*SetType*/ + ObDoubleType, /*EnumType*/ + ObDoubleType, /*SetType*/ ObNumberType, /*EnumInnerType*/ ObNumberType, /*SetInnerType*/ ObTimestampTZType, /* ObTimestampTZType */ @@ -934,8 +934,8 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /*MediumTextType*/ ObNumberType, /*LongTextType*/ ObUNumberType, /*BitType*/ - ObUNumberType, /*EnumType*/ - ObUNumberType, /*SetType*/ + ObDoubleType, /*EnumType*/ + ObDoubleType, /*SetType*/ ObUNumberType, /*EnumInnerType*/ ObUNumberType, /*SetInnerType*/ ObTimestampTZType, /* ObTimestampTZType */ @@ -1792,8 +1792,8 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObDoubleType, /* DoubleType */ ObDoubleType, /* UFloatType */ ObDoubleType, /* UDoubleType */ - ObNumberType, /* NumberType */ - ObNumberType, /* UNumberType */ + ObDoubleType, /* NumberType */ + ObDoubleType, /* UNumberType */ ObDateTimeType, /* DateTimeType */ ObTimestampType, /* TimestampType */ ObDateTimeType, /* DateType */ @@ -1827,7 +1827,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ ObMaxType, /* UDT */ - ObDecimalIntType, /* ObDecimalIntType */ + ObDoubleType, /* ObDecimalIntType */ }, /*SetType*/ { @@ -1846,8 +1846,8 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObDoubleType, /* DoubleType */ ObDoubleType, /* UFloatType */ ObDoubleType, /* UDoubleType */ - ObNumberType, /* NumberType */ - ObNumberType, /* UNumberType */ + ObDoubleType, /* NumberType */ + ObDoubleType, /* UNumberType */ ObDateTimeType, /* DateTimeType */ ObTimestampType, /* TimestampType */ ObDateTimeType, /* DateType */ @@ -1881,7 +1881,7 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObNumberType, /* ObJsonType */ ObMaxType, /* ObGeometryType */ ObMaxType, /* UDT */ - ObDecimalIntType, /* ObDecimalIntType */ + ObDoubleType, /* ObDecimalIntType */ }, /*EnumInnerType*/ { @@ -2782,8 +2782,8 @@ static ObObjType RELATIONAL_CMP_TYPE[ObMaxType][ObMaxType] = ObDecimalIntType, /*MediumTextType*/ ObDecimalIntType, /*LongTextType*/ ObDecimalIntType, /*BitType*/ - ObDecimalIntType, /*EnumType*/ - ObDecimalIntType, /*SetType*/ + ObDoubleType, /*EnumType*/ + ObDoubleType, /*SetType*/ ObDecimalIntType, /*EnumInnerType*/ ObDecimalIntType, /*SetInnerType*/ ObTimestampTZType, /* ObTimestampTZType */