mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 08:32:02 +00:00
Avoid performance degradation in few degenerate cases: added fast path for tautological compares #4405
This commit is contained in:
parent
b8ff976ee9
commit
0dc576e44f
@ -1142,6 +1142,25 @@ public:
|
||||
const auto & col_with_type_and_name_right = block.getByPosition(arguments[1]);
|
||||
const IColumn * col_left_untyped = col_with_type_and_name_left.column.get();
|
||||
const IColumn * col_right_untyped = col_with_type_and_name_right.column.get();
|
||||
|
||||
/// The case when arguments are the same (tautological comparison). Return constant.
|
||||
if (col_left_untyped == col_right_untyped)
|
||||
{
|
||||
/// Always true: =, <=, >=
|
||||
if constexpr (std::is_same_v<Op<int, int>, EqualsOp<int, int>>
|
||||
|| std::is_same_v<Op<int, int>, LessOrEqualsOp<int, int>>
|
||||
|| std::is_same_v<Op<int, int>, GreaterOrEqualsOp<int, int>>)
|
||||
{
|
||||
block.getByPosition(result).column = DataTypeUInt8().createColumnConst(input_rows_count, 1u);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
block.getByPosition(result).column = DataTypeUInt8().createColumnConst(input_rows_count, 0u);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const DataTypePtr & left_type = col_with_type_and_name_left.type;
|
||||
const DataTypePtr & right_type = col_with_type_and_name_right.type;
|
||||
|
||||
|
@ -0,0 +1,8 @@
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
||||
0
|
@ -0,0 +1,10 @@
|
||||
SELECT count() FROM system.numbers WHERE number != number;
|
||||
SELECT count() FROM system.numbers WHERE number < number;
|
||||
SELECT count() FROM system.numbers WHERE number > number;
|
||||
|
||||
SELECT count() FROM system.numbers WHERE NOT (number = number);
|
||||
SELECT count() FROM system.numbers WHERE NOT (number <= number);
|
||||
SELECT count() FROM system.numbers WHERE NOT (number >= number);
|
||||
|
||||
SELECT count() FROM system.numbers WHERE SHA256(toString(number)) != SHA256(toString(number));
|
||||
SELECT count() FROM system.numbers WHERE SHA256(toString(number)) != SHA256(toString(number)) AND rand() > 10;
|
Loading…
Reference in New Issue
Block a user