diff --git a/dbms/src/Parsers/ParserAlterQuery.cpp b/dbms/src/Parsers/ParserAlterQuery.cpp index f823ee84623..a4ffcab7c98 100644 --- a/dbms/src/Parsers/ParserAlterQuery.cpp +++ b/dbms/src/Parsers/ParserAlterQuery.cpp @@ -157,11 +157,10 @@ bool ParserAlterCommand::parseImpl(Pos & pos, ASTPtr & node, Expected & expected command->clear_index = true; command->detach = false; - if (s_in_partition.ignore(pos, expected)) - { - if (!parser_partition.parse(pos, command->partition, expected)) - return false; - } + if (!s_in_partition.ignore(pos, expected)) + return false; + if (!parser_partition.parse(pos, command->partition, expected)) + return false; } else if (s_materialize_index.ignore(pos, expected)) { diff --git a/dbms/src/Storages/AlterCommands.cpp b/dbms/src/Storages/AlterCommands.cpp index 88f3e909f49..5d8e8c97ec1 100644 --- a/dbms/src/Storages/AlterCommands.cpp +++ b/dbms/src/Storages/AlterCommands.cpp @@ -153,10 +153,10 @@ std::optional AlterCommand::parse(const ASTAlterCommand * command_ return command; } - else if (command_ast->type == ASTAlterCommand::DROP_INDEX) + else if (command_ast->type == ASTAlterCommand::DROP_INDEX && !command_ast->partition) { if (command_ast->clear_column) - throw Exception("\"ALTER TABLE table CLEAR COLUMN column\" queries are not supported yet. Use \"CLEAR COLUMN column IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED); + throw Exception("\"ALTER TABLE table CLEAR INDEX index\" queries are not supported yet. Use \"CLEAR INDEX index IN PARTITION\".", ErrorCodes::NOT_IMPLEMENTED); AlterCommand command; command.type = AlterCommand::DROP_INDEX; diff --git a/dbms/src/Storages/StorageMergeTree.cpp b/dbms/src/Storages/StorageMergeTree.cpp index 8f3539e0cc2..08599a6dd72 100644 --- a/dbms/src/Storages/StorageMergeTree.cpp +++ b/dbms/src/Storages/StorageMergeTree.cpp @@ -910,8 +910,8 @@ void StorageMergeTree::alterPartition(const ASTPtr & query, const PartitionComma case PartitionCommand::CLEAR_INDEX: { AlterCommand alter_command; - alter_command.type = AlterCommand::DROP_COLUMN; - alter_command.column_name = get(command.index_name); + alter_command.type = AlterCommand::DROP_INDEX; + alter_command.index_name = get(command.index_name); clearColumnOrIndexInPartition(command.partition, alter_command, context); } break; diff --git a/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.reference b/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.reference index c3e1b8bdb9a..a2feb54381d 100644 --- a/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.reference +++ b/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.reference @@ -1,4 +1,6 @@ +5 + "rows_read": 4, 5 "rows_read": 6, 5 - "rows_read": 10, + "rows_read": 4, \ No newline at end of file diff --git a/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.sh b/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.sh index 1d08f9facfc..123b2eb38a4 100755 --- a/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.sh +++ b/dbms/tests/queries/0_stateless/00944_clear_index_in_partition.sh @@ -25,10 +25,10 @@ $CLICKHOUSE_CLIENT --query="INSERT INTO test.minmax_idx VALUES (1, 1, 1), (2, 1, 1), (3, 1, 1), -(4, 2, 3), -(5, 2, 3), -(6, 2, 2), -(7, 2, 2), +(4, 1, 1), +(5, 2, 1), +(6, 1, 2), +(7, 1, 2), (8, 1, 2), (9, 1, 2)" @@ -40,4 +40,10 @@ $CLICKHOUSE_CLIENT --query="ALTER TABLE test.minmax_idx CLEAR INDEX idx IN PARTI $CLICKHOUSE_CLIENT --query="SELECT count() FROM test.minmax_idx WHERE i64 = 2;" $CLICKHOUSE_CLIENT --query="SELECT count() FROM test.minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read" -$CLICKHOUSE_CLIENT --query="DROP TABLE test.minmax_idx" +$CLICKHOUSE_CLIENT --query="ALTER TABLE test.minmax_idx MATERIALIZE INDEX idx IN PARTITION 1;" + +$CLICKHOUSE_CLIENT --query="SELECT count() FROM test.minmax_idx WHERE i64 = 2;" +$CLICKHOUSE_CLIENT --query="SELECT count() FROM test.minmax_idx WHERE i64 = 2 FORMAT JSON" | grep "rows_read" + + +#$CLICKHOUSE_CLIENT --query="DROP TABLE test.minmax_idx"