Merge pull request #41533 from kssenii/add-settings-for-delete

Support `SETTINGS` in `DELETE ...` query
This commit is contained in:
Kseniia Sumarokova 2022-09-21 13:45:51 +02:00 committed by GitHub
commit d598802988
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 0 deletions

View File

@ -20,6 +20,12 @@ ASTPtr ASTDeleteQuery::clone() const
res->children.push_back(res->predicate);
}
if (settings_ast)
{
res->settings_ast = settings_ast->clone();
res->children.push_back(res->settings_ast);
}
cloneTableOptions(*res);
return res;
}

View File

@ -2,6 +2,7 @@
#include <Parsers/ASTDeleteQuery.h>
#include <Parsers/parseDatabaseAndTableName.h>
#include <Parsers/ExpressionListParsers.h>
#include <Parsers/ParserSetQuery.h>
namespace DB
@ -16,6 +17,7 @@ bool ParserDeleteQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
ParserKeyword s_from("FROM");
ParserKeyword s_where("WHERE");
ParserExpression parser_exp_elem;
ParserKeyword s_settings("SETTINGS");
if (s_delete.ignore(pos, expected))
{
@ -30,6 +32,14 @@ bool ParserDeleteQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (!parser_exp_elem.parse(pos, query->predicate, expected))
return false;
if (s_settings.ignore(pos, expected))
{
ParserSetQuery parser_settings(true);
if (!parser_settings.parse(pos, query->settings_ast, expected))
return false;
}
}
else
return false;
@ -43,6 +53,9 @@ bool ParserDeleteQuery::parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
if (query->table)
query->children.push_back(query->table);
if (query->settings_ast)
query->children.push_back(query->settings_ast);
return true;
}

View File

@ -0,0 +1 @@
500000

View File

@ -0,0 +1,6 @@
drop table if exists test;
create table test (id Int32, key String) engine=MergeTree() order by tuple();
insert into test select number, toString(number) from numbers(1000000);
set allow_experimental_lightweight_delete=1;
delete from test where id % 2 = 0 SETTINGS mutations_sync=1;
select count() from test;