From cb6e9ad407d447f0ea9102af1d8b6e3bbf15b9d7 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Wed, 19 Jun 2024 20:16:56 +0200 Subject: [PATCH] Use `node.Name` only if set Signed-off-by: Tim Vaillancourt --- go/vt/sqlparser/ast_format.go | 7 ++++++- go/vt/sqlparser/ast_format_fast.go | 10 ++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/go/vt/sqlparser/ast_format.go b/go/vt/sqlparser/ast_format.go index 1212f9c0e90..830420e610d 100644 --- a/go/vt/sqlparser/ast_format.go +++ b/go/vt/sqlparser/ast_format.go @@ -2656,7 +2656,12 @@ func (node *Count) Format(buf *TrackedBuffer) { } func (node *CountStar) Format(buf *TrackedBuffer) { - buf.astPrintf(node, "%s(*)", node.Name) + if node.Name != "" { + buf.astPrintf(node, "%s(*)", node.Name) + } else { + buf.astPrintf(node, "%s(", node.AggrName()) + buf.WriteString("*)") + } } func (node *Avg) Format(buf *TrackedBuffer) { diff --git a/go/vt/sqlparser/ast_format_fast.go b/go/vt/sqlparser/ast_format_fast.go index 4d4e033733f..8115288278e 100644 --- a/go/vt/sqlparser/ast_format_fast.go +++ b/go/vt/sqlparser/ast_format_fast.go @@ -3482,8 +3482,14 @@ func (node *Count) formatFast(buf *TrackedBuffer) { } func (node *CountStar) formatFast(buf *TrackedBuffer) { - buf.WriteString(node.Name) - buf.WriteString("(*)") + if node.Name != "" { + buf.WriteString(node.Name) + buf.WriteString("(*)") + } else { + buf.WriteString(node.AggrName()) + buf.WriteByte('(') + buf.WriteString("*)") + } } func (node *Avg) formatFast(buf *TrackedBuffer) {