From b19d2f0bd2b3e761549d2a5539fbf51977ad1b70 Mon Sep 17 00:00:00 2001 From: Jason Mo Date: Tue, 22 Aug 2023 17:18:19 +0800 Subject: [PATCH] parser: fix parser identifier with dot --- parser/misc.go | 12 +++++++++++- parser/parser_test.go | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/parser/misc.go b/parser/misc.go index cf87a2357d553..462f024130978 100644 --- a/parser/misc.go +++ b/parser/misc.go @@ -1066,10 +1066,20 @@ var hintTokenMap = map[string]int{ func (s *Scanner) isTokenIdentifier(lit string, offset int) int { // An identifier before or after '.' means it is part of a qualified identifier. // We do not parse it as keyword. - if s.r.peek() == '.' || (offset > 0 && s.r.s[offset-1] == '.') { + if s.r.peek() == '.' { return 0 } + for idx := offset - 1; idx >= 0; idx-- { + if s.r.s[idx] == ' ' { + continue + } else if s.r.s[idx] == '.' { + return 0 + } else { + break + } + } + buf := &s.buf buf.Reset() buf.Grow(len(lit)) diff --git a/parser/parser_test.go b/parser/parser_test.go index 94e5864ddfefa..4550b89d25f98 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -1058,6 +1058,7 @@ AAAAAAAAAAAA5gm5Mg== {"select `t`.`1a`.1 from t;", true, "SELECT `t`.`1a`.`1` FROM `t`"}, {"select * from 1db.1table;", true, "SELECT * FROM `1db`.`1table`"}, + {"select * from t where t. status = 1;", true, "SELECT * FROM `t` WHERE `t`.`status`=1"}, // for show placement {"SHOW PLACEMENT", true, "SHOW PLACEMENT"},