From 03590c1bc87c98c121ee902701f6017d9df9e56f Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Mon, 14 Aug 2023 18:02:00 +0800 Subject: [PATCH] parser: reset `lexer.identifierDot` correctly when reusing parsers (#45903) (#45908) close pingcap/tidb#45898 --- parser/lexer.go | 1 + parser/parser_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/parser/lexer.go b/parser/lexer.go index 659fc14dd9235..37b952efdbc79 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -98,6 +98,7 @@ func (s *Scanner) reset(sql string) { s.stmtStartPos = 0 s.inBangComment = false s.lastKeyword = 0 + s.identifierDot = false } func (s *Scanner) stmtText() string { diff --git a/parser/parser_test.go b/parser/parser_test.go index 85e62987e96ec..3e96ace30f832 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -6722,3 +6722,15 @@ func TestNonTransactionalDelete(t *testing.T) { RunTest(t, cases, false) } + +func TestIssue45898(t *testing.T) { + p := parser.New() + p.ParseSQL("a.") + stmts, _, err := p.ParseSQL("select count(1) from t") + require.NoError(t, err) + var sb strings.Builder + restoreCtx := NewRestoreCtx(DefaultRestoreFlags, &sb) + sb.Reset() + stmts[0].Restore(restoreCtx) + require.Equal(t, "SELECT COUNT(1) FROM `t`", sb.String()) +}