From 51ea0888e58edfdf0bfe5d233ff2222da21baf44 Mon Sep 17 00:00:00 2001 From: cangyin Date: Fri, 17 Mar 2023 10:00:50 +0800 Subject: [PATCH] fix invalid segment id bug after mutation skip hardlinking inverted index files in mutation --- src/Storages/MergeTree/MutateTask.cpp | 10 ++++++++ .../02346_inverted_index_mutation.reference | 3 +++ .../02346_inverted_index_mutation.sql | 23 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 tests/queries/0_stateless/02346_inverted_index_mutation.reference create mode 100644 tests/queries/0_stateless/02346_inverted_index_mutation.sql diff --git a/src/Storages/MergeTree/MutateTask.cpp b/src/Storages/MergeTree/MutateTask.cpp index 9f7a12745c6..30fa50e325f 100644 --- a/src/Storages/MergeTree/MutateTask.cpp +++ b/src/Storages/MergeTree/MutateTask.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -551,6 +552,15 @@ static NameSet collectFilesToSkip( /// Since MinMax index has .idx2 extension, we need to add correct extension. files_to_skip.insert(index->getFileName() + index->getSerializedFileExtension()); files_to_skip.insert(index->getFileName() + mrk_extension); + + // skip all inverted index files, for they will be re-built + if (dynamic_cast(&*index) != nullptr) + { + files_to_skip.insert(index->getFileName() + ".gin_dict"); + files_to_skip.insert(index->getFileName() + ".gin_post"); + files_to_skip.insert(index->getFileName() + ".gin_sed"); + files_to_skip.insert(index->getFileName() + ".gin_sid"); + } } for (const auto & projection : projections_to_recalc) diff --git a/tests/queries/0_stateless/02346_inverted_index_mutation.reference b/tests/queries/0_stateless/02346_inverted_index_mutation.reference new file mode 100644 index 00000000000..b80f66e4c05 --- /dev/null +++ b/tests/queries/0_stateless/02346_inverted_index_mutation.reference @@ -0,0 +1,3 @@ +1 +2 +I am not inverted diff --git a/tests/queries/0_stateless/02346_inverted_index_mutation.sql b/tests/queries/0_stateless/02346_inverted_index_mutation.sql new file mode 100644 index 00000000000..0987b4aa43c --- /dev/null +++ b/tests/queries/0_stateless/02346_inverted_index_mutation.sql @@ -0,0 +1,23 @@ +SET allow_experimental_inverted_index=1; + +DROP TABLE IF EXISTS t; +CREATE TABLE t +( + `timestamp` UInt64, + `s` String, + INDEX idx s TYPE inverted(3) GRANULARITY 1 +) +ENGINE = MergeTree +ORDER BY tuple() +SETTINGS min_rows_for_wide_part = 1, min_bytes_for_wide_part = 1; + +INSERT INTO t (s) VALUES ('I am inverted'); + +SELECT data_version FROM system.parts WHERE database=currentDatabase() AND table='t' AND active=1; + +-- do update column synchronously +ALTER TABLE t UPDATE s='I am not inverted' WHERE 1 SETTINGS mutations_sync=1; + +SELECT data_version FROM system.parts WHERE database=currentDatabase() AND table='t' AND active=1; + +SELECT s FROM t WHERE s LIKE '%inverted%' SETTINGS force_data_skipping_indices='idx';