Skip to content

Commit d7968a1

Browse files
kyleconroyclaude
andcommitted
Add KILL QUERY SETTINGS support and fix operator mapping
- Add Settings field to KillQuery struct - Parse SETTINGS clause for KILL QUERY/MUTATION statements - Map comparison operators to function names in EXPLAIN output (e.g., = becomes equals, != becomes notEquals) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 90ff84d commit d7968a1

File tree

4 files changed

+34
-7
lines changed

4 files changed

+34
-7
lines changed

ast/ast.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,6 +1069,7 @@ type KillQuery struct {
10691069
Sync bool `json:"sync,omitempty"` // SYNC mode (default false = ASYNC)
10701070
Test bool `json:"test,omitempty"` // TEST mode
10711071
Format string `json:"format,omitempty"` // FORMAT clause
1072+
Settings []*SettingExpr `json:"settings,omitempty"`
10721073
}
10731074

10741075
func (k *KillQuery) Pos() token.Position { return k.Position }

internal/explain/statements.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2391,7 +2391,23 @@ func explainKillQuery(sb *strings.Builder, n *ast.KillQuery, indent string, dept
23912391
if n.Where != nil {
23922392
switch expr := n.Where.(type) {
23932393
case *ast.BinaryExpr:
2394-
funcName = "Function_" + strings.ToLower(expr.Op)
2394+
// Map operators to function names
2395+
opName := strings.ToLower(expr.Op)
2396+
switch opName {
2397+
case "=":
2398+
opName = "equals"
2399+
case "!=", "<>":
2400+
opName = "notEquals"
2401+
case "<":
2402+
opName = "less"
2403+
case "<=":
2404+
opName = "lessOrEquals"
2405+
case ">":
2406+
opName = "greater"
2407+
case ">=":
2408+
opName = "greaterOrEquals"
2409+
}
2410+
funcName = "Function_" + opName
23952411
case *ast.FunctionCall:
23962412
funcName = "Function_" + expr.Name
23972413
default:
@@ -2407,14 +2423,17 @@ func explainKillQuery(sb *strings.Builder, n *ast.KillQuery, indent string, dept
24072423
mode = "TEST"
24082424
}
24092425

2410-
// Count children: WHERE expression + FORMAT identifier
2426+
// Count children: WHERE expression + FORMAT identifier + Settings
24112427
children := 0
24122428
if n.Where != nil {
24132429
children++
24142430
}
24152431
if n.Format != "" {
24162432
children++
24172433
}
2434+
if len(n.Settings) > 0 {
2435+
children++
2436+
}
24182437

24192438
// Header: KillQueryQuery Function_xxx MODE (children N)
24202439
if funcName != "" {
@@ -2432,6 +2451,11 @@ func explainKillQuery(sb *strings.Builder, n *ast.KillQuery, indent string, dept
24322451
if n.Format != "" {
24332452
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Format)
24342453
}
2454+
2455+
// Output Settings
2456+
if len(n.Settings) > 0 {
2457+
fmt.Fprintf(sb, "%s Set\n", indent)
2458+
}
24352459
}
24362460

24372461
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
@@ -8380,6 +8380,12 @@ endModifiers:
83808380
}
83818381
}
83828382

8383+
// Parse SETTINGS clause
8384+
if p.currentIs(token.SETTINGS) {
8385+
p.nextToken() // skip SETTINGS
8386+
query.Settings = p.parseSettingsList()
8387+
}
8388+
83838389
return query
83848390
}
83858391

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt25": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)