Merge pull request #24162 from amosbird/projection-fix2

Fix add projection to replicated mergetree
This commit is contained in:
Nikolai Kochetov 2021-05-19 18:07:52 +03:00 committed by GitHub
commit e8f8b2ba18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -4722,6 +4722,10 @@ void StorageReplicatedMergeTree::alter(
if (new_indices_str != current_metadata->secondary_indices.toString())
future_metadata_in_zk.skip_indices = new_indices_str;
String new_projections_str = future_metadata.projections.toString();
if (new_projections_str != current_metadata->projections.toString())
future_metadata_in_zk.projections = new_projections_str;
String new_constraints_str = future_metadata.constraints.toString();
if (new_constraints_str != current_metadata->constraints.toString())
future_metadata_in_zk.constraints = new_constraints_str;

View File

@ -9,3 +9,9 @@
2 2
3 3
4 4
0
CREATE TABLE default.tp_2\n(\n `x` Int32,\n `y` Int32,\n PROJECTION p\n (\n SELECT \n x,\n y\n ORDER BY x\n ),\n PROJECTION pp\n (\n SELECT \n x,\n count()\n GROUP BY x\n )\n)\nENGINE = ReplicatedMergeTree(\'/clickhouse/tables/01710_projection_fetch_default\', \'2\')\nORDER BY y\nSETTINGS min_rows_for_compact_part = 2, min_rows_for_wide_part = 4, min_bytes_for_compact_part = 16, min_bytes_for_wide_part = 32, index_granularity = 8192
2
CREATE TABLE default.tp_2\n(\n `x` Int32,\n `y` Int32,\n PROJECTION p\n (\n SELECT \n x,\n y\n ORDER BY x\n ),\n PROJECTION pp\n (\n SELECT \n x,\n count()\n GROUP BY x\n )\n)\nENGINE = ReplicatedMergeTree(\'/clickhouse/tables/01710_projection_fetch_default\', \'2\')\nORDER BY y\nSETTINGS min_rows_for_compact_part = 2, min_rows_for_wide_part = 4, min_bytes_for_compact_part = 16, min_bytes_for_wide_part = 32, index_granularity = 8192
CREATE TABLE default.tp_2\n(\n `x` Int32,\n `y` Int32,\n PROJECTION p\n (\n SELECT \n x,\n y\n ORDER BY x\n ),\n PROJECTION pp\n (\n SELECT \n x,\n count()\n GROUP BY x\n )\n)\nENGINE = ReplicatedMergeTree(\'/clickhouse/tables/01710_projection_fetch_default\', \'2\')\nORDER BY y\nSETTINGS min_rows_for_compact_part = 2, min_rows_for_wide_part = 4, min_bytes_for_compact_part = 16, min_bytes_for_wide_part = 32, index_granularity = 8192
CREATE TABLE default.tp_2\n(\n `x` Int32,\n `y` Int32,\n PROJECTION p\n (\n SELECT \n x,\n y\n ORDER BY x\n )\n)\nENGINE = ReplicatedMergeTree(\'/clickhouse/tables/01710_projection_fetch_default\', \'2\')\nORDER BY y\nSETTINGS min_rows_for_compact_part = 2, min_rows_for_wide_part = 4, min_bytes_for_compact_part = 16, min_bytes_for_wide_part = 32, index_granularity = 8192

View File

@ -15,6 +15,27 @@ insert into tp_1 select number, number from numbers(5);
system sync replica tp_2;
select * from tp_2 order by x;
-- test projection creation, materialization, clear and drop
alter table tp_1 add projection pp (select x, count() group by x);
system sync replica tp_2;
select count() from system.projection_parts where table = 'tp_2' and name = 'pp' and active;
show create table tp_2;
-- all other three operations are mutations
set mutations_sync = 2;
alter table tp_1 materialize projection pp;
select count() from system.projection_parts where table = 'tp_2' and name = 'pp' and active;
show create table tp_2;
alter table tp_1 clear projection pp;
system sync replica tp_2;
select * from system.projection_parts where table = 'tp_2' and name = 'pp' and active;
show create table tp_2;
alter table tp_1 drop projection pp;
system sync replica tp_2;
select * from system.projection_parts where table = 'tp_2' and name = 'pp' and active;
show create table tp_2;
drop table if exists tp_1;
drop table if exists tp_2;