From 6143f99f7ad3a4dcb2ae6cd9646dadc7ff5cf23d Mon Sep 17 00:00:00 2001 From: sunny19930321 Date: Fri, 30 Aug 2024 15:02:09 +0800 Subject: [PATCH] fix: change alter query to ternary expression --- src/Interpreters/InterpreterDeleteQuery.cpp | 12 +++--------- src/Parsers/ASTDeleteQuery.h | 2 +- .../02352_lightweight_delete_in_partition.sql | 4 ++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/Interpreters/InterpreterDeleteQuery.cpp b/src/Interpreters/InterpreterDeleteQuery.cpp index 69aae3ae909..c0d840b8c5a 100644 --- a/src/Interpreters/InterpreterDeleteQuery.cpp +++ b/src/Interpreters/InterpreterDeleteQuery.cpp @@ -78,15 +78,9 @@ BlockIO InterpreterDeleteQuery::execute() String alter_query = "ALTER TABLE " + table->getStorageID().getFullTableName() + (delete_query.cluster.empty() ? "" : " ON CLUSTER " + backQuoteIfNeed(delete_query.cluster)) - + " UPDATE `_row_exists` = 0 WHERE " + serializeAST(*delete_query.predicate); - if (delete_query.partition) - { - alter_query = - "ALTER TABLE " + table->getStorageID().getFullTableName() - + (delete_query.cluster.empty() ? "" : " ON CLUSTER " + backQuoteIfNeed(delete_query.cluster)) - + " UPDATE `_row_exists` = 0 IN PARTITION " + serializeAST(*delete_query.partition) + " WHERE " - + serializeAST(*delete_query.predicate); - } + + " UPDATE `_row_exists` = 0" + + (delete_query.partition ? " IN PARTITION " + serializeAST(*delete_query.partition) : "") + + " WHERE " + serializeAST(*delete_query.predicate); ParserAlterQuery parser; ASTPtr alter_ast = parseQuery( diff --git a/src/Parsers/ASTDeleteQuery.h b/src/Parsers/ASTDeleteQuery.h index 6adc9b6a1c8..fcbeafac294 100644 --- a/src/Parsers/ASTDeleteQuery.h +++ b/src/Parsers/ASTDeleteQuery.h @@ -19,7 +19,7 @@ public: return removeOnCluster(clone(), params.default_database); } - /** Used in DROP PARTITION, ATTACH PARTITION FROM, UPDATE, DELETE, DELETE FROM queries. + /** Used in DELETE FROM queries. * The value or ID of the partition is stored here. */ ASTPtr partition; diff --git a/tests/queries/0_stateless/02352_lightweight_delete_in_partition.sql b/tests/queries/0_stateless/02352_lightweight_delete_in_partition.sql index 08cf5816f74..04371d273fd 100644 --- a/tests/queries/0_stateless/02352_lightweight_delete_in_partition.sql +++ b/tests/queries/0_stateless/02352_lightweight_delete_in_partition.sql @@ -5,10 +5,10 @@ CREATE TABLE t_merge_tree(time Date, id String , name String) ENGINE = MergeTree CREATE TABLE t_replicated_merge_tree(time Date, id String, name String) ENGINE = ReplicatedMergeTree('/test/02352/{database}/t_rep','1') PARTITION BY time ORDER BY id; INSERT INTO t_merge_tree select '2024-08-01', '1', toString(number) FROM numbers(100); -INSERT INTO t_merge_tree select '2024-08-02', '2', toString(number) FROM numbers(100); +INSERT INTO t_merge_tree select '2024-08-02', '1', toString(number) FROM numbers(100); INSERT INTO t_replicated_merge_tree select '2024-08-01', '1', toString(number) FROM numbers(100); -INSERT INTO t_replicated_merge_tree select '2024-08-02', '2', toString(number) FROM numbers(100); +INSERT INTO t_replicated_merge_tree select '2024-08-02', '1', toString(number) FROM numbers(100); SELECT COUNT() FROM t_merge_tree; SELECT COUNT() FROM t_replicated_merge_tree;