From 8dbc7a8dae17090a18778f29629d8746a1bb9b72 Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Wed, 1 Dec 2021 23:17:31 +0800 Subject: [PATCH] Fix detaching parts with projections --- src/Storages/MergeTree/IMergeTreeDataPart.cpp | 4 +--- .../01710_projection_detach_part.reference | 1 + .../0_stateless/01710_projection_detach_part.sql | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 tests/queries/0_stateless/01710_projection_detach_part.reference create mode 100644 tests/queries/0_stateless/01710_projection_detach_part.sql diff --git a/src/Storages/MergeTree/IMergeTreeDataPart.cpp b/src/Storages/MergeTree/IMergeTreeDataPart.cpp index 93149f87f99..1d89d53d64a 100644 --- a/src/Storages/MergeTree/IMergeTreeDataPart.cpp +++ b/src/Storages/MergeTree/IMergeTreeDataPart.cpp @@ -1323,9 +1323,7 @@ void IMergeTreeDataPart::renameToDetached(const String & prefix) const void IMergeTreeDataPart::makeCloneInDetached(const String & prefix, const StorageMetadataPtr & /*metadata_snapshot*/) const { String destination_path = fs::path(storage.relative_data_path) / getRelativePathForDetachedPart(prefix); - - /// Backup is not recursive (max_level is 0), so do not copy inner directories - localBackup(volume->getDisk(), getFullRelativePath(), destination_path, 0); + localBackup(volume->getDisk(), getFullRelativePath(), destination_path); volume->getDisk()->removeFileIfExists(fs::path(destination_path) / DELETE_ON_DESTROY_MARKER_FILE_NAME); } diff --git a/tests/queries/0_stateless/01710_projection_detach_part.reference b/tests/queries/0_stateless/01710_projection_detach_part.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/01710_projection_detach_part.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/01710_projection_detach_part.sql b/tests/queries/0_stateless/01710_projection_detach_part.sql new file mode 100644 index 00000000000..e3e6c7ac165 --- /dev/null +++ b/tests/queries/0_stateless/01710_projection_detach_part.sql @@ -0,0 +1,15 @@ +set allow_experimental_projection_optimization = 1; + +drop table if exists t; + +create table t (i int, j int, projection x (select * order by j)) engine MergeTree partition by i order by i; + +insert into t values (1, 2); + +alter table t detach partition 1; + +alter table t attach partition 1; + +select count() from system.projection_parts where database = currentDatabase() and table = 't'; + +drop table t;