From 3679e990399fde2b3c35ae7bc4502e3b8771c512 Mon Sep 17 00:00:00 2001 From: koarz <3577087577@qq.com> Date: Sat, 30 Nov 2024 17:12:14 +0800 Subject: [PATCH] fix --- be/src/vec/data_types/data_type_decimal.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/be/src/vec/data_types/data_type_decimal.h b/be/src/vec/data_types/data_type_decimal.h index 74655ff6ee8becf..002cf5f4f5e633b 100644 --- a/be/src/vec/data_types/data_type_decimal.h +++ b/be/src/vec/data_types/data_type_decimal.h @@ -315,9 +315,16 @@ DataTypePtr decimal_result_type(const DataTypeDecimal& tx, const DataTypeDeci size_t multiply_precision = tx.get_precision() + ty.get_precision(); size_t divide_precision = tx.get_precision() + ty.get_scale(); + // In the previous pr this was calculated as + // std::max(tx.get_precision() - tx.get_scale(), ty.get_precision() - ty.get_scale()) + scale + 1 + // this is to make sure that there is space for rounding when performing add. + // But in fact, the decimal type has already been converted in fe, if we continue to +1 here + // it will result in the precision of the func return type being 1 larger than the precision of the return type generated by fe. + // (fe + 1 and here + 1 again, result is + 2) + // This will cause return_type->equals(*func_return_type) to return false when building the Function size_t plus_minus_precision = std::max(tx.get_precision() - tx.get_scale(), ty.get_precision() - ty.get_scale()) + - scale + 1; + scale; if (is_multiply) { scale = tx.get_scale() + ty.get_scale(); precision = std::min(multiply_precision, max_decimal_precision());