diff --git a/dbms/src/Storages/AlterCommands.cpp b/dbms/src/Storages/AlterCommands.cpp index a4519800534..2d51afa1c46 100644 --- a/dbms/src/Storages/AlterCommands.cpp +++ b/dbms/src/Storages/AlterCommands.cpp @@ -321,7 +321,7 @@ void AlterCommand::apply(ColumnsDescription & columns_description, ASTPtr & orde if (indexes_decl_ast) new_indexes_decl_ast = indexes_decl_ast->clone(); else - new_indexes_decl_ast = ASTExpressionList().ptr(); + new_indexes_decl_ast = std::make_shared(); if (std::any_of( new_indexes_decl_ast->children.cbegin(), @@ -363,7 +363,7 @@ void AlterCommand::apply(ColumnsDescription & columns_description, ASTPtr & orde if (indexes_decl_ast) new_indexes_decl_ast = indexes_decl_ast->clone(); else - new_indexes_decl_ast = ASTExpressionList().ptr(); + new_indexes_decl_ast = std::make_shared(); auto erase_it = std::find_if( new_indexes_decl_ast->children.begin(), diff --git a/dbms/tests/queries/0_stateless/00824_indices_alter.reference b/dbms/tests/queries/0_stateless/00824_indices_alter.reference new file mode 100644 index 00000000000..e69de29bb2d diff --git a/dbms/tests/queries/0_stateless/00824_indices_alter.sql b/dbms/tests/queries/0_stateless/00824_indices_alter.sql new file mode 100644 index 00000000000..40ef6bb4fc8 --- /dev/null +++ b/dbms/tests/queries/0_stateless/00824_indices_alter.sql @@ -0,0 +1,68 @@ +DROP TABLE IF EXISTS test.minmax_idx; +DROP TABLE IF EXISTS test.minmax_idx2; + +CREATE TABLE test.minmax_idx +( + u64 UInt64, + i32 Int32 +) ENGINE = MergeTree() +ORDER BY u64; + +INSERT INTO test.minmax_idx VALUES (1, 2); + +ALTER TABLE test.minmax_idx ADD INDEX idx1 BY u64 * i32 TYPE minmax GRANULARITY 10; +ALTER TABLE test.minmax_idx ADD INDEX idx2 BY u64 * i32 TYPE minmax GRANULARITY 10; +ALTER TABLE test.minmax_idx ADD INDEX idx3 BY u64 * i32 TYPE minmax GRANULARITY 10 AFTER idx1; + +SHOW CREATE TABLE test.minmax_idx; + +SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3; + +INSERT INTO test.minmax_idx VALUES (1, 2); +INSERT INTO test.minmax_idx VALUES (1, 2); +INSERT INTO test.minmax_idx VALUES (1, 2); +INSERT INTO test.minmax_idx VALUES (1, 2); +INSERT INTO test.minmax_idx VALUES (1, 2); + +SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3; + +ALTER TABLE test.minmax_idx DROP INDEX idx1 + +SHOW CREATE TABLE test.minmax_idx; + +SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3; + +ALTER TABLE test.minmax_idx DROP INDEX idx3; +ALTER TABLE test.minmax_idx DROP INDEX idx2; + +SHOW CREATE TABLE test.minmax_idx; + +ALTER TABLE test.minmax_idx ADD INDEX idx1 BY u64 * i32 TYPE minmax GRANULARITY 10; + +SHOW CREATE TABLE test.minmax_idx; + +SELECT * FROM test.minmax_idx WHERE u64 * i32 = 3; + + +CREATE TABLE test.minmax_idx2 +( + u64 UInt64, + i32 Int32 +) ENGINE = MergeTree() + idx2 BY u64 * i32 TYPE minmax GRANULARITY 10 +INDEXES idx1 BY u64 * i32 TYPE minmax GRANULARITY 10, +ORDER BY u64; + +INSERT INTO test.minmax_idx2 VALUES (1, 2); +INSERT INTO test.minmax_idx2 VALUES (1, 2); + +SELECT * FROM test.minmax_idx2 WHERE u64 * i32 = 3; + +ALTER TABLE test.minmax_idx2 DROP INDEX idx1, DROP INDEX idx2; + +SHOW CREATE TABLE test.minmax_idx2; + +SELECT * FROM test.minmax_idx2 WHERE u64 * i32 = 3; + +DROP TABLE test.minmax_idx; +DROP TABLE test.minmax_idx2; \ No newline at end of file