Merge pull request #40850 from canhld94/ch_canh_fix_set

Fix tryGetPreparedSet crash when same set expression built from different column(s)
This commit is contained in:
Yakov Olkhovskiy 2022-09-02 14:40:35 -04:00 committed by GitHub
commit fdcced8962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 1 deletions

View File

@ -403,7 +403,13 @@ void Set::checkColumnsNumber(size_t num_key_columns) const
bool Set::areTypesEqual(size_t set_type_idx, const DataTypePtr & other_type) const
{
return removeNullable(recursiveRemoveLowCardinality(data_types[set_type_idx]))->equals(*removeNullable(recursiveRemoveLowCardinality(other_type)));
/// Out-of-bound access can happen when same set expression built with different columns.
/// Caller may call this method to make sure that the set is indeed the one they want
/// without awaring data_types.size().
if (set_type_idx >= data_types.size())
return false;
return removeNullable(recursiveRemoveLowCardinality(data_types[set_type_idx]))
->equals(*removeNullable(recursiveRemoveLowCardinality(other_type)));
}
void Set::checkTypesEqual(size_t set_type_idx, const DataTypePtr & other_type) const

View File

@ -297,8 +297,10 @@ public:
assert(indexes_mapping.size() == data_types.size());
for (size_t i = 0; i < indexes_mapping.size(); ++i)
{
if (!candidate_set->areTypesEqual(indexes_mapping[i].tuple_index, data_types[i]))
return false;
}
return true;
};

View File

@ -0,0 +1,3 @@
CREATE TABLE set_crash (key1 Int32, id1 Int64, c1 Int64) ENGINE = MergeTree PARTITION BY id1 ORDER BY key1;
INSERT INTO set_crash VALUES (-1, 1, 0);
SELECT 1 in (-1, 1) FROM set_crash WHERE (key1, id1) in (-1, 1);