From 4c7f6a1ac1cf9f3d98fc3c9bfa8ea73ab7736fdf Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Thu, 4 Jul 2024 20:40:28 +0800 Subject: [PATCH] parser, infoschema, executor: Add information_schema.keywords (#48807) (#54219) close pingcap/tidb#48801 --- .gitignore | 2 + pkg/executor/builder.go | 3 +- pkg/executor/infoschema_reader.go | 13 + .../infoschema_reader_internal_test.go | 8 + pkg/infoschema/tables.go | 9 + pkg/parser/BUILD.bazel | 3 + pkg/parser/Makefile | 8 +- pkg/parser/generate.go | 4 + pkg/parser/generate_keyword/BUILD.bazel | 11 +- .../generate_keyword/genkeyword_test.go | 15 + pkg/parser/keywords.go | 673 ++++++++++++++++++ pkg/parser/keywords_test.go | 57 ++ 12 files changed, 803 insertions(+), 3 deletions(-) create mode 100644 pkg/parser/generate.go create mode 100644 pkg/parser/generate_keyword/genkeyword_test.go create mode 100644 pkg/parser/keywords.go create mode 100644 pkg/parser/keywords_test.go diff --git a/.gitignore b/.gitignore index 9c4a07aa04bbf..933f46b996c3d 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,5 @@ bazel-tidb MODULE.bazel.lock .ijwb/ /oom_record/ +*.log.json +genkeyword diff --git a/pkg/executor/builder.go b/pkg/executor/builder.go index cf74d3130bf55..7c3325a204d5e 100644 --- a/pkg/executor/builder.go +++ b/pkg/executor/builder.go @@ -2097,7 +2097,8 @@ func (b *executorBuilder) buildMemTable(v *plannercore.PhysicalMemTable) exec.Ex strings.ToLower(infoschema.ClusterTableMemoryUsageOpsHistory), strings.ToLower(infoschema.TableResourceGroups), strings.ToLower(infoschema.TableRunawayWatches), - strings.ToLower(infoschema.TableCheckConstraints): + strings.ToLower(infoschema.TableCheckConstraints), + strings.ToLower(infoschema.TableKeywords): memTracker := memory.NewTracker(v.ID(), -1) memTracker.AttachTo(b.ctx.GetSessionVars().StmtCtx.MemTracker) return &MemTableReaderExec{ diff --git a/pkg/executor/infoschema_reader.go b/pkg/executor/infoschema_reader.go index acdda6baea985..0d2fe1fdc3696 100644 --- a/pkg/executor/infoschema_reader.go +++ b/pkg/executor/infoschema_reader.go @@ -43,6 +43,7 @@ import ( "github.com/pingcap/tidb/pkg/infoschema" "github.com/pingcap/tidb/pkg/kv" "github.com/pingcap/tidb/pkg/meta/autoid" + "github.com/pingcap/tidb/pkg/parser" "github.com/pingcap/tidb/pkg/parser/charset" "github.com/pingcap/tidb/pkg/parser/model" "github.com/pingcap/tidb/pkg/parser/mysql" @@ -197,6 +198,8 @@ func (e *memtableRetriever) retrieve(ctx context.Context, sctx sessionctx.Contex err = e.setDataFromRunawayWatches(sctx) case infoschema.TableCheckConstraints: err = e.setDataFromCheckConstraints(sctx, dbs) + case infoschema.TableKeywords: + err = e.setDataFromKeywords() } if err != nil { return nil, err @@ -3390,6 +3393,16 @@ func (e *memtableRetriever) setDataFromResourceGroups() error { return nil } +func (e *memtableRetriever) setDataFromKeywords() error { + rows := make([][]types.Datum, 0, len(parser.Keywords)) + for _, kw := range parser.Keywords { + row := types.MakeDatums(kw.Word, kw.Reserved) + rows = append(rows, row) + } + e.rows = rows + return nil +} + func checkRule(rule *label.Rule) (dbName, tableName string, partitionName string, err error) { s := strings.Split(rule.ID, "/") if len(s) < 3 { diff --git a/pkg/executor/infoschema_reader_internal_test.go b/pkg/executor/infoschema_reader_internal_test.go index 3585c50e3787d..f25892e06ffcc 100644 --- a/pkg/executor/infoschema_reader_internal_test.go +++ b/pkg/executor/infoschema_reader_internal_test.go @@ -71,3 +71,11 @@ func TestSetDataFromCheckConstraints(t *testing.T) { require.Equal(t, types.NewStringDatum("t2_c1"), mt.rows[0][2]) require.Equal(t, types.NewStringDatum("(id<10)"), mt.rows[0][3]) } + +func TestSetDataFromKeywords(t *testing.T) { + mt := memtableRetriever{} + err := mt.setDataFromKeywords() + require.NoError(t, err) + require.Equal(t, types.NewStringDatum("ADD"), mt.rows[0][0]) // Keyword: ADD + require.Equal(t, types.NewIntDatum(1), mt.rows[0][1]) // Reserved: true(1) +} diff --git a/pkg/infoschema/tables.go b/pkg/infoschema/tables.go index 9fe6ccdd21cda..a6d90cb9c2ab3 100644 --- a/pkg/infoschema/tables.go +++ b/pkg/infoschema/tables.go @@ -209,6 +209,8 @@ const ( TableRunawayWatches = "RUNAWAY_WATCHES" // TableCheckConstraints is the list of CHECK constraints. TableCheckConstraints = "CHECK_CONSTRAINTS" + // TableKeywords is the list of keywords. + TableKeywords = "KEYWORDS" ) const ( @@ -318,6 +320,7 @@ var tableIDMap = map[string]int64{ TableResourceGroups: autoid.InformationSchemaDBID + 88, TableRunawayWatches: autoid.InformationSchemaDBID + 89, TableCheckConstraints: autoid.InformationSchemaDBID + 90, + TableKeywords: autoid.InformationSchemaDBID + 92, } // columnInfo represents the basic column information of all kinds of INFORMATION_SCHEMA tables @@ -1648,6 +1651,11 @@ var tableCheckConstraintsCols = []columnInfo{ {name: "CHECK_CLAUSE", tp: mysql.TypeLongBlob, size: types.UnspecifiedLength, flag: mysql.NotNullFlag}, } +var tableKeywords = []columnInfo{ + {name: "WORD", tp: mysql.TypeVarchar, size: 128}, + {name: "RESERVED", tp: mysql.TypeLong, size: 11}, +} + // GetShardingInfo returns a nil or description string for the sharding information of given TableInfo. // The returned description string may be: // - "NOT_SHARDED": for tables that SHARD_ROW_ID_BITS is not specified. @@ -2166,6 +2174,7 @@ var tableNameToColumns = map[string][]columnInfo{ TableResourceGroups: tableResourceGroupsCols, TableRunawayWatches: tableRunawayWatchListCols, TableCheckConstraints: tableCheckConstraintsCols, + TableKeywords: tableKeywords, } func createInfoSchemaTable(_ autoid.Allocators, meta *model.TableInfo) (table.Table, error) { diff --git a/pkg/parser/BUILD.bazel b/pkg/parser/BUILD.bazel index 516fbc1dbf7cb..c1229045532ff 100644 --- a/pkg/parser/BUILD.bazel +++ b/pkg/parser/BUILD.bazel @@ -9,8 +9,10 @@ go_library( name = "parser", srcs = [ "digester.go", + "generate.go", "hintparser.go", "hintparserimpl.go", + "keywords.go", "lexer.go", "misc.go", "parser.go", @@ -41,6 +43,7 @@ go_test( "consistent_test.go", "digester_test.go", "hintparser_test.go", + "keywords_test.go", "lexer_test.go", "main_test.go", "parser_test.go", diff --git a/pkg/parser/Makefile b/pkg/parser/Makefile index 641b2fc7681d4..f7a203f03951b 100644 --- a/pkg/parser/Makefile +++ b/pkg/parser/Makefile @@ -1,12 +1,18 @@ .PHONY: all parser clean -all: fmt parser +all: fmt parser generate test: fmt parser sh test.sh parser: parser.go hintparser.go +genkeyword: generate_keyword/genkeyword.go + go build -C generate_keyword -o ../genkeyword + +generate: genkeyword parser.y + go generate + %arser.go: prefix = $(@:parser.go=) %arser.go: %arser.y bin/goyacc @echo "bin/goyacc -o $@ -p yy$(prefix) -t $(prefix)Parser $<" diff --git a/pkg/parser/generate.go b/pkg/parser/generate.go new file mode 100644 index 0000000000000..5f2d38640cb27 --- /dev/null +++ b/pkg/parser/generate.go @@ -0,0 +1,4 @@ +package parser + +// Generate keywords.go +//go:generate ./genkeyword diff --git a/pkg/parser/generate_keyword/BUILD.bazel b/pkg/parser/generate_keyword/BUILD.bazel index e5649ab2ad6e2..c37b690d6b1c3 100644 --- a/pkg/parser/generate_keyword/BUILD.bazel +++ b/pkg/parser/generate_keyword/BUILD.bazel @@ -1,4 +1,4 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") go_library( name = "generate_keyword_lib", @@ -12,3 +12,12 @@ go_binary( embed = [":generate_keyword_lib"], visibility = ["//visibility:public"], ) + +go_test( + name = "generate_keyword_test", + timeout = "short", + srcs = ["genkeyword_test.go"], + embed = [":generate_keyword_lib"], + flaky = True, + deps = ["@com_github_stretchr_testify//require"], +) diff --git a/pkg/parser/generate_keyword/genkeyword_test.go b/pkg/parser/generate_keyword/genkeyword_test.go new file mode 100644 index 0000000000000..2a7a7d5b24722 --- /dev/null +++ b/pkg/parser/generate_keyword/genkeyword_test.go @@ -0,0 +1,15 @@ +package main + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +func TestParseLine(t *testing.T) { + add := parseLine(" add \"ADD\"") + require.Equal(t, add, "ADD") + + tso := parseLine(" tidbCurrentTSO \"TiDB_CURRENT_TSO\"") + require.Equal(t, tso, "TiDB_CURRENT_TSO") +} diff --git a/pkg/parser/keywords.go b/pkg/parser/keywords.go new file mode 100644 index 0000000000000..fda6d5e1906dc --- /dev/null +++ b/pkg/parser/keywords.go @@ -0,0 +1,673 @@ +// Copyright 2023 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package parser + +// WARNING: This file is generated by 'genkeyword' + +// KeywordsType defines the attributes of keywords +type KeywordsType struct { + Word string + Reserved bool + Section string +} + +// Keywords is used for all keywords in TiDB +var Keywords = []KeywordsType{ + {"ADD", true, "reserved"}, + {"ALL", true, "reserved"}, + {"ALTER", true, "reserved"}, + {"ANALYZE", true, "reserved"}, + {"AND", true, "reserved"}, + {"ARRAY", true, "reserved"}, + {"AS", true, "reserved"}, + {"ASC", true, "reserved"}, + {"BETWEEN", true, "reserved"}, + {"BIGINT", true, "reserved"}, + {"BINARY", true, "reserved"}, + {"BLOB", true, "reserved"}, + {"BOTH", true, "reserved"}, + {"BY", true, "reserved"}, + {"CALL", true, "reserved"}, + {"CASCADE", true, "reserved"}, + {"CASE", true, "reserved"}, + {"CHANGE", true, "reserved"}, + {"CHAR", true, "reserved"}, + {"CHARACTER", true, "reserved"}, + {"CHECK", true, "reserved"}, + {"COLLATE", true, "reserved"}, + {"COLUMN", true, "reserved"}, + {"CONSTRAINT", true, "reserved"}, + {"CONTINUE", true, "reserved"}, + {"CONVERT", true, "reserved"}, + {"CREATE", true, "reserved"}, + {"CROSS", true, "reserved"}, + {"CUME_DIST", true, "reserved"}, + {"CURRENT_DATE", true, "reserved"}, + {"CURRENT_ROLE", true, "reserved"}, + {"CURRENT_TIME", true, "reserved"}, + {"CURRENT_TIMESTAMP", true, "reserved"}, + {"CURRENT_USER", true, "reserved"}, + {"CURSOR", true, "reserved"}, + {"DATABASE", true, "reserved"}, + {"DATABASES", true, "reserved"}, + {"DAY_HOUR", true, "reserved"}, + {"DAY_MICROSECOND", true, "reserved"}, + {"DAY_MINUTE", true, "reserved"}, + {"DAY_SECOND", true, "reserved"}, + {"DECIMAL", true, "reserved"}, + {"DEFAULT", true, "reserved"}, + {"DELAYED", true, "reserved"}, + {"DELETE", true, "reserved"}, + {"DENSE_RANK", true, "reserved"}, + {"DESC", true, "reserved"}, + {"DESCRIBE", true, "reserved"}, + {"DISTINCT", true, "reserved"}, + {"DISTINCTROW", true, "reserved"}, + {"DIV", true, "reserved"}, + {"DOUBLE", true, "reserved"}, + {"DROP", true, "reserved"}, + {"DUAL", true, "reserved"}, + {"ELSE", true, "reserved"}, + {"ELSEIF", true, "reserved"}, + {"ENCLOSED", true, "reserved"}, + {"ESCAPED", true, "reserved"}, + {"EXCEPT", true, "reserved"}, + {"EXISTS", true, "reserved"}, + {"EXIT", true, "reserved"}, + {"EXPLAIN", true, "reserved"}, + {"FALSE", true, "reserved"}, + {"FETCH", true, "reserved"}, + {"FIRST_VALUE", true, "reserved"}, + {"FLOAT", true, "reserved"}, + {"FLOAT4", true, "reserved"}, + {"FLOAT8", true, "reserved"}, + {"FOR", true, "reserved"}, + {"FORCE", true, "reserved"}, + {"FOREIGN", true, "reserved"}, + {"FROM", true, "reserved"}, + {"FULLTEXT", true, "reserved"}, + {"GENERATED", true, "reserved"}, + {"GRANT", true, "reserved"}, + {"GROUP", true, "reserved"}, + {"GROUPS", true, "reserved"}, + {"HAVING", true, "reserved"}, + {"HIGH_PRIORITY", true, "reserved"}, + {"HOUR_MICROSECOND", true, "reserved"}, + {"HOUR_MINUTE", true, "reserved"}, + {"HOUR_SECOND", true, "reserved"}, + {"IF", true, "reserved"}, + {"IGNORE", true, "reserved"}, + {"ILIKE", true, "reserved"}, + {"IN", true, "reserved"}, + {"INDEX", true, "reserved"}, + {"INFILE", true, "reserved"}, + {"INNER", true, "reserved"}, + {"INOUT", true, "reserved"}, + {"INSERT", true, "reserved"}, + {"INT", true, "reserved"}, + {"INT1", true, "reserved"}, + {"INT2", true, "reserved"}, + {"INT3", true, "reserved"}, + {"INT4", true, "reserved"}, + {"INT8", true, "reserved"}, + {"INTEGER", true, "reserved"}, + {"INTERSECT", true, "reserved"}, + {"INTERVAL", true, "reserved"}, + {"INTO", true, "reserved"}, + {"IS", true, "reserved"}, + {"ITERATE", true, "reserved"}, + {"JOIN", true, "reserved"}, + {"KEY", true, "reserved"}, + {"KEYS", true, "reserved"}, + {"KILL", true, "reserved"}, + {"LAG", true, "reserved"}, + {"LAST_VALUE", true, "reserved"}, + {"LEAD", true, "reserved"}, + {"LEADING", true, "reserved"}, + {"LEAVE", true, "reserved"}, + {"LEFT", true, "reserved"}, + {"LIKE", true, "reserved"}, + {"LIMIT", true, "reserved"}, + {"LINEAR", true, "reserved"}, + {"LINES", true, "reserved"}, + {"LOAD", true, "reserved"}, + {"LOCALTIME", true, "reserved"}, + {"LOCALTIMESTAMP", true, "reserved"}, + {"LOCK", true, "reserved"}, + {"LONG", true, "reserved"}, + {"LONGBLOB", true, "reserved"}, + {"LONGTEXT", true, "reserved"}, + {"LOW_PRIORITY", true, "reserved"}, + {"MATCH", true, "reserved"}, + {"MAXVALUE", true, "reserved"}, + {"MEDIUMBLOB", true, "reserved"}, + {"MEDIUMINT", true, "reserved"}, + {"MEDIUMTEXT", true, "reserved"}, + {"MIDDLEINT", true, "reserved"}, + {"MINUTE_MICROSECOND", true, "reserved"}, + {"MINUTE_SECOND", true, "reserved"}, + {"MOD", true, "reserved"}, + {"NATURAL", true, "reserved"}, + {"NOT", true, "reserved"}, + {"NO_WRITE_TO_BINLOG", true, "reserved"}, + {"NTH_VALUE", true, "reserved"}, + {"NTILE", true, "reserved"}, + {"NULL", true, "reserved"}, + {"NUMERIC", true, "reserved"}, + {"OF", true, "reserved"}, + {"ON", true, "reserved"}, + {"OPTIMIZE", true, "reserved"}, + {"OPTION", true, "reserved"}, + {"OPTIONALLY", true, "reserved"}, + {"OR", true, "reserved"}, + {"ORDER", true, "reserved"}, + {"OUT", true, "reserved"}, + {"OUTER", true, "reserved"}, + {"OUTFILE", true, "reserved"}, + {"OVER", true, "reserved"}, + {"PARTITION", true, "reserved"}, + {"PERCENT_RANK", true, "reserved"}, + {"PRECISION", true, "reserved"}, + {"PRIMARY", true, "reserved"}, + {"PROCEDURE", true, "reserved"}, + {"RANGE", true, "reserved"}, + {"RANK", true, "reserved"}, + {"READ", true, "reserved"}, + {"REAL", true, "reserved"}, + {"RECURSIVE", true, "reserved"}, + {"REFERENCES", true, "reserved"}, + {"REGEXP", true, "reserved"}, + {"RELEASE", true, "reserved"}, + {"RENAME", true, "reserved"}, + {"REPEAT", true, "reserved"}, + {"REPLACE", true, "reserved"}, + {"REQUIRE", true, "reserved"}, + {"RESTRICT", true, "reserved"}, + {"REVOKE", true, "reserved"}, + {"RIGHT", true, "reserved"}, + {"RLIKE", true, "reserved"}, + {"ROW", true, "reserved"}, + {"ROWS", true, "reserved"}, + {"ROW_NUMBER", true, "reserved"}, + {"SECOND_MICROSECOND", true, "reserved"}, + {"SELECT", true, "reserved"}, + {"SET", true, "reserved"}, + {"SHOW", true, "reserved"}, + {"SMALLINT", true, "reserved"}, + {"SPATIAL", true, "reserved"}, + {"SQL", true, "reserved"}, + {"SQLEXCEPTION", true, "reserved"}, + {"SQLSTATE", true, "reserved"}, + {"SQLWARNING", true, "reserved"}, + {"SQL_BIG_RESULT", true, "reserved"}, + {"SQL_CALC_FOUND_ROWS", true, "reserved"}, + {"SQL_SMALL_RESULT", true, "reserved"}, + {"SSL", true, "reserved"}, + {"STARTING", true, "reserved"}, + {"STATS_EXTENDED", true, "reserved"}, + {"STORED", true, "reserved"}, + {"STRAIGHT_JOIN", true, "reserved"}, + {"TABLE", true, "reserved"}, + {"TABLESAMPLE", true, "reserved"}, + {"TERMINATED", true, "reserved"}, + {"THEN", true, "reserved"}, + {"TINYBLOB", true, "reserved"}, + {"TINYINT", true, "reserved"}, + {"TINYTEXT", true, "reserved"}, + {"TO", true, "reserved"}, + {"TRAILING", true, "reserved"}, + {"TRIGGER", true, "reserved"}, + {"TRUE", true, "reserved"}, + {"TiDB_CURRENT_TSO", true, "reserved"}, + {"UNION", true, "reserved"}, + {"UNIQUE", true, "reserved"}, + {"UNLOCK", true, "reserved"}, + {"UNSIGNED", true, "reserved"}, + {"UNTIL", true, "reserved"}, + {"UPDATE", true, "reserved"}, + {"USAGE", true, "reserved"}, + {"USE", true, "reserved"}, + {"USING", true, "reserved"}, + {"UTC_DATE", true, "reserved"}, + {"UTC_TIME", true, "reserved"}, + {"UTC_TIMESTAMP", true, "reserved"}, + {"VALUES", true, "reserved"}, + {"VARBINARY", true, "reserved"}, + {"VARCHAR", true, "reserved"}, + {"VARCHARACTER", true, "reserved"}, + {"VARYING", true, "reserved"}, + {"VIRTUAL", true, "reserved"}, + {"WHEN", true, "reserved"}, + {"WHERE", true, "reserved"}, + {"WHILE", true, "reserved"}, + {"WINDOW", true, "reserved"}, + {"WITH", true, "reserved"}, + {"WRITE", true, "reserved"}, + {"XOR", true, "reserved"}, + {"YEAR_MONTH", true, "reserved"}, + {"ZEROFILL", true, "reserved"}, + {"ACCOUNT", false, "unreserved"}, + {"ACTION", false, "unreserved"}, + {"ADVISE", false, "unreserved"}, + {"AFTER", false, "unreserved"}, + {"AGAINST", false, "unreserved"}, + {"AGO", false, "unreserved"}, + {"ALGORITHM", false, "unreserved"}, + {"ALWAYS", false, "unreserved"}, + {"ANY", false, "unreserved"}, + {"ASCII", false, "unreserved"}, + {"ATTRIBUTE", false, "unreserved"}, + {"ATTRIBUTES", false, "unreserved"}, + {"AUTO_ID_CACHE", false, "unreserved"}, + {"AUTO_INCREMENT", false, "unreserved"}, + {"AUTO_RANDOM", false, "unreserved"}, + {"AUTO_RANDOM_BASE", false, "unreserved"}, + {"AVG", false, "unreserved"}, + {"AVG_ROW_LENGTH", false, "unreserved"}, + {"BACKEND", false, "unreserved"}, + {"BACKUP", false, "unreserved"}, + {"BACKUPS", false, "unreserved"}, + {"BDR", false, "unreserved"}, + {"BEGIN", false, "unreserved"}, + {"BERNOULLI", false, "unreserved"}, + {"BINDING", false, "unreserved"}, + {"BINDINGS", false, "unreserved"}, + {"BINDING_CACHE", false, "unreserved"}, + {"BINLOG", false, "unreserved"}, + {"BIT", false, "unreserved"}, + {"BLOCK", false, "unreserved"}, + {"BOOL", false, "unreserved"}, + {"BOOLEAN", false, "unreserved"}, + {"BTREE", false, "unreserved"}, + {"BYTE", false, "unreserved"}, + {"CACHE", false, "unreserved"}, + {"CALIBRATE", false, "unreserved"}, + {"CAPTURE", false, "unreserved"}, + {"CASCADED", false, "unreserved"}, + {"CAUSAL", false, "unreserved"}, + {"CHAIN", false, "unreserved"}, + {"CHARSET", false, "unreserved"}, + {"CHECKPOINT", false, "unreserved"}, + {"CHECKSUM", false, "unreserved"}, + {"CIPHER", false, "unreserved"}, + {"CLEANUP", false, "unreserved"}, + {"CLIENT", false, "unreserved"}, + {"CLIENT_ERRORS_SUMMARY", false, "unreserved"}, + {"CLOSE", false, "unreserved"}, + {"CLUSTER", false, "unreserved"}, + {"CLUSTERED", false, "unreserved"}, + {"COALESCE", false, "unreserved"}, + {"COLLATION", false, "unreserved"}, + {"COLUMNS", false, "unreserved"}, + {"COLUMN_FORMAT", false, "unreserved"}, + {"COMMENT", false, "unreserved"}, + {"COMMIT", false, "unreserved"}, + {"COMMITTED", false, "unreserved"}, + {"COMPACT", false, "unreserved"}, + {"COMPRESSED", false, "unreserved"}, + {"COMPRESSION", false, "unreserved"}, + {"CONCURRENCY", false, "unreserved"}, + {"CONFIG", false, "unreserved"}, + {"CONNECTION", false, "unreserved"}, + {"CONSISTENCY", false, "unreserved"}, + {"CONSISTENT", false, "unreserved"}, + {"CONTEXT", false, "unreserved"}, + {"CPU", false, "unreserved"}, + {"CSV_BACKSLASH_ESCAPE", false, "unreserved"}, + {"CSV_DELIMITER", false, "unreserved"}, + {"CSV_HEADER", false, "unreserved"}, + {"CSV_NOT_NULL", false, "unreserved"}, + {"CSV_NULL", false, "unreserved"}, + {"CSV_SEPARATOR", false, "unreserved"}, + {"CSV_TRIM_LAST_SEPARATORS", false, "unreserved"}, + {"CURRENT", false, "unreserved"}, + {"CYCLE", false, "unreserved"}, + {"DATA", false, "unreserved"}, + {"DATE", false, "unreserved"}, + {"DATETIME", false, "unreserved"}, + {"DAY", false, "unreserved"}, + {"DEALLOCATE", false, "unreserved"}, + {"DECLARE", false, "unreserved"}, + {"DEFINER", false, "unreserved"}, + {"DELAY_KEY_WRITE", false, "unreserved"}, + {"DIGEST", false, "unreserved"}, + {"DIRECTORY", false, "unreserved"}, + {"DISABLE", false, "unreserved"}, + {"DISABLED", false, "unreserved"}, + {"DISCARD", false, "unreserved"}, + {"DISK", false, "unreserved"}, + {"DO", false, "unreserved"}, + {"DUPLICATE", false, "unreserved"}, + {"DYNAMIC", false, "unreserved"}, + {"ENABLE", false, "unreserved"}, + {"ENABLED", false, "unreserved"}, + {"ENCRYPTION", false, "unreserved"}, + {"END", false, "unreserved"}, + {"ENFORCED", false, "unreserved"}, + {"ENGINE", false, "unreserved"}, + {"ENGINES", false, "unreserved"}, + {"ENUM", false, "unreserved"}, + {"ERROR", false, "unreserved"}, + {"ERRORS", false, "unreserved"}, + {"ESCAPE", false, "unreserved"}, + {"EVENT", false, "unreserved"}, + {"EVENTS", false, "unreserved"}, + {"EVOLVE", false, "unreserved"}, + {"EXCHANGE", false, "unreserved"}, + {"EXCLUSIVE", false, "unreserved"}, + {"EXECUTE", false, "unreserved"}, + {"EXPANSION", false, "unreserved"}, + {"EXPIRE", false, "unreserved"}, + {"EXTENDED", false, "unreserved"}, + {"FAILED_LOGIN_ATTEMPTS", false, "unreserved"}, + {"FAULTS", false, "unreserved"}, + {"FIELDS", false, "unreserved"}, + {"FILE", false, "unreserved"}, + {"FIRST", false, "unreserved"}, + {"FIXED", false, "unreserved"}, + {"FLUSH", false, "unreserved"}, + {"FOLLOWING", false, "unreserved"}, + {"FORMAT", false, "unreserved"}, + {"FOUND", false, "unreserved"}, + {"FULL", false, "unreserved"}, + {"FUNCTION", false, "unreserved"}, + {"GENERAL", false, "unreserved"}, + {"GLOBAL", false, "unreserved"}, + {"GRANTS", false, "unreserved"}, + {"HANDLER", false, "unreserved"}, + {"HASH", false, "unreserved"}, + {"HELP", false, "unreserved"}, + {"HISTOGRAM", false, "unreserved"}, + {"HISTORY", false, "unreserved"}, + {"HOSTS", false, "unreserved"}, + {"HOUR", false, "unreserved"}, + {"HYPO", false, "unreserved"}, + {"IDENTIFIED", false, "unreserved"}, + {"IMPORT", false, "unreserved"}, + {"IMPORTS", false, "unreserved"}, + {"INCREMENT", false, "unreserved"}, + {"INCREMENTAL", false, "unreserved"}, + {"INDEXES", false, "unreserved"}, + {"INSERT_METHOD", false, "unreserved"}, + {"INSTANCE", false, "unreserved"}, + {"INVISIBLE", false, "unreserved"}, + {"INVOKER", false, "unreserved"}, + {"IO", false, "unreserved"}, + {"IPC", false, "unreserved"}, + {"ISOLATION", false, "unreserved"}, + {"ISSUER", false, "unreserved"}, + {"JSON", false, "unreserved"}, + {"KEY_BLOCK_SIZE", false, "unreserved"}, + {"LABELS", false, "unreserved"}, + {"LANGUAGE", false, "unreserved"}, + {"LAST", false, "unreserved"}, + {"LASTVAL", false, "unreserved"}, + {"LAST_BACKUP", false, "unreserved"}, + {"LESS", false, "unreserved"}, + {"LEVEL", false, "unreserved"}, + {"LIST", false, "unreserved"}, + {"LOCAL", false, "unreserved"}, + {"LOCAL_ONLY", false, "unreserved"}, + {"LOCATION", false, "unreserved"}, + {"LOCKED", false, "unreserved"}, + {"LOGS", false, "unreserved"}, + {"MASTER", false, "unreserved"}, + {"MAX_CONNECTIONS_PER_HOUR", false, "unreserved"}, + {"MAX_IDXNUM", false, "unreserved"}, + {"MAX_MINUTES", false, "unreserved"}, + {"MAX_QUERIES_PER_HOUR", false, "unreserved"}, + {"MAX_ROWS", false, "unreserved"}, + {"MAX_UPDATES_PER_HOUR", false, "unreserved"}, + {"MAX_USER_CONNECTIONS", false, "unreserved"}, + {"MB", false, "unreserved"}, + {"MEMBER", false, "unreserved"}, + {"MEMORY", false, "unreserved"}, + {"MERGE", false, "unreserved"}, + {"MICROSECOND", false, "unreserved"}, + {"MINUTE", false, "unreserved"}, + {"MINVALUE", false, "unreserved"}, + {"MIN_ROWS", false, "unreserved"}, + {"MODE", false, "unreserved"}, + {"MODIFY", false, "unreserved"}, + {"MONTH", false, "unreserved"}, + {"NAMES", false, "unreserved"}, + {"NATIONAL", false, "unreserved"}, + {"NCHAR", false, "unreserved"}, + {"NEVER", false, "unreserved"}, + {"NEXT", false, "unreserved"}, + {"NEXTVAL", false, "unreserved"}, + {"NO", false, "unreserved"}, + {"NOCACHE", false, "unreserved"}, + {"NOCYCLE", false, "unreserved"}, + {"NODEGROUP", false, "unreserved"}, + {"NOMAXVALUE", false, "unreserved"}, + {"NOMINVALUE", false, "unreserved"}, + {"NONCLUSTERED", false, "unreserved"}, + {"NONE", false, "unreserved"}, + {"NOWAIT", false, "unreserved"}, + {"NULLS", false, "unreserved"}, + {"NVARCHAR", false, "unreserved"}, + {"OFF", false, "unreserved"}, + {"OFFSET", false, "unreserved"}, + {"OLTP_READ_ONLY", false, "unreserved"}, + {"OLTP_READ_WRITE", false, "unreserved"}, + {"OLTP_WRITE_ONLY", false, "unreserved"}, + {"ONLINE", false, "unreserved"}, + {"ONLY", false, "unreserved"}, + {"ON_DUPLICATE", false, "unreserved"}, + {"OPEN", false, "unreserved"}, + {"OPTIONAL", false, "unreserved"}, + {"PACK_KEYS", false, "unreserved"}, + {"PAGE", false, "unreserved"}, + {"PARSER", false, "unreserved"}, + {"PARTIAL", false, "unreserved"}, + {"PARTITIONING", false, "unreserved"}, + {"PARTITIONS", false, "unreserved"}, + {"PASSWORD", false, "unreserved"}, + {"PASSWORD_LOCK_TIME", false, "unreserved"}, + {"PAUSE", false, "unreserved"}, + {"PERCENT", false, "unreserved"}, + {"PER_DB", false, "unreserved"}, + {"PER_TABLE", false, "unreserved"}, + {"PLUGINS", false, "unreserved"}, + {"POINT", false, "unreserved"}, + {"POLICY", false, "unreserved"}, + {"PRECEDING", false, "unreserved"}, + {"PREPARE", false, "unreserved"}, + {"PRESERVE", false, "unreserved"}, + {"PRE_SPLIT_REGIONS", false, "unreserved"}, + {"PRIVILEGES", false, "unreserved"}, + {"PROCESS", false, "unreserved"}, + {"PROCESSLIST", false, "unreserved"}, + {"PROFILE", false, "unreserved"}, + {"PROFILES", false, "unreserved"}, + {"PROXY", false, "unreserved"}, + {"PURGE", false, "unreserved"}, + {"QUARTER", false, "unreserved"}, + {"QUERIES", false, "unreserved"}, + {"QUERY", false, "unreserved"}, + {"QUICK", false, "unreserved"}, + {"RATE_LIMIT", false, "unreserved"}, + {"REBUILD", false, "unreserved"}, + {"RECOVER", false, "unreserved"}, + {"REDUNDANT", false, "unreserved"}, + {"RELOAD", false, "unreserved"}, + {"REMOVE", false, "unreserved"}, + {"REORGANIZE", false, "unreserved"}, + {"REPAIR", false, "unreserved"}, + {"REPEATABLE", false, "unreserved"}, + {"REPLICA", false, "unreserved"}, + {"REPLICAS", false, "unreserved"}, + {"REPLICATION", false, "unreserved"}, + {"REQUIRED", false, "unreserved"}, + {"RESOURCE", false, "unreserved"}, + {"RESPECT", false, "unreserved"}, + {"RESTART", false, "unreserved"}, + {"RESTORE", false, "unreserved"}, + {"RESTORES", false, "unreserved"}, + {"RESUME", false, "unreserved"}, + {"REUSE", false, "unreserved"}, + {"REVERSE", false, "unreserved"}, + {"ROLE", false, "unreserved"}, + {"ROLLBACK", false, "unreserved"}, + {"ROLLUP", false, "unreserved"}, + {"ROUTINE", false, "unreserved"}, + {"ROW_COUNT", false, "unreserved"}, + {"ROW_FORMAT", false, "unreserved"}, + {"RTREE", false, "unreserved"}, + {"SAN", false, "unreserved"}, + {"SAVEPOINT", false, "unreserved"}, + {"SECOND", false, "unreserved"}, + {"SECONDARY", false, "unreserved"}, + {"SECONDARY_ENGINE", false, "unreserved"}, + {"SECONDARY_LOAD", false, "unreserved"}, + {"SECONDARY_UNLOAD", false, "unreserved"}, + {"SECURITY", false, "unreserved"}, + {"SEND_CREDENTIALS_TO_TIKV", false, "unreserved"}, + {"SEPARATOR", false, "unreserved"}, + {"SEQUENCE", false, "unreserved"}, + {"SERIAL", false, "unreserved"}, + {"SERIALIZABLE", false, "unreserved"}, + {"SESSION", false, "unreserved"}, + {"SETVAL", false, "unreserved"}, + {"SHARD_ROW_ID_BITS", false, "unreserved"}, + {"SHARE", false, "unreserved"}, + {"SHARED", false, "unreserved"}, + {"SHUTDOWN", false, "unreserved"}, + {"SIGNED", false, "unreserved"}, + {"SIMPLE", false, "unreserved"}, + {"SKIP", false, "unreserved"}, + {"SKIP_SCHEMA_FILES", false, "unreserved"}, + {"SLAVE", false, "unreserved"}, + {"SLOW", false, "unreserved"}, + {"SNAPSHOT", false, "unreserved"}, + {"SOME", false, "unreserved"}, + {"SOURCE", false, "unreserved"}, + {"SQL_BUFFER_RESULT", false, "unreserved"}, + {"SQL_CACHE", false, "unreserved"}, + {"SQL_NO_CACHE", false, "unreserved"}, + {"SQL_TSI_DAY", false, "unreserved"}, + {"SQL_TSI_HOUR", false, "unreserved"}, + {"SQL_TSI_MINUTE", false, "unreserved"}, + {"SQL_TSI_MONTH", false, "unreserved"}, + {"SQL_TSI_QUARTER", false, "unreserved"}, + {"SQL_TSI_SECOND", false, "unreserved"}, + {"SQL_TSI_WEEK", false, "unreserved"}, + {"SQL_TSI_YEAR", false, "unreserved"}, + {"START", false, "unreserved"}, + {"STATS_AUTO_RECALC", false, "unreserved"}, + {"STATS_COL_CHOICE", false, "unreserved"}, + {"STATS_COL_LIST", false, "unreserved"}, + {"STATS_OPTIONS", false, "unreserved"}, + {"STATS_PERSISTENT", false, "unreserved"}, + {"STATS_SAMPLE_PAGES", false, "unreserved"}, + {"STATS_SAMPLE_RATE", false, "unreserved"}, + {"STATUS", false, "unreserved"}, + {"STORAGE", false, "unreserved"}, + {"STRICT_FORMAT", false, "unreserved"}, + {"SUBJECT", false, "unreserved"}, + {"SUBPARTITION", false, "unreserved"}, + {"SUBPARTITIONS", false, "unreserved"}, + {"SUPER", false, "unreserved"}, + {"SWAPS", false, "unreserved"}, + {"SWITCHES", false, "unreserved"}, + {"SYSTEM", false, "unreserved"}, + {"SYSTEM_TIME", false, "unreserved"}, + {"TABLES", false, "unreserved"}, + {"TABLESPACE", false, "unreserved"}, + {"TABLE_CHECKSUM", false, "unreserved"}, + {"TEMPORARY", false, "unreserved"}, + {"TEMPTABLE", false, "unreserved"}, + {"TEXT", false, "unreserved"}, + {"THAN", false, "unreserved"}, + {"TIKV_IMPORTER", false, "unreserved"}, + {"TIME", false, "unreserved"}, + {"TIMESTAMP", false, "unreserved"}, + {"TOKEN_ISSUER", false, "unreserved"}, + {"TPCC", false, "unreserved"}, + {"TPCH_10", false, "unreserved"}, + {"TRACE", false, "unreserved"}, + {"TRADITIONAL", false, "unreserved"}, + {"TRANSACTION", false, "unreserved"}, + {"TRIGGERS", false, "unreserved"}, + {"TRUNCATE", false, "unreserved"}, + {"TSO", false, "unreserved"}, + {"TTL", false, "unreserved"}, + {"TTL_ENABLE", false, "unreserved"}, + {"TTL_JOB_INTERVAL", false, "unreserved"}, + {"TYPE", false, "unreserved"}, + {"UNBOUNDED", false, "unreserved"}, + {"UNCOMMITTED", false, "unreserved"}, + {"UNDEFINED", false, "unreserved"}, + {"UNICODE", false, "unreserved"}, + {"UNKNOWN", false, "unreserved"}, + {"USER", false, "unreserved"}, + {"VALIDATION", false, "unreserved"}, + {"VALUE", false, "unreserved"}, + {"VARIABLES", false, "unreserved"}, + {"VIEW", false, "unreserved"}, + {"VISIBLE", false, "unreserved"}, + {"WAIT", false, "unreserved"}, + {"WARNINGS", false, "unreserved"}, + {"WEEK", false, "unreserved"}, + {"WEIGHT_STRING", false, "unreserved"}, + {"WITHOUT", false, "unreserved"}, + {"WORKLOAD", false, "unreserved"}, + {"X509", false, "unreserved"}, + {"YEAR", false, "unreserved"}, + {"ADMIN", false, "tidb"}, + {"BATCH", false, "tidb"}, + {"BUCKETS", false, "tidb"}, + {"BUILTINS", false, "tidb"}, + {"CANCEL", false, "tidb"}, + {"CARDINALITY", false, "tidb"}, + {"CMSKETCH", false, "tidb"}, + {"COLUMN_STATS_USAGE", false, "tidb"}, + {"CORRELATION", false, "tidb"}, + {"DDL", false, "tidb"}, + {"DEPENDENCY", false, "tidb"}, + {"DEPTH", false, "tidb"}, + {"DRAINER", false, "tidb"}, + {"DRY", false, "tidb"}, + {"HISTOGRAMS_IN_FLIGHT", false, "tidb"}, + {"JOB", false, "tidb"}, + {"JOBS", false, "tidb"}, + {"NODE_ID", false, "tidb"}, + {"NODE_STATE", false, "tidb"}, + {"OPTIMISTIC", false, "tidb"}, + {"PESSIMISTIC", false, "tidb"}, + {"PUMP", false, "tidb"}, + {"REGION", false, "tidb"}, + {"REGIONS", false, "tidb"}, + {"RESET", false, "tidb"}, + {"RUN", false, "tidb"}, + {"SAMPLERATE", false, "tidb"}, + {"SAMPLES", false, "tidb"}, + {"SESSION_STATES", false, "tidb"}, + {"SPLIT", false, "tidb"}, + {"STATISTICS", false, "tidb"}, + {"STATS", false, "tidb"}, + {"STATS_BUCKETS", false, "tidb"}, + {"STATS_HEALTHY", false, "tidb"}, + {"STATS_HISTOGRAMS", false, "tidb"}, + {"STATS_LOCKED", false, "tidb"}, + {"STATS_META", false, "tidb"}, + {"STATS_TOPN", false, "tidb"}, + {"TELEMETRY", false, "tidb"}, + {"TELEMETRY_ID", false, "tidb"}, + {"TIDB", false, "tidb"}, + {"TIFLASH", false, "tidb"}, + {"TOPN", false, "tidb"}, + {"WIDTH", false, "tidb"}, +} diff --git a/pkg/parser/keywords_test.go b/pkg/parser/keywords_test.go new file mode 100644 index 0000000000000..2cfb7be092c00 --- /dev/null +++ b/pkg/parser/keywords_test.go @@ -0,0 +1,57 @@ +// Copyright 2023 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// See the License for the specific language governing permissions and +// limitations under the License. + +package parser_test + +import ( + "testing" + + "github.com/pingcap/tidb/pkg/parser" + "github.com/stretchr/testify/require" +) + +func TestKeywords(t *testing.T) { + // Test for the first keyword + require.Equal(t, "ADD", parser.Keywords[0].Word) + require.Equal(t, true, parser.Keywords[0].Reserved) + + // Make sure TiDBKeywords are included. + found := false + for _, kw := range parser.Keywords { + if kw.Word == "ADMIN" { + found = true + } + } + require.Equal(t, found, true, "TiDBKeyword ADMIN is part of the list") +} + +func TestKeywordsLength(t *testing.T) { + require.Equal(t, 646, len(parser.Keywords)) + + reservedNr := 0 + for _, kw := range parser.Keywords { + if kw.Reserved { + reservedNr += 1 + } + } + require.Equal(t, 233, reservedNr) +} + +func TestKeywordsSorting(t *testing.T) { + for i, kw := range parser.Keywords { + if i > 1 && parser.Keywords[i-1].Word > kw.Word && parser.Keywords[i-1].Section == kw.Section { + t.Errorf("%s should come after %s, please update parser.y and re-generate keywords.go\n", + parser.Keywords[i-1].Word, kw.Word) + } + } +}