mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 09:32:06 +00:00
Merge pull request #18211 from zhang2014/fix/ISSUES-18186
ISSUES-18186 fix unique key convert crash
This commit is contained in:
commit
0e807d0647
@ -202,10 +202,10 @@ static inline std::tuple<NamesAndTypesList, NamesAndTypesList, NamesAndTypesList
|
||||
keys->arguments->children.insert(keys->arguments->children.end(),
|
||||
index_columns->children.begin(), index_columns->children.end());
|
||||
else if (startsWith(declare_index->index_type, "UNIQUE_"))
|
||||
unique_keys->arguments->children.insert(keys->arguments->children.end(),
|
||||
unique_keys->arguments->children.insert(unique_keys->arguments->children.end(),
|
||||
index_columns->children.begin(), index_columns->children.end());
|
||||
if (startsWith(declare_index->index_type, "PRIMARY_KEY_"))
|
||||
primary_keys->arguments->children.insert(keys->arguments->children.end(),
|
||||
primary_keys->arguments->children.insert(primary_keys->arguments->children.end(),
|
||||
index_columns->children.begin(), index_columns->children.end());
|
||||
}
|
||||
}
|
||||
|
@ -195,3 +195,15 @@ TEST(MySQLCreateRewritten, RewrittenQueryWithPrefixKey)
|
||||
"ReplacingMergeTree(_version) PARTITION BY intDiv(key, 4294967) ORDER BY (key, prefix_key)");
|
||||
}
|
||||
|
||||
TEST(MySQLCreateRewritten, UniqueKeysConvert)
|
||||
{
|
||||
tryRegisterFunctions();
|
||||
const auto & context_holder = getContext();
|
||||
|
||||
EXPECT_EQ(queryToString(tryRewrittenCreateQuery(
|
||||
"CREATE TABLE `test_database`.`test_table_1` (code varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,"
|
||||
" id bigint NOT NULL AUTO_INCREMENT, tenant_id bigint NOT NULL, PRIMARY KEY (id), UNIQUE KEY code_id (code, tenant_id), UNIQUE KEY name_id (name, tenant_id))"
|
||||
" ENGINE=InnoDB AUTO_INCREMENT=100 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;", context_holder.context)),
|
||||
"CREATE TABLE test_database.test_table_1 (`code` String, `name` String, `id` Int64, `tenant_id` Int64, `_sign` Int8() MATERIALIZED 1, `_version` UInt64() MATERIALIZED 1)"
|
||||
" ENGINE = ReplacingMergeTree(_version) PARTITION BY intDiv(id, 18446744073709551) ORDER BY (code, name, tenant_id, id)");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user