Backport #63097 to 24.3: Fix incorrect judgement of of monotonicity of function abs

This commit is contained in:
robot-clickhouse 2024-04-30 03:09:46 +00:00
parent f46ef3bf05
commit 483ff9438c
4 changed files with 14 additions and 3 deletions

View File

@ -45,7 +45,7 @@ template <> struct FunctionUnaryArithmeticMonotonicity<NameAbs>
if ((left_float < 0 && right_float > 0) || (left_float > 0 && right_float < 0))
return {};
return { .is_monotonic = true, .is_positive = left_float > 0, .is_strict = true, };
return { .is_monotonic = true, .is_positive = std::min(left_float, right_float) >= 0, .is_strict = true, };
}
};

View File

@ -2860,9 +2860,9 @@ bool KeyCondition::mayBeTrueInRange(
String KeyCondition::RPNElement::toString() const
{
if (argument_num_of_space_filling_curve)
return toString(fmt::format("argument {} of column {}", *argument_num_of_space_filling_curve, key_column), false);
return toString(fmt::format("argument {} of column {}", *argument_num_of_space_filling_curve, key_column), true);
else
return toString(fmt::format("column {}", key_column), false);
return toString(fmt::format("column {}", key_column), true);
}
String KeyCondition::RPNElement::toString(std::string_view column_name, bool print_constants) const

View File

@ -0,0 +1,10 @@
DROP TABLE IF EXISTS t;
CREATE TABLE t (id UInt64, ts DateTime) ENGINE = MergeTree() ORDER BY (id, ts) SETTINGS index_granularity = 2;
INSERT INTO t VALUES
(1, toDateTime('2023-05-04 21:17:23', 'UTC')), (1, toDateTime('2023-05-04 22:17:23', 'UTC')), (2, toDateTime('2023-05-04 22:17:23', 'UTC')), (2, toDateTime('2023-05-04 23:17:23', 'UTC'));
SELECT count(abs(toUnixTimestamp(ts, 'UTC') - toUnixTimestamp('2023-05-04 22:17:23', 'UTC')) AS error) FROM t WHERE error < 3600;
DROP TABLE IF EXISTS t;