diff --git a/src/Storages/MergeTree/MergeTreeIndices.h b/src/Storages/MergeTree/MergeTreeIndices.h index 8f10b2c51ba..1e001d01ada 100644 --- a/src/Storages/MergeTree/MergeTreeIndices.h +++ b/src/Storages/MergeTree/MergeTreeIndices.h @@ -147,9 +147,11 @@ struct IMergeTreeIndex /// Returns extension for deserialization. /// /// Return pair. - virtual MergeTreeIndexFormat getDeserializedFormat(const DiskPtr, const std::string & /* relative_path_prefix */) const + virtual MergeTreeIndexFormat getDeserializedFormat(const DiskPtr disk, const std::string & relative_path_prefix) const { - return {1, ".idx"}; + if (disk->exists(relative_path_prefix + ".idx")) + return {1, ".idx"}; + return {0 /*unknown*/, ""}; } /// Checks whether the column is in data skipping index. diff --git a/tests/queries/0_stateless/02131_skip_index_not_materialized.reference b/tests/queries/0_stateless/02131_skip_index_not_materialized.reference new file mode 100644 index 00000000000..d00491fd7e5 --- /dev/null +++ b/tests/queries/0_stateless/02131_skip_index_not_materialized.reference @@ -0,0 +1 @@ +1 diff --git a/tests/queries/0_stateless/02131_skip_index_not_materialized.sql b/tests/queries/0_stateless/02131_skip_index_not_materialized.sql new file mode 100644 index 00000000000..706ee043e09 --- /dev/null +++ b/tests/queries/0_stateless/02131_skip_index_not_materialized.sql @@ -0,0 +1,11 @@ +DROP TABLE IF EXISTS t_index_non_materialized; + +CREATE TABLE t_index_non_materialized (a UInt32) ENGINE = MergeTree ORDER BY tuple(); + +INSERT INTO t_index_non_materialized VALUES (1); + +ALTER TABLE t_index_non_materialized ADD INDEX ind (a) TYPE set(1) GRANULARITY 1; + +SELECT count() FROM t_index_non_materialized WHERE a = 1; + +DROP TABLE t_index_non_materialized;