未验证 提交 654245af 编写于 作者: A Amos Bird

Fix signedness conversion monotonicity

上级 c2f762e2
......@@ -1570,25 +1570,15 @@ struct ToNumberMonotonicity
if (left.isNull() || right.isNull())
return {};
if (from_is_unsigned == to_is_unsigned)
{
/// all bits other than that fits, must be same.
if (divideByRangeOfType(left.get<UInt64>()) == divideByRangeOfType(right.get<UInt64>()))
return {true};
/// Function cannot be monotonic when left and right are not on the same ranges.
if (divideByRangeOfType(left.get<UInt64>()) != divideByRangeOfType(right.get<UInt64>()))
return {};
}
else
{
/// When signedness is changed, it's also required for arguments to be from the same half.
/// And they must be in the same half after converting to the result type.
if (left_in_first_half == right_in_first_half
&& (T(left.get<Int64>()) >= 0) == (T(right.get<Int64>()) >= 0)
&& divideByRangeOfType(left.get<UInt64>()) == divideByRangeOfType(right.get<UInt64>()))
return {true};
return {};
}
if (to_is_unsigned)
return {true};
else
// If To is signed, it's possible that the signedness is different after conversion. So we check it explicitly.
return {(T(left.get<UInt64>()) >= 0) == (T(right.get<UInt64>()) >= 0)};
}
__builtin_unreachable();
......
drop table if exists test1;
create table test1 (i Int64) engine MergeTree order by i;
insert into test1 values (53), (1777), (53284);
select count() from test1 where toInt16(i) = 1777;
drop table if exists test1;
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册