Skip to content

Commit cbde83c

Browse files
kyleconroyclaude
andcommitted
Fix SYSTEM FLUSH DISTRIBUTED table name parsing
- Stop command parsing after "FLUSH DISTRIBUTED" to treat next token as table name - Set DuplicateTableOutput for FLUSH DISTRIBUTED to output table name twice Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent b218c3d commit cbde83c

2 files changed

Lines changed: 13 additions & 11 deletions

File tree

parser/parser.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6821,7 +6821,10 @@ func (p *Parser) parseSystem() *ast.SystemQuery {
68216821
strings.HasSuffix(upperCmd, " MOVES") ||
68226822
strings.HasSuffix(upperCmd, " FETCHES") ||
68236823
strings.HasSuffix(upperCmd, " SENDS") ||
6824-
strings.HasSuffix(upperCmd, " MUTATIONS") {
6824+
strings.HasSuffix(upperCmd, " MUTATIONS") ||
6825+
upperCmd == "FLUSH DISTRIBUTED" ||
6826+
upperCmd == "STOP DISTRIBUTED SENDS" ||
6827+
upperCmd == "START DISTRIBUTED SENDS" {
68256828
// Next token should be the table name
68266829
break
68276830
}
@@ -6901,13 +6904,13 @@ func (p *Parser) parseSystem() *ast.SystemQuery {
69016904
}
69026905
} else {
69036906
// For certain commands, the table name appears as both database and table in EXPLAIN
6907+
// But for FLUSH DISTRIBUTED, use DuplicateTableOutput instead of setting both
69046908
upperCmd := strings.ToUpper(sys.Command)
69056909
if strings.Contains(upperCmd, "RELOAD DICTIONARY") ||
69066910
strings.Contains(upperCmd, "DROP REPLICA") ||
69076911
strings.Contains(upperCmd, "RESTORE REPLICA") ||
69086912
strings.Contains(upperCmd, "STOP DISTRIBUTED SENDS") ||
6909-
strings.Contains(upperCmd, "START DISTRIBUTED SENDS") ||
6910-
strings.Contains(upperCmd, "FLUSH DISTRIBUTED") {
6913+
strings.Contains(upperCmd, "START DISTRIBUTED SENDS") {
69116914
sys.Database = tableName
69126915
sys.Table = tableName
69136916
} else {
@@ -6917,11 +6920,14 @@ func (p *Parser) parseSystem() *ast.SystemQuery {
69176920
}
69186921

69196922
// Set DuplicateTableOutput for commands that need database/table output twice
6920-
// Only duplicate when we have a qualified name (database != table)
69216923
upperCmd := strings.ToUpper(sys.Command)
6922-
if strings.Contains(upperCmd, "STOP DISTRIBUTED SENDS") ||
6924+
if strings.Contains(upperCmd, "FLUSH DISTRIBUTED") {
6925+
// FLUSH DISTRIBUTED always outputs the table name twice (even if unqualified)
6926+
if sys.Table != "" {
6927+
sys.DuplicateTableOutput = true
6928+
}
6929+
} else if strings.Contains(upperCmd, "STOP DISTRIBUTED SENDS") ||
69236930
strings.Contains(upperCmd, "START DISTRIBUTED SENDS") ||
6924-
strings.Contains(upperCmd, "FLUSH DISTRIBUTED") ||
69256931
strings.Contains(upperCmd, "RELOAD DICTIONARY") {
69266932
// Only set duplicate if database and table are different (qualified name)
69276933
if sys.Database != sys.Table {
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+
{}

0 commit comments

Comments
 (0)