mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-29 11:02:08 +00:00
Prevent attaching parts from tables with different projections or indices (#55062)
* Prevent attaching parts from tables with different projections or indices * Update docs * Add tests
This commit is contained in:
parent
8ac88645c8
commit
c911c8daf4
@ -113,6 +113,7 @@ For the query to run successfully, the following conditions must be met:
|
||||
|
||||
- Both tables must have the same structure.
|
||||
- Both tables must have the same partition key, the same order by key and the same primary key.
|
||||
- Both tables must have the same indices and projections.
|
||||
- Both tables must have the same storage policy.
|
||||
|
||||
## REPLACE PARTITION
|
||||
@ -132,6 +133,7 @@ For the query to run successfully, the following conditions must be met:
|
||||
|
||||
- Both tables must have the same structure.
|
||||
- Both tables must have the same partition key, the same order by key and the same primary key.
|
||||
- Both tables must have the same indices and projections.
|
||||
- Both tables must have the same storage policy.
|
||||
|
||||
## MOVE PARTITION TO TABLE
|
||||
@ -146,6 +148,7 @@ For the query to run successfully, the following conditions must be met:
|
||||
|
||||
- Both tables must have the same structure.
|
||||
- Both tables must have the same partition key, the same order by key and the same primary key.
|
||||
- Both tables must have the same indices and projections.
|
||||
- Both tables must have the same storage policy.
|
||||
- Both tables must be the same engine family (replicated or non-replicated).
|
||||
|
||||
|
@ -7543,6 +7543,28 @@ MergeTreeData & MergeTreeData::checkStructureAndGetMergeTreeData(IStorage & sour
|
||||
if (query_to_string(my_snapshot->getPrimaryKeyAST()) != query_to_string(src_snapshot->getPrimaryKeyAST()))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Tables have different primary key");
|
||||
|
||||
const auto check_definitions = [](const auto & my_descriptions, const auto & src_descriptions)
|
||||
{
|
||||
if (my_descriptions.size() != src_descriptions.size())
|
||||
return false;
|
||||
|
||||
std::unordered_set<std::string> my_query_strings;
|
||||
for (const auto & description : my_descriptions)
|
||||
my_query_strings.insert(queryToString(description.definition_ast));
|
||||
|
||||
for (const auto & src_description : src_descriptions)
|
||||
if (!my_query_strings.contains(queryToString(src_description.definition_ast)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
if (!check_definitions(my_snapshot->getSecondaryIndices(), src_snapshot->getSecondaryIndices()))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Tables have different secondary indices");
|
||||
|
||||
if (!check_definitions(my_snapshot->getProjections(), src_snapshot->getProjections()))
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS, "Tables have different projections");
|
||||
|
||||
return *src_data;
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
1 1
|
||||
0 0
|
||||
1 1
|
||||
2 2
|
||||
3 3
|
||||
4 4
|
||||
5 5
|
||||
6 6
|
||||
7 7
|
||||
8 8
|
||||
9 9
|
@ -0,0 +1,90 @@
|
||||
-- test different index type
|
||||
CREATE TABLE attach_partition_t1 (
|
||||
a UInt32,
|
||||
b String,
|
||||
INDEX bf b TYPE tokenbf_v1(8192, 3, 0) GRANULARITY 1
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY a;
|
||||
|
||||
INSERT INTO attach_partition_t1 SELECT number, toString(number) FROM numbers(10);
|
||||
|
||||
CREATE TABLE attach_partition_t2 (
|
||||
a UInt32,
|
||||
b String,
|
||||
INDEX bf b TYPE bloom_filter GRANULARITY 1
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY a;
|
||||
|
||||
ALTER TABLE attach_partition_t2 ATTACH PARTITION tuple() FROM attach_partition_t1; -- { serverError 36 }
|
||||
|
||||
-- test different projection name
|
||||
CREATE TABLE attach_partition_t3 (
|
||||
a UInt32,
|
||||
b String,
|
||||
PROJECTION proj
|
||||
(
|
||||
SELECT
|
||||
b,
|
||||
sum(a)
|
||||
GROUP BY b
|
||||
)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY a;
|
||||
|
||||
INSERT INTO attach_partition_t3 SELECT number, toString(number) FROM numbers(10);
|
||||
|
||||
CREATE TABLE attach_partition_t4 (
|
||||
a UInt32,
|
||||
b String,
|
||||
PROJECTION differently_named_proj
|
||||
(
|
||||
SELECT
|
||||
b,
|
||||
sum(a)
|
||||
GROUP BY b
|
||||
)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY a;
|
||||
|
||||
ALTER TABLE attach_partition_t4 ATTACH PARTITION tuple() FROM attach_partition_t3; -- { serverError 36 }
|
||||
|
||||
-- check attach with same index and projection
|
||||
CREATE TABLE attach_partition_t5 (
|
||||
a UInt32,
|
||||
b String,
|
||||
PROJECTION proj
|
||||
(
|
||||
SELECT
|
||||
b,
|
||||
sum(a)
|
||||
GROUP BY b
|
||||
)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY a;
|
||||
|
||||
INSERT INTO attach_partition_t5 SELECT number, toString(number) FROM numbers(10);
|
||||
|
||||
|
||||
CREATE TABLE attach_partition_t6 (
|
||||
a UInt32,
|
||||
b String,
|
||||
PROJECTION proj
|
||||
(
|
||||
SELECT
|
||||
b,
|
||||
sum(a)
|
||||
GROUP BY b
|
||||
)
|
||||
)
|
||||
ENGINE = MergeTree
|
||||
ORDER BY a;
|
||||
|
||||
ALTER TABLE attach_partition_t6 ATTACH PARTITION tuple() FROM attach_partition_t5;
|
||||
|
||||
SELECT * FROM attach_partition_t6 WHERE b = '1';
|
||||
SELECT b, sum(a) FROM attach_partition_t6 GROUP BY b ORDER BY b;
|
Loading…
Reference in New Issue
Block a user