Skip to content

Commit 38227b2

Browse files
committed
Add SETTINGS clause support for lightweight DELETE statements
Parse and output SETTINGS clause for DELETE FROM queries, matching ClickHouse's EXPLAIN AST format.
1 parent d89d45d commit 38227b2

10 files changed

Lines changed: 21 additions & 40 deletions

File tree

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,7 @@ type DeleteQuery struct {
709709
Database string `json:"database,omitempty"`
710710
Table string `json:"table"`
711711
Where Expression `json:"where,omitempty"`
712+
Settings []*SettingExpr `json:"settings,omitempty"`
712713
}
713714

714715
func (d *DeleteQuery) Pos() token.Position { return d.Position }

internal/explain/statements.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2026,17 +2026,23 @@ func explainDeleteQuery(sb *strings.Builder, n *ast.DeleteQuery, indent string,
20262026
return
20272027
}
20282028

2029-
// Count children: Where expression + table identifier
2029+
// Count children: Where expression + table identifier + settings
20302030
children := 1 // table identifier
20312031
if n.Where != nil {
20322032
children++
20332033
}
2034+
if len(n.Settings) > 0 {
2035+
children++
2036+
}
20342037

20352038
fmt.Fprintf(sb, "%sDeleteQuery %s (children %d)\n", indent, n.Table, children)
20362039
if n.Where != nil {
20372040
Node(sb, n.Where, depth+1)
20382041
}
20392042
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Table)
2043+
if len(n.Settings) > 0 {
2044+
fmt.Fprintf(sb, "%s Set\n", indent)
2045+
}
20402046
}
20412047

20422048
func explainCheckQuery(sb *strings.Builder, n *ast.CheckQuery, indent string) {

parser/parser.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6002,6 +6002,12 @@ func (p *Parser) parseDelete() *ast.DeleteQuery {
60026002
del.Where = p.parseExpression(LOWEST)
60036003
}
60046004

6005+
// Parse SETTINGS clause
6006+
if p.currentIs(token.SETTINGS) {
6007+
p.nextToken() // skip SETTINGS
6008+
del.Settings = p.parseSettingsList()
6009+
}
6010+
60056011
return del
60066012
}
60076013

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt16": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt8": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true,
4-
"stmt7": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt9": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true,
4-
"stmt16": true,
5-
"stmt8": true
6-
}
7-
}
1+
{}

0 commit comments

Comments
 (0)