Merge pull request #10110 from amosbird/tsm

more monotonicity for toString()
This commit is contained in:
alexey-milovidov 2020-04-08 22:55:04 +03:00 committed by GitHub
commit 0372a6119a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 3 deletions

View File

@ -24,6 +24,12 @@ const Type * checkAndGetDataType(const IDataType * data_type)
return typeid_cast<const Type *>(data_type); return typeid_cast<const Type *>(data_type);
} }
template <typename... Types>
bool checkDataTypes(const IDataType * data_type)
{
return (... || typeid_cast<const Types *>(data_type));
}
template <typename Type> template <typename Type>
const ColumnConst * checkAndGetColumnConst(const IColumn * column) const ColumnConst * checkAndGetColumnConst(const IColumn * column)
{ {

View File

@ -1496,10 +1496,12 @@ struct ToStringMonotonicity
IFunction::Monotonicity positive(true, true); IFunction::Monotonicity positive(true, true);
IFunction::Monotonicity not_monotonic; IFunction::Monotonicity not_monotonic;
/// `toString` function is monotonous if the argument is Date or DateTime, or non-negative numbers with the same number of symbols. auto type_ptr = &type;
if (auto * low_cardinality_type = checkAndGetDataType<DataTypeLowCardinality>(type_ptr))
type_ptr = low_cardinality_type->getDictionaryType().get();
if (checkAndGetDataType<DataTypeDate>(&type) /// `toString` function is monotonous if the argument is Date or DateTime or String, or non-negative numbers with the same number of symbols.
|| typeid_cast<const DataTypeDateTime *>(&type)) if (checkDataTypes<DataTypeDate, DataTypeDateTime, DataTypeString>(type_ptr))
return positive; return positive;
if (left.isNull() || right.isNull()) if (left.isNull() || right.isNull())

View File

@ -0,0 +1,2 @@
1234
1234

View File

@ -0,0 +1,14 @@
DROP TABLE IF EXISTS test1;
DROP TABLE IF EXISTS test2;
CREATE TABLE test1 (s String) ENGINE = MergeTree ORDER BY s SETTINGS index_granularity = 1;
CREATE TABLE test2 (s LowCardinality(String)) ENGINE = MergeTree ORDER BY s SETTINGS index_granularity = 1;
INSERT INTO test1 SELECT toString(number) FROM numbers(10000);
INSERT INTO test2 SELECT toString(number) FROM numbers(10000);
SELECT s FROM test1 WHERE toString(s) = '1234' SETTINGS max_rows_to_read = 2;
SELECT s FROM test2 WHERE toString(s) = '1234' SETTINGS max_rows_to_read = 2;
DROP TABLE test1;
DROP TABLE test2;