From 33d19d15f06d7bf64a0b9939aca00f5f969fee29 Mon Sep 17 00:00:00 2001 From: obdev Date: Thu, 5 May 2022 14:18:45 +0800 Subject: [PATCH] =?UTF-8?q?[CP]=20=E3=80=90SQLancer=E3=80=91query=20result?= =?UTF-8?q?=20mismatch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/sql/engine/expr/ob_expr_operator.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/sql/engine/expr/ob_expr_operator.cpp b/src/sql/engine/expr/ob_expr_operator.cpp index 47a644b295..145c32e33b 100644 --- a/src/sql/engine/expr/ob_expr_operator.cpp +++ b/src/sql/engine/expr/ob_expr_operator.cpp @@ -202,13 +202,19 @@ int OB_INLINE ObExprOperator::cast_operand_type( LOG_DEBUG( "need cast operand", K(res_type), K(res_type.get_calc_meta().get_scale()), K(res_obj), K(res_obj.get_scale())); ObCastMode cast_mode = get_cast_mode(); - // In PAD expression, we need add COLUMN_CONVERT to cast mode when cast is - // from bit to binary and column convert is set in column_conv_ctx_. The COLUMN_CONVERT - // cast mode is used in bit_to_string to decide which cast way is appropriate. + if (OB_UNLIKELY(T_FUN_PAD == get_type() && ob_is_bit_tc(param_type) && ob_is_varbinary_type(calc_type, calc_collation_type) && CM_IS_COLUMN_CONVERT(expr_ctx.column_conv_ctx_.cast_mode_))) { + // In PAD expression, we need add COLUMN_CONVERT to cast mode when cast is + // from bit to binary and column convert is set in column_conv_ctx_. The COLUMN_CONVERT + // cast mode is used in bit_to_string to decide which cast way is appropriate. cast_mode |= CM_COLUMN_CONVERT; + } else if (OB_UNLIKELY(T_FUN_SYS_BIT_COUNT == get_type() && ObIntType == param_type && ObUInt64Type == calc_type)) { + // when param_type is ObIntType and calc_type is ObUInt64Type, + // set CM_NO_RANGE_CHECK in cast_mode, + // so that res_obj will not convert to zero even res_obj is less than 0. + cast_mode |= CM_NO_RANGE_CHECK; } bool is_bool = false;