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;