Avoid performance degradation in few degenerate cases: added fast path for tautological compares #4405

This commit is contained in:
Alexey Milovidov 2019-03-03 02:51:21 +03:00
parent b8ff976ee9
commit 0dc576e44f
3 changed files with 37 additions and 0 deletions

View File

@ -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;

View File

@ -0,0 +1,8 @@
0
0
0
0
0
0
0
0

View File

@ -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;