2 Star 2 Fork 2

tym_hmm / mysql-mydumper

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
sql.y 71.92 KB
一键复制 编辑 原始数据 按行查看 历史
天蝎儿 提交于 2021-12-16 21:06 . 完成底层封装
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618
/*
Copyright 2017 Google 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,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
%{
package sqlparser
func setParseTree(yylex interface{}, stmt Statement) {
yylex.(*Tokenizer).ParseTree = stmt
}
func setAllowComments(yylex interface{}, allow bool) {
yylex.(*Tokenizer).AllowComments = allow
}
func setDDL(yylex interface{}, ddl *DDL) {
yylex.(*Tokenizer).partialDDL = ddl
}
func incNesting(yylex interface{}) bool {
yylex.(*Tokenizer).nesting++
if yylex.(*Tokenizer).nesting == 200 {
return true
}
return false
}
func decNesting(yylex interface{}) {
yylex.(*Tokenizer).nesting--
}
func forceEOF(yylex interface{}) {
yylex.(*Tokenizer).ForceEOF = true
}
%}
%union {
empty struct{}
statement Statement
selStmt SelectStatement
ddl *DDL
ins *Insert
byt byte
bytes []byte
bytes2 [][]byte
str string
strs []string
selectExprs SelectExprs
selectExpr SelectExpr
columns Columns
colName *ColName
tableExprs TableExprs
tableExpr TableExpr
tableName TableName
tableNames TableNames
indexHints *IndexHints
expr Expr
exprs Exprs
boolVal BoolVal
colTuple ColTuple
values Values
valTuple ValTuple
subquery *Subquery
whens []*When
when *When
orderBy OrderBy
order *Order
limit *Limit
updateExprs UpdateExprs
updateExpr *UpdateExpr
setExprs SetExprs
setExpr *SetExpr
setVal SetVal
colIdent ColIdent
colIdents []ColIdent
tableIdent TableIdent
convertType *ConvertType
aliasedTableName *AliasedTableExpr
tableSpec *TableSpec
tableOptionListOpt TableOptionListOpt
tableOptionList []*TableOption
tableOption *TableOption
columnType ColumnType
colPrimaryKeyOpt ColumnPrimaryKeyOption
colUniqueKeyOpt ColumnUniqueKeyOption
optVal *SQLVal
lengthScaleOption LengthScaleOption
columnDefinition *ColumnDefinition
indexDefinition *IndexDefinition
indexColumn *IndexColumn
indexColumns []*IndexColumn
indexOptionList []*IndexOption
indexOption *IndexOption
columnOptionListOpt ColumnOptionListOpt
columnOptionList []*ColumnOption
columnOption *ColumnOption
databaseOptionListOpt DatabaseOptionListOpt
databaseOptionList []*DatabaseOption
databaseOption *DatabaseOption
partitionDefinition *PartitionDefinition
partitionDefinitions []*PartitionDefinition
showFilter *ShowFilter
}
%token LEX_ERROR
%left <bytes>
UNION
%token <bytes>
SELECT
INSERT
UPDATE
DELETE
FROM
WHERE
GROUP
HAVING
ORDER
BY
LIMIT
OFFSET
FOR
// INDEX.
%token <bytes>
ALGORITHM
BTREE
FULLTEXT
KEY_BLOCK_SIZE
NGRAM
PARSER
SPATIAL
// Resolve shift/reduce conflict on 'UNIQUE KEY', if we don`t define the precedence, the code
// doesn`t know which way to shift. Such as it can be parsed like 'UNIQUE' and 'KEY'(primary key),
// and also can be parsed like just 'UNIQUE KEY'.
// in mysql sql_yacc.cc, they are: %right UNIQUE_SYM KEY_SYM
// see: https://github.com/percona/percona-server/blob/8.0/sql/sql_yacc.yy#L1258
%right <bytes>
UNIQUE
KEY
%token <bytes>
ALL
DISTINCT
AS
EXISTS
ASC
DESC
INTO
DUPLICATE
DEFAULT
SET
LOCK
FULL
CHECKSUM
%token <bytes>
VALUES
LAST_INSERT_ID
%token <bytes>
NEXT
VALUE
SHARE
MODE
%token <bytes>
SQL_NO_CACHE
SQL_CACHE
%left <bytes>
JOIN
STRAIGHT_JOIN
LEFT
RIGHT
INNER
OUTER
CROSS
NATURAL
USE
FORCE
%left <bytes>
ON
%token <empty>
'('
','
')'
%token <bytes>
ID
HEX
STRING
INTEGRAL
FLOAT
HEXNUM
VALUE_ARG
LIST_ARG
COMMENT
COMMENT_KEYWORD
%token <bytes>
NULL
TRUE
FALSE
OFF
// Precedence dictated by mysql. But the vitess grammar is simplified.
// Some of these operators don't conflict in our situation. Nevertheless,
// it's better to have these listed in the correct order. Also, we don't
// support all operators yet.
%left <bytes>
OR
%left <bytes>
AND
%right <bytes>
NOT
'!'
%left <bytes>
BETWEEN
CASE
WHEN
THEN
ELSE
END
%left <bytes>
'='
'<'
'>'
LE
GE
NE
NULL_SAFE_EQUAL
IS
LIKE
REGEXP
IN
%left <bytes>
'|'
%left <bytes>
'&'
%left <bytes>
SHIFT_LEFT
SHIFT_RIGHT
%left <bytes>
'+'
'-'
%left <bytes>
'*'
'/'
DIV
'%'
MOD
%left <bytes>
'^'
%right <bytes>
'~'
UNARY
%left <bytes>
COLLATE
%right <bytes>
BINARY
%right <bytes>
INTERVAL
%nonassoc <bytes>
'.'
// There is no need to define precedence for the JSON
// operators because the syntax is restricted enough that
// they don't cause conflicts.
%token <empty>
JSON_EXTRACT_OP
JSON_UNQUOTE_EXTRACT_OP
// DDL Tokens
%token <bytes>
CREATE
ALTER
DROP
RENAME
ANALYZE
ADD
MODIFY
%token <bytes>
TABLE
INDEX
VIEW
TO
IGNORE
IF
USING
PRIMARY
COLUMN
%token <bytes>
SHOW
DESCRIBE
EXPLAIN
DATE
ESCAPE
REPAIR
OPTIMIZE
TRUNCATE
// Type Tokens
%token <bytes>
BIT
TINYINT
SMALLINT
MEDIUMINT
INT
INTEGER
BIGINT
INTNUM
%token <bytes>
REAL
DOUBLE
FLOAT_TYPE
DECIMAL
NUMERIC
%token <bytes>
TIME
TIMESTAMP
DATETIME
YEAR
%token <bytes>
CHAR
VARCHAR
BOOL
CHARACTER
VARBINARY
NCHAR
CHARSET
%token <bytes>
TEXT
TINYTEXT
MEDIUMTEXT
LONGTEXT
%token <bytes>
BLOB
TINYBLOB
MEDIUMBLOB
LONGBLOB
JSON
ENUM
%token <bytes>
GEOMETRY
POINT
LINESTRING
POLYGON
GEOMETRYCOLLECTION
MULTIPOINT
MULTILINESTRING
MULTIPOLYGON
// Type Modifiers
%token <bytes>
NULLX
AUTO_INCREMENT
APPROXNUM
SIGNED
UNSIGNED
ZEROFILL
FIXED
DYNAMIC
STORAGE
DISK
MEMORY
COLUMN_FORMAT
AVG_ROW_LENGTH
COMPRESSION
CONNECTION
DATA
DIRECTORY
DELAY_KEY_WRITE
ENCRYPTION
INSERT_METHOD
MAX_ROWS
MIN_ROWS
PACK_KEYS
PASSWORD
ROW_FORMAT
STATS_AUTO_RECALC
STATS_PERSISTENT
STATS_SAMPLE_PAGES
TABLESPACE
// ROW_FORMAT options
%token <bytes>
COMPRESSED
REDUNDANT
COMPACT
TOKUDB_DEFAULT
TOKUDB_FAST
TOKUDB_SMALL
TOKUDB_ZLIB
TOKUDB_QUICKLZ
TOKUDB_LZMA
TOKUDB_SNAPPY
TOKUDB_UNCOMPRESSED
// Supported SHOW tokens
%token <bytes>
DATABASES
TABLES
WARNINGS
VARIABLES
EVENTS
BINLOG
GTID
STATUS
COLUMNS
FIELDS
// Functions
%token <bytes>
CURRENT_TIMESTAMP
DATABASE
CURRENT_DATE
%token <bytes>
CURRENT_TIME
LOCALTIME
LOCALTIMESTAMP
%token <bytes>
UTC_DATE
UTC_TIME
UTC_TIMESTAMP
%token <bytes>
REPLACE
%token <bytes>
CONVERT
CAST
%token <bytes>
GROUP_CONCAT
SEPARATOR
// Match
%token <bytes>
MATCH
AGAINST
BOOLEAN
LANGUAGE
WITH
QUERY
EXPANSION
// MySQL reserved words that are unused by this grammar will map to this token.
%token <bytes>
UNUSED
// RadonDB
%token <empty>
PARTITION
PARTITIONS
HASH
LIST
XA
DISTRIBUTED
%type <statement>
truncate_statement
xa_statement
explain_statement
kill_statement
transaction_statement
radon_statement
%token <bytes>
ENGINES
VERSIONS
PROCESSLIST
QUERYZ
TXNZ
KILL
ENGINE
SINGLE
// Transaction Tokens
%token <bytes>
BEGIN
START
TRANSACTION
COMMIT
ROLLBACK
// SET tokens
%token <bytes>
GLOBAL
LOCAL
SESSION
NAMES
ISOLATION
LEVEL
READ
WRITE
ONLY
REPEATABLE
COMMITTED
UNCOMMITTED
SERIALIZABLE
// Radon Tokens
%token <bytes>
RADON
ATTACH
ATTACHLIST
DETACH
RESHARD
CLEANUP
%type <statement>
command
%type <selStmt>
select_statement
base_select
union_lhs
union_rhs
%type <statement>
insert_statement
update_statement
delete_statement
set_statement
%type <statement>
create_statement
alter_statement
drop_statement
%type <ddl>
create_table_prefix
%type <statement>
analyze_statement
show_statement
use_statement
other_statement
checksum_statement
%type <bytes2>
comment_opt
comment_list
%type <str>
union_op
insert_or_replace
now_sym_with_frac_opt
on_update_opt
%type <str>
distinct_opt
straight_join_opt
cache_opt
match_option
separator_opt
binlog_from_opt
%type <expr>
like_escape_opt
%type <selectExprs>
select_expression_list
select_expression_list_opt
%type <selectExpr>
select_expression
%type <expr>
expression
%type <tableExprs>
from_opt
table_references
%type <tableExpr>
table_reference
table_factor
join_table
%type <str>
inner_join
outer_join
natural_join
%type <tableName>
table_name
into_table_name
database_from_opt
%type <str>
full_opt
columns_or_fields
%type <showFilter>
like_or_where_opt
%type <tableNames>
table_name_list
%type <aliasedTableName>
aliased_table_name
%type <indexHints>
index_hint_list
%type <colIdents>
index_list
%type <expr>
where_expression_opt
%type <expr>
condition
%type <boolVal>
boolean_value
%type <str>
compare
%type <ins>
insert_data
%type <expr>
value
value_expression
num_val
%type <expr>
function_call_keyword
function_call_nonkeyword
function_call_generic
function_call_conflict
%type <str>
is_suffix
%type <colTuple>
col_tuple
%type <exprs>
expression_list
%type <values>
tuple_list
%type <valTuple>
row_tuple
tuple_or_empty
%type <expr>
tuple_expression
%type <subquery>
subquery
%type <colName>
column_name
%type <whens>
when_expression_list
%type <when>
when_expression
%type <expr>
expression_opt
else_expression_opt
%type <exprs>
group_by_opt
%type <expr>
having_opt
%type <orderBy>
order_by_opt
order_list
%type <order>
order
%type <str>
asc_desc_opt
%type <limit>
limit_opt
%type <str>
lock_opt
%type <columns>
ins_column_list
%type <updateExprs>
on_dup_opt
%type <updateExprs>
update_list
%type <updateExpr>
update_expression
%type <setExprs>
set_list
txn_list
%type <setExpr>
set_opt_vals
set_expression
%type <setVal>
set_txn_vals
%type <str>
access_mode
access_mode_opt
isolation_level
isolation_level_opt
isolation_types
%type <expr>
charset_value
%type <bytes>
charset_or_character_set
now_sym
%type <bytes>
for_from
%type <str>
ignore_opt
default_opt
%type <byt>
exists_opt
not_exists_opt
%type <empty>
non_rename_operation
to_opt
index_opt
%type <bytes>
reserved_keyword
non_reserved_keyword
%type <colIdent>
sql_id
reserved_sql_id
col_alias
as_ci_opt
col_id
%type <tableIdent>
table_id
reserved_table_id
table_alias
as_opt_id
%type <empty>
as_opt
%type <empty>
force_eof
ddl_force_eof
%type <str>
charset
%type <str>
set_session_or_global
%type <convertType>
convert_type
%type <columnType>
column_type
%type <columnType>
int_type
decimal_type
numeric_type
time_type
char_type
spatial_type
// table options
%type <optVal>
length_opt
column_default_opt
column_comment_opt
col_collate_opt
table_engine_option
parts_num_opt
table_charset_option
table_type_option
table_auto_opt
table_comment_opt
table_avg_row_length_opt
table_checksum_opt
table_collate_opt
table_compression_opt
table_connection_opt
table_data_directory_opt
table_index_directory_opt
table_delay_key_write_opt
table_encryption_opt
table_insert_method_opt
table_key_block_size_opt
table_max_rows_opt
table_min_rows_opt
table_pack_keys_opt
table_password_opt
table_row_format_opt
table_stats_auto_recalc_opt
table_stats_persistent_opt
table_stats_sample_pages_opt
table_tablespace_opt
%type <str>
charset_opt
collate_opt
column_format_opt
storage_opt
%type <optVal>
id_or_string
%type <str>
opt_charset
opt_equal
opt_default
charset_name_or_default
%type <boolVal>
unsigned_opt
zero_fill_opt
%type <lengthScaleOption>
float_length_opt
decimal_length_opt
%type <boolVal>
null_opt
auto_increment_opt
%type <colPrimaryKeyOpt>
column_primary_key_opt
%type <colUniqueKeyOpt>
column_unique_key_opt
%type <strs>
enum_values
%type <columnDefinition>
column_definition
%type <indexDefinition>
index_definition
%type <str>
index_or_key
%type <tableSpec>
table_spec
table_column_list
%type <tableOptionListOpt>
table_option_list_opt
%type <tableOptionList>
table_option_list
%type <tableOption>
table_option
%type <indexColumn>
index_column
%type <indexColumns>
index_column_list
%type <indexOptionList>
fulltext_key_opts
lock_algorithm_opts
normal_key_opts
spatial_key_opts
%type <indexOption>
all_key_opt
fulltext_key_opt
index_using_opt
lock_algorithm_opt
normal_key_opt
%type <str>
constraint_opt
index_using_str
id_or_default
%type <columnOptionListOpt>
column_option_list_opt
%type <columnOptionList>
column_option_list
%type <columnOption>
column_option
%type <databaseOptionListOpt>
database_option_list_opt
%type <databaseOptionList>
database_option_list
%type <databaseOption>
database_option
%type <partitionDefinition>
partition_definition
%type <partitionDefinitions>
partition_definitions
%start any_command
%%
any_command:
command semicolon_opt
{
setParseTree(yylex, $1)
}
semicolon_opt:
/*empty*/
{}
| ';'
{}
command:
select_statement
{
$$ = $1
}
| insert_statement
| update_statement
| delete_statement
| set_statement
| create_statement
| alter_statement
| drop_statement
| truncate_statement
| analyze_statement
| show_statement
| checksum_statement
| use_statement
| xa_statement
| explain_statement
| kill_statement
| transaction_statement
| radon_statement
| other_statement
select_statement:
base_select order_by_opt limit_opt lock_opt
{
sel := $1.(*Select)
sel.OrderBy = $2
sel.Limit = $3
sel.Lock = $4
$$ = sel
}
| union_lhs union_op union_rhs order_by_opt limit_opt lock_opt
{
$$ = &Union{Type: $2, Left: $1, Right: $3, OrderBy: $4, Limit: $5, Lock: $6}
}
| SELECT comment_opt cache_opt NEXT num_val for_from table_name
{
$$ = &Select{Comments: Comments($2), Cache: $3, SelectExprs: SelectExprs{Nextval{Expr: $5}}, From: TableExprs{&AliasedTableExpr{Expr: $7}}}
}
// base_select is an unparenthesized SELECT with no order by clause or beyond.
base_select:
SELECT comment_opt cache_opt distinct_opt straight_join_opt select_expression_list from_opt where_expression_opt group_by_opt having_opt
{
$$ = &Select{Comments: Comments($2), Cache: $3, Distinct: $4, Hints: $5, SelectExprs: $6, From: $7, Where: NewWhere(WhereStr, $8), GroupBy: GroupBy($9), Having: NewWhere(HavingStr, $10)}
}
union_lhs:
select_statement
{
$$ = $1
}
| openb select_statement closeb
{
$$ = &ParenSelect{Select: $2}
}
union_rhs:
base_select
{
$$ = $1
}
| openb select_statement closeb
{
$$ = &ParenSelect{Select: $2}
}
insert_statement:
insert_or_replace comment_opt ignore_opt into_table_name insert_data on_dup_opt
{
// insert_data returns a *Insert pre-filled with Columns & Values
ins := $5
ins.Action = $1
ins.Comments = $2
ins.Ignore = $3
ins.Table = $4
ins.OnDup = OnDup($6)
$$ = ins
}
| insert_or_replace comment_opt ignore_opt into_table_name SET update_list on_dup_opt
{
cols := make(Columns, 0, len($6))
vals := make(ValTuple, 0, len($7))
for _, updateList := range $6 {
cols = append(cols, updateList.Name.Name)
vals = append(vals, updateList.Expr)
}
$$ = &Insert{Action: $1, Comments: Comments($2), Ignore: $3, Table: $4, Columns: cols, Rows: Values{vals}, OnDup: OnDup($7)}
}
insert_or_replace:
INSERT
{
$$ = InsertStr
}
| REPLACE
{
$$ = ReplaceStr
}
update_statement:
UPDATE comment_opt table_name SET update_list where_expression_opt order_by_opt limit_opt
{
$$ = &Update{Comments: Comments($2), Table: $3, Exprs: $5, Where: NewWhere(WhereStr, $6), OrderBy: $7, Limit: $8}
}
delete_statement:
DELETE comment_opt FROM table_name where_expression_opt order_by_opt limit_opt
{
$$ = &Delete{Comments: Comments($2), Table: $4, Where: NewWhere(WhereStr, $5), OrderBy: $6, Limit: $7}
}
set_statement:
SET comment_opt set_list
{
$$ = &Set{Comments: Comments($2), Exprs: $3}
}
| SET comment_opt txn_list
{
$$ = &Set{Comments: Comments($2), Exprs: $3}
}
partition_definitions:
partition_definition
{
$$ = []*PartitionDefinition{$1}
}
| partition_definitions ',' partition_definition
{
$$ = append($1, $3)
}
partition_definition:
PARTITION ID VALUES IN row_tuple
{
$$ = &PartitionDefinition{Backend: string($2), Row: $5}
}
parts_num_opt:
/* empty */
{
$$ = nil
}
| PARTITIONS INTEGRAL
{
if string($2) == "0" {
yylex.Error("Number of partitions must be a positive integer")
return 1
}
$$ = NewIntVal($2)
}
create_statement:
create_table_prefix table_spec
{
$1.Action = CreateTableStr
$1.TableSpec = $2
$$ = $1
}
| create_table_prefix table_spec PARTITION BY HASH openb col_id closeb parts_num_opt ddl_force_eof
{
$1.Action = CreateTableStr
$1.TableSpec = $2
$1.PartitionName = $7.String()
$1.PartitionNum = $9
if $2.Options.Type == GlobalTableType || $2.Options.Type == SingleTableType {
yylex.Error("SINGLE or GLOBAL should not be used simultaneously with PARTITION")
return 1
} else {
$1.TableSpec.Options.Type = PartitionTableHash
}
$$ = $1
}
| create_table_prefix table_spec PARTITION BY LIST openb col_id closeb openb partition_definitions closeb ddl_force_eof
{
$1.Action = CreateTableStr
$1.TableSpec = $2
$1.PartitionName = $7.String()
$1.TableSpec.Options.Type = PartitionTableList
$1.PartitionOptions = $10
$$ = $1
}
| create_table_prefix table_spec DISTRIBUTED BY openb col_id closeb ddl_force_eof
{
$1.Action = CreateTableStr
$1.TableSpec = $2
$1.BackendName = $6.String()
if $2.Options.Type == GlobalTableType || $2.Options.Type == SingleTableType {
yylex.Error("SINGLE or GLOBAL should not be used simultaneously with DISTRIBUTED")
return 1
} else {
$1.TableSpec.Options.Type = SingleTableType
}
$$ = $1
}
| CREATE DATABASE not_exists_opt table_id database_option_list_opt
{
var ifnotexists bool
if $3 != 0 {
ifnotexists = true
}
$$ = &DDL{Action: CreateDBStr, IfNotExists: ifnotexists, Database: $4, DatabaseOptions: $5}
}
| CREATE constraint_opt INDEX ID ON table_name openb index_column_list closeb normal_key_opts lock_algorithm_opts
{
$$ = &DDL{Action: CreateIndexStr, IndexType: $2, IndexName: string($4), Table: $6, NewName: $6, IndexOpts: NewIndexOptions($8, append($10, $11...))}
}
| CREATE FULLTEXT INDEX ID ON table_name openb index_column_list closeb fulltext_key_opts lock_algorithm_opts
{
$$ = &DDL{Action: CreateIndexStr, IndexType: FullTextStr, IndexName: string($4), Table: $6, NewName: $6, IndexOpts: NewIndexOptions($8, append($10, $11...))}
}
| CREATE SPATIAL INDEX ID ON table_name openb index_column_list closeb spatial_key_opts lock_algorithm_opts
{
$$ = &DDL{Action: CreateIndexStr, IndexType: SpatialStr, IndexName: string($4), Table: $6, NewName: $6, IndexOpts: NewIndexOptions($8, append($10, $11...))}
}
index_using_str:
HASH
{
$$ = "hash"
}
| BTREE
{
$$ = "btree"
}
id_or_default:
ID
{
$$ = string($1)
}
| DEFAULT
{
$$ = "default"
}
index_using_opt:
USING index_using_str
{
$$ = &IndexOption{
Type: IndexOptionUsing,
Val: NewStrValWithoutQuote([]byte($2)),
}
}
all_key_opt:
KEY_BLOCK_SIZE opt_equal INTEGRAL
{
$$ = &IndexOption{
Type: IndexOptionBlockSize,
Val: NewIntVal($3),
}
}
| COMMENT_KEYWORD STRING
{
$$ = &IndexOption{
Type: IndexOptionComment,
Val: NewStrVal($2),
}
}
normal_key_opts:
{
$$ = []*IndexOption{}
}
| normal_key_opts normal_key_opt
{
$$ = append($1, $2)
}
normal_key_opt:
all_key_opt
{
$$ = $1
}
| index_using_opt
{
$$ = $1
}
fulltext_key_opts:
{
$$ = []*IndexOption{}
}
| fulltext_key_opts fulltext_key_opt
{
$$ = append($1, $2)
}
fulltext_key_opt:
all_key_opt
{
$$ = $1
}
| WITH PARSER NGRAM
{
$$ = &IndexOption{
Type: IndexOptionParser,
Val: NewStrValWithoutQuote($3),
}
}
spatial_key_opts:
{
$$ = []*IndexOption{}
}
| spatial_key_opts all_key_opt
{
$$ = append($1, $2)
}
lock_algorithm_opts:
{
$$ = []*IndexOption{}
}
| lock_algorithm_opts lock_algorithm_opt
{
$$ = append($1, $2)
}
lock_algorithm_opt:
LOCK opt_equal id_or_default
{
if !CheckIndexLock($3) {
yylex.Error("unknown lock type")
return 1
}
$$ = &IndexOption{
Type: IndexOptionLock,
Val: NewStrValWithoutQuote([]byte($3)),
}
}
| ALGORITHM opt_equal id_or_default
{
if !CheckIndexAlgorithm($3) {
yylex.Error("unknown algorithm type")
return 1
}
$$ = &IndexOption{
Type: IndexOptionAlgorithm,
Val: NewStrValWithoutQuote([]byte($3)),
}
}
database_option_list_opt:
{
$$.DBOptList = []*DatabaseOption{}
}
| database_option_list
{
$$.DBOptList = $1
}
database_option_list:
database_option
{
$$ = append($$, $1)
}
| database_option_list database_option
{
$$ = append($1, $2)
}
database_option:
opt_default COLLATE opt_equal id_or_default
{
$$ = &DatabaseOption{
CharsetOrCollate: string($2),
Value: $4,
}
}
| opt_default opt_charset opt_equal charset_name_or_default
{
$$ = &DatabaseOption{
CharsetOrCollate: string($2),
Value: $4,
}
}
opt_default:
{}
| DEFAULT
{}
opt_equal:
{}
| '='
{}
opt_charset:
CHARSET
{
$$ = string($1)
}
| CHARACTER SET
{
$$ = "character set"
}
charset_name_or_default:
ID
{
$$ = string($1)
}
| BINARY
{
$$ = string($1)
}
| DEFAULT
{
$$ = "default"
}
create_table_prefix:
CREATE TABLE not_exists_opt table_name
{
var ifnotexists bool
if $3 != 0 {
ifnotexists = true
}
$$ = &DDL{Action: CreateTableStr, IfNotExists: ifnotexists, Table: $4, NewName: $4}
setDDL(yylex, $$)
}
table_spec:
'(' table_column_list ')' table_option_list_opt
{
$$ = $2
if len($4.TblOptList) != 0 {
if str := $4.CheckIfTableOptDuplicate(); str != "" {
yylex.Error(str)
return 1
}
if val := $4.GetTableOptValByType(TableOptionComment); val != nil {
$$.Options.Comment = String(val)
}
if val := $4.GetTableOptValByType(TableOptionEngine); val != nil {
$$.Options.Engine = String(val)
}
if val := $4.GetTableOptValByType(TableOptionCharset); val != nil {
$$.Options.Charset = String(val)
}
if val := $4.GetTableOptValByType(TableOptionTableType); val != nil {
$$.Options.Type = String(val)
}
if val := $4.GetTableOptValByType(TableOptionAvgRowLength); val != nil {
$$.Options.AvgRowLength = String(val)
}
if val := $4.GetTableOptValByType(TableOptionChecksum); val != nil {
$$.Options.Checksum = String(val)
}
if val := $4.GetTableOptValByType(TableOptionCollate); val != nil {
$$.Options.Collate = String(val)
}
if val := $4.GetTableOptValByType(TableOptionCompression); val != nil {
$$.Options.Compression = String(val)
}
if val := $4.GetTableOptValByType(TableOptionConnection); val != nil {
$$.Options.Connection = String(val)
}
if val := $4.GetTableOptValByType(TableOptionDataDirectory); val != nil {
$$.Options.DataDirectory = String(val)
}
if val := $4.GetTableOptValByType(TableOptionIndexDirectory); val != nil {
$$.Options.IndexDirectory = String(val)
}
if val := $4.GetTableOptValByType(TableOptionDelayKeyWrite); val != nil {
$$.Options.DelayKeyWrite = String(val)
}
if val := $4.GetTableOptValByType(TableOptionEncryption); val != nil {
$$.Options.Encryption = String(val)
}
if val := $4.GetTableOptValByType(TableOptionInsertMethod); val != nil {
$$.Options.InsertMethod = String(val)
}
if val := $4.GetTableOptValByType(TableOptionKeyBlockSize); val != nil {
$$.Options.KeyBlockSize= String(val)
}
if val := $4.GetTableOptValByType(TableOptionMaxRows); val != nil {
$$.Options.MaxRows= String(val)
}
if val := $4.GetTableOptValByType(TableOptionMinRows); val != nil {
$$.Options.MinRows = String(val)
}
if val := $4.GetTableOptValByType(TableOptionPackKeys); val != nil {
$$.Options.PackKeys = String(val)
}
if val := $4.GetTableOptValByType(TableOptionPassword); val != nil {
$$.Options.Password = String(val)
}
if val := $4.GetTableOptValByType(TableOptionRowFormat); val != nil {
$$.Options.RowFormat = String(val)
}
if val := $4.GetTableOptValByType(TableOptionStatsAutoRecalc); val != nil {
$$.Options.StatsAutoRecalc = String(val)
}
if val := $4.GetTableOptValByType(TableOptionStatsPersistent); val != nil {
$$.Options.StatsPersistent = String(val)
}
if val := $4.GetTableOptValByType(TableOptionStatsSamplePages); val != nil {
$$.Options.StatsSamplePages = String(val)
}
if val := $4.GetTableOptValByType(TableOptionTableSpace); val != nil {
$$.Options.TableSpace = String(val)
}
}
if $$.Options.Type == "" {
$$.Options.Type = NormalTableType
}
}
table_option_list_opt:
{
$$.TblOptList = []*TableOption{}
}
| table_option_list
{
$$.TblOptList = $1
}
table_option_list:
table_option
{
$$ = append($$, $1)
}
| table_option_list table_option
{
$$ = append($1, $2)
}
table_option:
table_comment_opt
{
$$ = &TableOption{
Type: TableOptionComment,
Val: $1,
}
}
| table_engine_option
{
$$ = &TableOption{
Type: TableOptionEngine,
Val: $1,
}
}
| table_charset_option
{
$$ = &TableOption{
Type: TableOptionCharset,
Val: $1,
}
}
| table_type_option
{
$$ = &TableOption{
Type: TableOptionTableType,
Val: $1,
}
}
| table_auto_opt
{
$$ = &TableOption{
Type: TableOptionAutoInc,
Val: $1,
}
}
| table_avg_row_length_opt
{
$$ = &TableOption{
Type: TableOptionAvgRowLength,
Val: $1,
}
}
| table_checksum_opt
{
$$ = &TableOption{
Type: TableOptionChecksum,
Val: $1,
}
}
| table_collate_opt
{
$$ = &TableOption{
Type: TableOptionCollate,
Val: $1,
}
}
| table_compression_opt
{
$$ = &TableOption{
Type: TableOptionCompression,
Val: $1,
}
}
| table_connection_opt
{
$$ = &TableOption{
Type: TableOptionConnection,
Val: $1,
}
}
| table_data_directory_opt
{
$$ = &TableOption{
Type: TableOptionDataDirectory,
Val: $1,
}
}
| table_index_directory_opt
{
$$ = &TableOption{
Type: TableOptionIndexDirectory,
Val: $1,
}
}
| table_delay_key_write_opt
{
$$ = &TableOption{
Type: TableOptionDelayKeyWrite,
Val: $1,
}
}
| table_encryption_opt
{
$$ = &TableOption{
Type: TableOptionEncryption,
Val: $1,
}
}
| table_insert_method_opt
{
$$ = &TableOption{
Type: TableOptionInsertMethod,
Val: $1,
}
}
| table_key_block_size_opt
{
$$ = &TableOption{
Type: TableOptionKeyBlockSize,
Val: $1,
}
}
| table_max_rows_opt
{
$$ = &TableOption{
Type: TableOptionMaxRows,
Val: $1,
}
}
| table_min_rows_opt
{
$$ = &TableOption{
Type: TableOptionMinRows,
Val: $1,
}
}
| table_pack_keys_opt
{
$$ = &TableOption{
Type: TableOptionPackKeys,
Val: $1,
}
}
| table_password_opt
{
$$ = &TableOption{
Type: TableOptionPassword,
Val: $1,
}
}
| table_row_format_opt
{
$$ = &TableOption{
Type: TableOptionRowFormat,
Val: $1,
}
}
| table_stats_auto_recalc_opt
{
$$ = &TableOption{
Type: TableOptionStatsAutoRecalc,
Val: $1,
}
}
| table_stats_persistent_opt
{
$$ = &TableOption{
Type: TableOptionStatsPersistent,
Val: $1,
}
}
| table_stats_sample_pages_opt
{
$$ = &TableOption{
Type: TableOptionStatsSamplePages,
Val: $1,
}
}
| table_tablespace_opt
{
$$ = &TableOption{
Type: TableOptionTableSpace,
Val: $1,
}
}
table_auto_opt:
AUTO_INCREMENT opt_equal INTEGRAL
{}
table_avg_row_length_opt:
AVG_ROW_LENGTH opt_equal INTEGRAL
{
$$ = NewIntVal($3)
}
table_collate_opt:
opt_default COLLATE opt_equal id_or_string
{
$$ = $4
}
table_compression_opt:
COMPRESSION opt_equal STRING
{
switch StrToLower(string($3)) {
case "zlib", "lz4", "none":
break
default:
yylex.Error("Invalid compression option, argument (should be 'ZLIB', 'LZ4' or 'NONE')")
return 1
}
$$ = NewStrVal($3)
}
table_connection_opt:
CONNECTION opt_equal STRING
{
$$ = NewStrVal($3)
}
table_data_directory_opt:
DATA DIRECTORY opt_equal STRING
{
$$ = NewStrVal($4)
}
table_index_directory_opt:
INDEX DIRECTORY opt_equal STRING
{
$$ = NewStrVal($4)
}
table_delay_key_write_opt:
DELAY_KEY_WRITE opt_equal INTEGRAL
{
$$ = NewIntVal($3)
}
table_encryption_opt:
ENCRYPTION opt_equal STRING
{
switch string($3) {
case "Y", "y":
yylex.Error("The encryption option is parsed but ignored by all storage engines.")
return 1
case "N", "n":
break
default:
yylex.Error("Invalid encryption option, argument (should be Y or N)")
return 1
}
$$ = NewStrVal($3)
}
table_insert_method_opt:
INSERT_METHOD opt_equal ID
{
switch StrToLower(string($3)) {
case "no", "first", "last":
break
default:
yylex.Error("Invalid insert_method option, argument (should be NO, FIRST or LAST)")
return 1
}
$$ = NewStrValWithoutQuote($3)
}
table_key_block_size_opt:
KEY_BLOCK_SIZE opt_equal INTEGRAL
{
$$ = NewIntVal($3)
}
table_max_rows_opt:
MAX_ROWS opt_equal INTEGRAL
{
$$ = NewIntVal($3)
}
table_min_rows_opt:
MIN_ROWS opt_equal INTEGRAL
{
$$ = NewIntVal($3)
}
table_pack_keys_opt:
PACK_KEYS opt_equal INTEGRAL
{
$$ = NewStrValWithoutQuote($3)
}
| PACK_KEYS opt_equal DEFAULT
{
$$ = NewStrValWithoutQuote($3)
}
table_password_opt:
PASSWORD opt_equal STRING
{
$$ = NewStrVal($3)
}
// In the newest version of 5.7, formats with tokudb are abandoned, but we reserve them in RadonDB.
// see: https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L6211
table_row_format_opt:
ROW_FORMAT opt_equal DEFAULT
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal DYNAMIC
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal FIXED
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal COMPRESSED
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal REDUNDANT
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal COMPACT
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_DEFAULT
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_FAST
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_SMALL
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_ZLIB
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_QUICKLZ
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_LZMA
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_SNAPPY
{
$$ = NewStrValWithoutQuote($3)
}
| ROW_FORMAT opt_equal TOKUDB_UNCOMPRESSED
{
$$ = NewStrValWithoutQuote($3)
}
table_stats_auto_recalc_opt:
STATS_AUTO_RECALC opt_equal INTEGRAL
{
$$ = NewStrValWithoutQuote($3)
}
| STATS_AUTO_RECALC opt_equal DEFAULT
{
$$ = NewStrValWithoutQuote($3)
}
table_stats_persistent_opt:
STATS_PERSISTENT opt_equal INTEGRAL
{
$$ = NewStrValWithoutQuote($3)
}
| STATS_PERSISTENT opt_equal DEFAULT
{
$$ = NewStrValWithoutQuote($3)
}
// In MySQL, STATS_SAMPLE_PAGES=N(Where 0<N<=65535) or STAS_SAMPLE_PAGES=DEFAULT.
table_stats_sample_pages_opt:
STATS_SAMPLE_PAGES opt_equal INTEGRAL
{
$$ = NewStrValWithoutQuote($3)
}
| STATS_SAMPLE_PAGES opt_equal DEFAULT
{
$$ = NewStrValWithoutQuote($3)
}
table_tablespace_opt:
TABLESPACE opt_equal ID
{
$$ = NewStrValWithoutQuote($3)
}
| TABLESPACE opt_equal non_reserved_keyword
{
$$ = NewStrValWithoutQuote($3)
}
table_checksum_opt:
CHECKSUM opt_equal INTEGRAL
{
$$ = NewIntVal($3)
}
id_or_string:
ID
{
// Normal str as an identify, without quote
$$ = NewStrValWithoutQuote($1)
}
| STRING
{
// Str with Quote, it will be parsed by Lex begin with quote \' or \"
$$ = NewStrVal($1)
}
table_comment_opt:
COMMENT_KEYWORD opt_equal STRING
{
$$ = NewStrVal($3)
}
table_engine_option:
ENGINE opt_equal id_or_string
{
$$ = $3
}
table_charset_option:
opt_default opt_charset opt_equal id_or_string
{
$$ = $4
}
table_type_option:
GLOBAL
{
$$ = NewStrValWithoutQuote([]byte(GlobalTableType))
}
| SINGLE
{
$$ = NewStrValWithoutQuote([]byte(SingleTableType))
}
table_column_list:
column_definition
{
$$ = &TableSpec{}
$$.AddColumn($1)
}
| table_column_list ',' column_definition
{
$$.AddColumn($3)
}
| table_column_list ',' index_definition
{
$$.AddIndex($3)
}
column_definition:
col_id column_type column_option_list_opt
{
$2.NotNull = $3.GetColumnOption(ColumnOptionNotNull).NotNull
$2.Autoincrement = $3.GetColumnOption(ColumnOptionAutoincrement).Autoincrement
$2.Default = $3.GetColumnOption(ColumnOptionDefault).Default
$2.Comment = $3.GetColumnOption(ColumnOptionComment).Comment
$2.OnUpdate = $3.GetColumnOption(ColumnOptionOnUpdate).OnUpdate
$2.PrimaryKeyOpt = $3.GetColumnOption(ColumnOptionKeyPrimaryOpt).PrimaryKeyOpt
$2.UniqueKeyOpt = $3.GetColumnOption(ColumnOptionKeyUniqueOpt).UniqueKeyOpt
$2.Collate = $3.GetColumnOption(ColumnOptionCollate).Collate
$2.ColumnFormat = $3.GetColumnOption(ColumnOptionFormat).ColumnFormat
$2.Storage = $3.GetColumnOption(ColumnOptionStorage).Storage
$$ = &ColumnDefinition{Name: $1, Type: $2}
}
col_id:
ID
{
$$ = NewColIdent(string($1))
}
| non_reserved_keyword
{
$$ = NewColIdent(string($1))
}
column_type:
numeric_type unsigned_opt zero_fill_opt
{
$$ = $1
$$.Unsigned = $2
$$.Zerofill = $3
}
| char_type
| time_type
| spatial_type
column_option_list_opt:
{
$$.ColOptList = []*ColumnOption{}
}
| column_option_list
{
$$.ColOptList = $1
}
column_option_list:
column_option
{
$$ = append($$, $1)
}
| column_option_list column_option
{
$$ = append($1, $2)
}
column_option:
null_opt
{
$$ = &ColumnOption{
typ: ColumnOptionNotNull,
NotNull: $1,
}
}
| column_default_opt
{
$$ = &ColumnOption{
typ: ColumnOptionDefault,
Default: $1,
}
}
| auto_increment_opt
{
$$ = &ColumnOption{
typ: ColumnOptionAutoincrement,
Autoincrement: $1,
}
}
| column_primary_key_opt
{
$$ = &ColumnOption{
typ: ColumnOptionKeyPrimaryOpt,
PrimaryKeyOpt: $1,
}
}
| column_unique_key_opt
{
$$ = &ColumnOption{
typ: ColumnOptionKeyUniqueOpt,
UniqueKeyOpt: $1,
}
}
| column_comment_opt
{
$$ = &ColumnOption{
typ: ColumnOptionComment,
Comment: $1,
}
}
| on_update_opt
{
$$ = &ColumnOption{
typ: ColumnOptionOnUpdate,
OnUpdate: $1,
}
}
| col_collate_opt
{
$$ = &ColumnOption{
typ: ColumnOptionCollate,
Collate: $1,
}
}
| column_format_opt
{
$$ = &ColumnOption{
typ: ColumnOptionFormat,
ColumnFormat: $1,
}
}
| storage_opt
{
$$ = &ColumnOption{
typ: ColumnOptionStorage,
Storage: $1,
}
}
numeric_type:
int_type length_opt
{
$$ = $1
$$.Length = $2
}
| decimal_type
{
$$ = $1
}
int_type:
BIT
{
$$ = ColumnType{Type: string($1)}
}
| BOOL
{
$$ = ColumnType{Type: string($1)}
}
| BOOLEAN
{
$$ = ColumnType{Type: string($1)}
}
| TINYINT
{
$$ = ColumnType{Type: string($1)}
}
| SMALLINT
{
$$ = ColumnType{Type: string($1)}
}
| MEDIUMINT
{
$$ = ColumnType{Type: string($1)}
}
| INT
{
$$ = ColumnType{Type: string($1)}
}
| INTEGER
{
$$ = ColumnType{Type: string($1)}
}
| BIGINT
{
$$ = ColumnType{Type: string($1)}
}
decimal_type:
REAL float_length_opt
{
$$ = ColumnType{Type: string($1)}
$$.Length = $2.Length
$$.Scale = $2.Scale
}
| DOUBLE float_length_opt
{
$$ = ColumnType{Type: string($1)}
$$.Length = $2.Length
$$.Scale = $2.Scale
}
| FLOAT_TYPE float_length_opt
{
$$ = ColumnType{Type: string($1)}
$$.Length = $2.Length
$$.Scale = $2.Scale
}
| DECIMAL decimal_length_opt
{
$$ = ColumnType{Type: string($1)}
$$.Length = $2.Length
$$.Scale = $2.Scale
}
| NUMERIC decimal_length_opt
{
$$ = ColumnType{Type: string($1)}
$$.Length = $2.Length
$$.Scale = $2.Scale
}
time_type:
DATE
{
$$ = ColumnType{Type: string($1)}
}
| TIME length_opt
{
$$ = ColumnType{Type: string($1), Length: $2}
}
| TIMESTAMP length_opt
{
$$ = ColumnType{Type: string($1), Length: $2}
}
| DATETIME length_opt
{
$$ = ColumnType{Type: string($1), Length: $2}
}
| YEAR
{
$$ = ColumnType{Type: string($1)}
}
char_type:
CHAR length_opt charset_opt
{
$$ = ColumnType{Type: string($1), Length: $2, Charset: $3}
}
| VARCHAR length_opt charset_opt
{
$$ = ColumnType{Type: string($1), Length: $2, Charset: $3}
}
| BINARY length_opt
{
$$ = ColumnType{Type: string($1), Length: $2}
}
| VARBINARY length_opt
{
$$ = ColumnType{Type: string($1), Length: $2}
}
| TEXT charset_opt
{
$$ = ColumnType{Type: string($1), Charset: $2}
}
| TINYTEXT charset_opt
{
$$ = ColumnType{Type: string($1), Charset: $2}
}
| MEDIUMTEXT charset_opt
{
$$ = ColumnType{Type: string($1), Charset: $2}
}
| LONGTEXT charset_opt
{
$$ = ColumnType{Type: string($1), Charset: $2}
}
| BLOB
{
$$ = ColumnType{Type: string($1)}
}
| TINYBLOB
{
$$ = ColumnType{Type: string($1)}
}
| MEDIUMBLOB
{
$$ = ColumnType{Type: string($1)}
}
| LONGBLOB
{
$$ = ColumnType{Type: string($1)}
}
| JSON
{
$$ = ColumnType{Type: string($1)}
}
| ENUM '(' enum_values ')'
{
$$ = ColumnType{Type: string($1), EnumValues: $3}
}
spatial_type:
GEOMETRY
{
$$ = ColumnType{Type: string($1)}
}
| POINT
{
$$ = ColumnType{Type: string($1)}
}
| LINESTRING
{
$$ = ColumnType{Type: string($1)}
}
| POLYGON
{
$$ = ColumnType{Type: string($1)}
}
| GEOMETRYCOLLECTION
{
$$ = ColumnType{Type: string($1)}
}
| MULTIPOINT
{
$$ = ColumnType{Type: string($1)}
}
| MULTILINESTRING
{
$$ = ColumnType{Type: string($1)}
}
| MULTIPOLYGON
{
$$ = ColumnType{Type: string($1)}
}
enum_values:
STRING
{
$$ = make([]string, 0, 4)
$$ = append($$, "'"+string($1)+"'")
}
| enum_values ',' STRING
{
$$ = append($1, "'"+string($3)+"'")
}
length_opt:
{
$$ = nil
}
| '(' INTEGRAL ')'
{
$$ = NewIntVal($2)
}
float_length_opt:
{
$$ = LengthScaleOption{}
}
| '(' INTEGRAL ',' INTEGRAL ')'
{
$$ = LengthScaleOption{
Length: NewIntVal($2),
Scale: NewIntVal($4),
}
}
decimal_length_opt:
{
$$ = LengthScaleOption{}
}
| '(' INTEGRAL ')'
{
$$ = LengthScaleOption{
Length: NewIntVal($2),
}
}
| '(' INTEGRAL ',' INTEGRAL ')'
{
$$ = LengthScaleOption{
Length: NewIntVal($2),
Scale: NewIntVal($4),
}
}
unsigned_opt:
{
$$ = BoolVal(false)
}
| UNSIGNED
{
$$ = BoolVal(true)
}
zero_fill_opt:
{
$$ = BoolVal(false)
}
| ZEROFILL
{
$$ = BoolVal(true)
}
// Null opt returns false to mean NULL (i.e. the default) and true for NOT NULL
null_opt:
NULL
{
$$ = BoolVal(false)
}
| NOT NULL
{
$$ = BoolVal(true)
}
column_default_opt:
DEFAULT STRING
{
$$ = NewStrVal($2)
}
| DEFAULT INTEGRAL
{
$$ = NewIntVal($2)
}
| DEFAULT FLOAT
{
$$ = NewFloatVal($2)
}
| DEFAULT NULL
{
$$ = NewValArg($2)
}
| DEFAULT CURRENT_TIMESTAMP
{
$$ = NewValArg($2)
}
on_update_opt:
ON UPDATE now_sym_with_frac_opt
{
$$ = $3
}
now_sym_with_frac_opt:
now_sym
{
$$ = string($1)
}
| now_sym '(' ')'
{
$$ = string($1)+"("+")"
}
| now_sym '(' INTEGRAL ')'
{
$$ = string($1)+"("+string($3)+")"
}
// See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_localtime
// TODO: Process other three keywords, see function_call_nonkeyword, and we'll abandon function_call_nonkeyword in the future.
now_sym:
CURRENT_TIMESTAMP
{
$$ = $1
}
| LOCALTIME
{
$$ = $1
}
| LOCALTIMESTAMP
{
$$ = $1
}
auto_increment_opt:
AUTO_INCREMENT
{
$$ = BoolVal(true)
}
charset_opt:
{
$$ = ""
}
| CHARACTER SET ID
{
$$ = string($3)
}
| CHARACTER SET BINARY
{
$$ = string($3)
}
// TODO in the futrue we'll combine col_collate_opt and collate_opt into one.
col_collate_opt:
COLLATE id_or_string
{
$$ = $2
}
collate_opt:
{
$$ = ""
}
| COLLATE ID
{
$$ = string($2)
}
column_format_opt:
COLUMN_FORMAT FIXED
{
$$ = string($2)
}
| COLUMN_FORMAT DYNAMIC
{
$$ = string($2)
}
| COLUMN_FORMAT DEFAULT
{
$$ = string($2)
}
storage_opt:
STORAGE DEFAULT
{
// "default" is not in official doc: https://dev.mysql.com/doc/refman/5.7/en/create-table.html
// but actually mysql support it, see: https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L6953
$$ = string($2)
}
| STORAGE DISK
{
$$ = string($2)
}
| STORAGE MEMORY
{
$$ = string($2)
}
column_primary_key_opt:
PRIMARY KEY
{
$$ = ColKeyPrimary
}
| KEY
{
// KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY
// can also be specified as just KEY when given in a column definition.
// See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
$$ = ColKeyPrimary
}
column_unique_key_opt:
UNIQUE KEY
{
$$ = ColKeyUniqueKey
}
| UNIQUE
{
$$ = ColKeyUniqueKey
}
column_comment_opt:
COMMENT_KEYWORD STRING
{
$$ = NewStrVal($2)
}
index_definition:
PRIMARY KEY '(' index_column_list ')'
{
$$ = &IndexDefinition {
Type: string($1) + " " + string($2),
Name: NewColIdent("PRIMARY"),
Opts: NewIndexOptions($4, nil),
Primary: true,
Unique: true,
}
}
| UNIQUE index_or_key ID '(' index_column_list ')' normal_key_opts
{
$$ = &IndexDefinition {
Type: string($1) + " " + string($2),
Name: NewColIdent(string($3)),
Opts: NewIndexOptions($5, $7),
Primary: false,
Unique: true,
}
}
| UNIQUE ID '(' index_column_list ')' normal_key_opts
{
$$ = &IndexDefinition {
Type: string($1),
Name: NewColIdent(string($2)),
Opts: NewIndexOptions($4, $6),
Primary: false,
Unique: true,
}
}
| index_or_key ID '(' index_column_list ')' normal_key_opts
{
$$ = &IndexDefinition {
Type: string($1),
Name: NewColIdent(string($2)),
Opts: NewIndexOptions($4, $6),
Primary: false,
Unique: false,
}
}
| FULLTEXT index_or_key ID '(' index_column_list ')' fulltext_key_opts
{
$$ = &IndexDefinition {
Type: string($1) + " " + string($2),
Name: NewColIdent(string($3)),
Opts: NewIndexOptions($5, $7),
Primary: false,
Unique: false,
}
}
| SPATIAL index_or_key ID '(' index_column_list ')' spatial_key_opts
{
$$ = &IndexDefinition {
Type: string($1) + " " + string($2),
Name: NewColIdent(string($3)),
Opts: NewIndexOptions($5, $7),
Primary: false,
Unique: false,
}
}
index_or_key:
INDEX
{
$$ = string($1)
}
| KEY
{
$$ = string($1)
}
index_column_list:
index_column
{
$$ = []*IndexColumn{$1}
}
| index_column_list ',' index_column
{
$$ = append($$, $3)
}
index_column:
sql_id length_opt
{
$$ = &IndexColumn{Column: $1, Length: $2}
}
alter_statement:
ALTER ignore_opt TABLE table_name non_rename_operation force_eof
{
$$ = &DDL{Action: AlterStr, Table: $4, NewName: $4}
}
| ALTER ignore_opt TABLE table_name RENAME to_opt table_name
{
// Change this to a rename statement
$$ = &DDL{Action: RenameStr, Table: $4, NewName: $7}
}
| ALTER ignore_opt TABLE table_name RENAME index_opt force_eof
{
// Rename an index can just be an alter
$$ = &DDL{Action: AlterStr, Table: $4, NewName: $4}
}
| ALTER ignore_opt TABLE table_name ENGINE '=' ID
{
$$ = &DDL{Action: AlterEngineStr, Table: $4, NewName: $4, Engine: string($7)}
}
| ALTER ignore_opt TABLE table_name CONVERT TO CHARACTER SET ID
{
$$ = &DDL{Action: AlterCharsetStr, Table: $4, NewName: $4, Charset: string($9)}
}
| ALTER ignore_opt TABLE table_name ADD COLUMN table_spec
{
$$ = &DDL{Action: AlterAddColumnStr, Table: $4, NewName: $4, TableSpec: $7}
}
| ALTER ignore_opt TABLE table_name DROP COLUMN ID
{
$$ = &DDL{Action: AlterDropColumnStr, Table: $4, NewName: $4, DropColumnName: string($7)}
}
| ALTER ignore_opt TABLE table_name MODIFY COLUMN column_definition
{
$$ = &DDL{Action: AlterModifyColumnStr, Table: $4, NewName: $4, ModifyColumnDef: $7}
}
drop_statement:
DROP TABLE exists_opt table_name_list
{
var exists bool
if $3 != 0 {
exists = true
}
$$ = &DDL{Action: DropTableStr, Tables: $4, IfExists: exists}
}
| DROP INDEX ID ON table_name
{
// Change this to an alter statement
$$ = &DDL{Action: DropIndexStr, IndexName: string($3), Table: $5, NewName: $5}
}
| DROP DATABASE exists_opt table_id
{
var exists bool
if $3 != 0 {
exists = true
}
$$ = &DDL{Action: DropDBStr, Database: $4, IfExists: exists}
}
table_name_list:
table_name
{
$$ = TableNames{$1}
}
| table_name_list ',' table_name
{
$$ = append($$, $3)
}
truncate_statement:
TRUNCATE TABLE table_name
{
$$ = &DDL{Action: TruncateTableStr, Table: $3, NewName: $3}
}
analyze_statement:
ANALYZE TABLE table_name
{
$$ = &DDL{Action: AlterStr, Table: $3, NewName: $3}
}
xa_statement:
XA force_eof
{
$$ = &Xa{}
}
explain_statement:
EXPLAIN force_eof
{
$$ = &Explain{}
}
kill_statement:
KILL INTEGRAL force_eof
{
$$ = &Kill{QueryID: &NumVal{raw: string($2)}}
}
| KILL QUERY INTEGRAL force_eof
{
$$ = &Kill{QueryID: &NumVal{raw: string($3)}}
}
transaction_statement:
BEGIN force_eof
{
$$ = &Transaction{Action: BeginTxnStr}
}
| START TRANSACTION force_eof
{
$$ = &Transaction{Action: StartTxnStr}
}
| ROLLBACK force_eof
{
$$ = &Transaction{Action: RollbackTxnStr}
}
| COMMIT force_eof
{
$$ = &Transaction{Action: CommitTxnStr}
}
radon_statement:
RADON ATTACH row_tuple force_eof
{
$$ = &Radon{Action: AttachStr, Row: $3}
}
| RADON DETACH row_tuple force_eof
{
$$ = &Radon{Action: DetachStr, Row: $3}
}
| RADON ATTACHLIST force_eof
{
$$ = &Radon{Action: AttachListStr}
}
| RADON RESHARD table_name to_opt table_name force_eof
{
$$ = &Radon{Action: ReshardStr, Table: $3, NewName: $5}
}
| RADON CLEANUP force_eof
{
$$ = &Radon{Action: CleanupStr}
}
show_statement:
SHOW BINLOG EVENTS binlog_from_opt limit_opt force_eof
{
$$ = &Show{Type: ShowBinlogEventsStr, From: $4, Limit: $5}
}
| SHOW CREATE TABLE table_name force_eof
{
$$ = &Show{Type: ShowCreateTableStr, Table: $4}
}
| SHOW CREATE DATABASE table_name force_eof
{
$$ = &Show{Type: ShowCreateDatabaseStr, Database: $4}
}
| SHOW DATABASES force_eof
{
$$ = &Show{Type: ShowDatabasesStr}
}
| SHOW ENGINES force_eof
{
$$ = &Show{Type: ShowEnginesStr}
}
| SHOW full_opt TABLES database_from_opt like_or_where_opt
{
$$ = &Show{Full: $2, Type: ShowTablesStr, Database: $4, Filter: $5}
}
| SHOW full_opt columns_or_fields FROM table_name like_or_where_opt
{
$$ = &Show{Full: $2, Type: ShowColumnsStr, Table: $5, Filter: $6}
}
| SHOW PROCESSLIST force_eof
{
$$ = &Show{Type: ShowProcesslistStr}
}
| SHOW QUERYZ force_eof
{
$$ = &Show{Type: ShowQueryzStr}
}
| SHOW STATUS force_eof
{
$$ = &Show{Type: ShowStatusStr}
}
| SHOW TABLE STATUS database_from_opt force_eof
{
$$ = &Show{Type: ShowTableStatusStr, Database: $4}
}
| SHOW TXNZ force_eof
{
$$ = &Show{Type: ShowTxnzStr}
}
| SHOW VARIABLES force_eof
{
$$ = &Show{Type: ShowVariablesStr}
}
| SHOW VERSIONS force_eof
{
$$ = &Show{Type: ShowVersionsStr}
}
| SHOW WARNINGS force_eof
{
$$ = &Show{Type: ShowWarningsStr}
}
| SHOW ID force_eof
{
$$ = &Show{Type: ShowUnsupportedStr}
}
binlog_from_opt:
{
$$ = ""
}
| FROM GTID STRING
{
$$ = string($3)
}
database_from_opt:
{
$$ = TableName{}
}
| FROM table_name
{
$$ = $2
}
full_opt:
/* empty */
{
$$ = ""
}
| FULL
{
$$ = "full "
}
columns_or_fields:
COLUMNS
{
$$ = string($1)
}
| FIELDS
{
$$ = string($1)
}
like_or_where_opt:
/* empty */
{
$$ = nil
}
| LIKE STRING
{
$$ = &ShowFilter{Like: string($2)}
}
| WHERE expression
{
$$ = &ShowFilter{Filter: $2}
}
checksum_statement:
CHECKSUM TABLE table_name force_eof
{
$$ = &Checksum{Table: $3}
}
use_statement:
USE table_id
{
$$ = &Use{DBName: $2}
}
other_statement:
DESC force_eof
{
$$ = &OtherRead{}
}
| DESCRIBE force_eof
{
$$ = &OtherRead{}
}
| REPAIR force_eof
{
$$ = &OtherAdmin{}
}
| OPTIMIZE force_eof
{
$$ = &OtherAdmin{}
}
comment_opt:
{
setAllowComments(yylex, true)
} comment_list
{
$$ = $2
setAllowComments(yylex, false)
}
comment_list:
{
$$ = nil
}
| comment_list COMMENT
{
$$ = append($1, $2)
}
union_op:
UNION
{
$$ = UnionStr
}
| UNION ALL
{
$$ = UnionAllStr
}
| UNION DISTINCT
{
$$ = UnionDistinctStr
}
cache_opt:
{
$$ = ""
}
| SQL_NO_CACHE
{
$$ = SQLNoCacheStr
}
| SQL_CACHE
{
$$ = SQLCacheStr
}
distinct_opt:
{
$$ = ""
}
| DISTINCT
{
$$ = DistinctStr
}
straight_join_opt:
{
$$ = ""
}
| STRAIGHT_JOIN
{
$$ = StraightJoinHint
}
select_expression_list_opt:
{
$$ = nil
}
| select_expression_list
{
$$ = $1
}
select_expression_list:
select_expression
{
$$ = SelectExprs{$1}
}
| select_expression_list ',' select_expression
{
$$ = append($$, $3)
}
select_expression:
'*'
{
$$ = &StarExpr{}
}
| expression as_ci_opt
{
$$ = &AliasedExpr{Expr: $1, As: $2}
}
| table_id '.' '*'
{
$$ = &StarExpr{TableName: TableName{Name: $1}}
}
| table_id '.' reserved_table_id '.' '*'
{
$$ = &StarExpr{TableName: TableName{Qualifier: $1, Name: $3}}
}
as_ci_opt:
{
$$ = ColIdent{}
}
| col_alias
{
$$ = $1
}
| AS col_alias
{
$$ = $2
}
col_alias:
sql_id
| STRING
{
$$ = NewColIdent(string($1))
}
from_opt:
{
$$ = TableExprs{&AliasedTableExpr{Expr: TableName{Name: NewTableIdent("dual")}}}
}
| FROM table_references
{
$$ = $2
}
table_references:
table_reference
{
$$ = TableExprs{$1}
}
| table_references ',' table_reference
{
$$ = append($$, $3)
}
table_reference:
table_factor
| join_table
table_factor:
aliased_table_name
{
$$ = $1
}
| subquery as_opt table_id
{
$$ = &AliasedTableExpr{Expr: $1, As: $3}
}
| openb table_references closeb
{
$$ = &ParenTableExpr{Exprs: $2}
}
aliased_table_name:
table_name as_opt_id index_hint_list
{
$$ = &AliasedTableExpr{Expr: $1, As: $2, Hints: $3}
}
// There is a grammar conflict here:
// 1: INSERT INTO a SELECT * FROM b JOIN c ON b.i = c.i
// 2: INSERT INTO a SELECT * FROM b JOIN c ON DUPLICATE KEY UPDATE a.i = 1
// When yacc encounters the ON clause, it cannot determine which way to
// resolve. The %prec override below makes the parser choose the
// first construct, which automatically makes the second construct a
// syntax error. This is the same behavior as MySQL.
join_table:
table_reference inner_join table_factor %prec JOIN
{
$$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3}
}
| table_reference inner_join table_factor ON expression
{
$$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, On: $5}
}
| table_reference outer_join table_reference ON expression
{
$$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3, On: $5}
}
| table_reference natural_join table_factor
{
$$ = &JoinTableExpr{LeftExpr: $1, Join: $2, RightExpr: $3}
}
as_opt:
{
$$ = struct{}{}
}
| AS
{
$$ = struct{}{}
}
as_opt_id:
{
$$ = NewTableIdent("")
}
| table_alias
{
$$ = $1
}
| AS table_alias
{
$$ = $2
}
table_alias:
table_id
| STRING
{
$$ = NewTableIdent(string($1))
}
inner_join:
JOIN
{
$$ = JoinStr
}
| INNER JOIN
{
$$ = JoinStr
}
| CROSS JOIN
{
$$ = JoinStr
}
| STRAIGHT_JOIN
{
$$ = StraightJoinStr
}
outer_join:
LEFT JOIN
{
$$ = LeftJoinStr
}
| LEFT OUTER JOIN
{
$$ = LeftJoinStr
}
| RIGHT JOIN
{
$$ = RightJoinStr
}
| RIGHT OUTER JOIN
{
$$ = RightJoinStr
}
natural_join:
NATURAL JOIN
{
$$ = NaturalJoinStr
}
| NATURAL outer_join
{
if $2 == LeftJoinStr {
$$ = NaturalLeftJoinStr
} else {
$$ = NaturalRightJoinStr
}
}
into_table_name:
INTO table_name
{
$$ = $2
}
| table_name
{
$$ = $1
}
table_name:
table_id
{
$$ = TableName{Name: $1}
}
| table_id '.' reserved_table_id
{
$$ = TableName{Qualifier: $1, Name: $3}
}
index_hint_list:
{
$$ = nil
}
| USE INDEX openb index_list closeb
{
$$ = &IndexHints{Type: UseStr, Indexes: $4}
}
| IGNORE INDEX openb index_list closeb
{
$$ = &IndexHints{Type: IgnoreStr, Indexes: $4}
}
| FORCE INDEX openb index_list closeb
{
$$ = &IndexHints{Type: ForceStr, Indexes: $4}
}
index_list:
sql_id
{
$$ = []ColIdent{$1}
}
| index_list ',' sql_id
{
$$ = append($1, $3)
}
where_expression_opt:
{
$$ = nil
}
| WHERE expression
{
$$ = $2
}
expression:
condition
{
$$ = $1
}
| expression AND expression
{
$$ = &AndExpr{Left: $1, Right: $3}
}
| expression OR expression
{
$$ = &OrExpr{Left: $1, Right: $3}
}
| NOT expression
{
$$ = &NotExpr{Expr: $2}
}
| expression IS is_suffix
{
$$ = &IsExpr{Operator: $3, Expr: $1}
}
| value_expression
{
$$ = $1
}
| DEFAULT default_opt
{
$$ = &Default{ColName: $2}
}
default_opt:
/* empty */
{
$$ = ""
}
| openb ID closeb
{
$$ = string($2)
}
boolean_value:
TRUE
{
$$ = BoolVal(true)
}
| FALSE
{
$$ = BoolVal(false)
}
condition:
value_expression compare value_expression
{
$$ = &ComparisonExpr{Left: $1, Operator: $2, Right: $3}
}
| value_expression IN col_tuple
{
$$ = &ComparisonExpr{Left: $1, Operator: InStr, Right: $3}
}
| value_expression NOT IN col_tuple
{
$$ = &ComparisonExpr{Left: $1, Operator: NotInStr, Right: $4}
}
| value_expression LIKE value_expression like_escape_opt
{
$$ = &ComparisonExpr{Left: $1, Operator: LikeStr, Right: $3, Escape: $4}
}
| value_expression NOT LIKE value_expression like_escape_opt
{
$$ = &ComparisonExpr{Left: $1, Operator: NotLikeStr, Right: $4, Escape: $5}
}
| value_expression REGEXP value_expression
{
$$ = &ComparisonExpr{Left: $1, Operator: RegexpStr, Right: $3}
}
| value_expression NOT REGEXP value_expression
{
$$ = &ComparisonExpr{Left: $1, Operator: NotRegexpStr, Right: $4}
}
| value_expression BETWEEN value_expression AND value_expression
{
$$ = &RangeCond{Left: $1, Operator: BetweenStr, From: $3, To: $5}
}
| value_expression NOT BETWEEN value_expression AND value_expression
{
$$ = &RangeCond{Left: $1, Operator: NotBetweenStr, From: $4, To: $6}
}
| EXISTS subquery
{
$$ = &ExistsExpr{Subquery: $2}
}
is_suffix:
NULL
{
$$ = IsNullStr
}
| NOT NULL
{
$$ = IsNotNullStr
}
| TRUE
{
$$ = IsTrueStr
}
| NOT TRUE
{
$$ = IsNotTrueStr
}
| FALSE
{
$$ = IsFalseStr
}
| NOT FALSE
{
$$ = IsNotFalseStr
}
compare:
'='
{
$$ = EqualStr
}
| '<'
{
$$ = LessThanStr
}
| '>'
{
$$ = GreaterThanStr
}
| LE
{
$$ = LessEqualStr
}
| GE
{
$$ = GreaterEqualStr
}
| NE
{
$$ = NotEqualStr
}
| NULL_SAFE_EQUAL
{
$$ = NullSafeEqualStr
}
like_escape_opt:
{
$$ = nil
}
| ESCAPE value_expression
{
$$ = $2
}
col_tuple:
row_tuple
{
$$ = $1
}
| subquery
{
$$ = $1
}
| LIST_ARG
{
$$ = ListArg($1)
}
subquery:
openb select_statement closeb
{
$$ = &Subquery{$2}
}
expression_list:
expression
{
$$ = Exprs{$1}
}
| expression_list ',' expression
{
$$ = append($1, $3)
}
value_expression:
value
{
$$ = $1
}
| boolean_value
{
$$ = $1
}
| column_name
{
$$ = $1
}
| tuple_expression
{
$$ = $1
}
| subquery
{
$$ = $1
}
| value_expression '&' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: BitAndStr, Right: $3}
}
| value_expression '|' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: BitOrStr, Right: $3}
}
| value_expression '^' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: BitXorStr, Right: $3}
}
| value_expression '+' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: PlusStr, Right: $3}
}
| value_expression '-' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: MinusStr, Right: $3}
}
| value_expression '*' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: MultStr, Right: $3}
}
| value_expression '/' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: DivStr, Right: $3}
}
| value_expression DIV value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: IntDivStr, Right: $3}
}
| value_expression '%' value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: ModStr, Right: $3}
}
| value_expression MOD value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: ModStr, Right: $3}
}
| value_expression SHIFT_LEFT value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: ShiftLeftStr, Right: $3}
}
| value_expression SHIFT_RIGHT value_expression
{
$$ = &BinaryExpr{Left: $1, Operator: ShiftRightStr, Right: $3}
}
| column_name JSON_EXTRACT_OP value
{
$$ = &BinaryExpr{Left: $1, Operator: JSONExtractOp, Right: $3}
}
| column_name JSON_UNQUOTE_EXTRACT_OP value
{
$$ = &BinaryExpr{Left: $1, Operator: JSONUnquoteExtractOp, Right: $3}
}
| value_expression COLLATE charset
{
$$ = &CollateExpr{Expr: $1, Charset: $3}
}
| BINARY value_expression %prec UNARY
{
$$ = &UnaryExpr{Operator: BinaryStr, Expr: $2}
}
| '+' value_expression %prec UNARY
{
if num, ok := $2.(*SQLVal); ok && num.Type == IntVal {
$$ = num
} else {
$$ = &UnaryExpr{Operator: UPlusStr, Expr: $2}
}
}
| '-' value_expression %prec UNARY
{
if num, ok := $2.(*SQLVal); ok && num.Type == IntVal {
// Handle double negative
if num.Val[0] == '-' {
num.Val = num.Val[1:]
$$ = num
} else {
$$ = NewIntVal(append([]byte("-"), num.Val...))
}
} else {
$$ = &UnaryExpr{Operator: UMinusStr, Expr: $2}
}
}
| '~' value_expression
{
$$ = &UnaryExpr{Operator: TildaStr, Expr: $2}
}
| '!' value_expression %prec UNARY
{
$$ = &UnaryExpr{Operator: BangStr, Expr: $2}
}
| INTERVAL value_expression sql_id
{
// This rule prevents the usage of INTERVAL
// as a function. If support is needed for that,
// we'll need to revisit this. The solution
// will be non-trivial because of grammar conflicts.
$$ = &IntervalExpr{Expr: $2, Unit: $3.String()}
}
| function_call_generic
| function_call_keyword
| function_call_nonkeyword
| function_call_conflict
/*
Regular function calls without special token or syntax, guaranteed to not
introduce side effects due to being a simple identifier
*/
function_call_generic:
sql_id openb select_expression_list_opt closeb
{
$$ = &FuncExpr{Name: $1, Exprs: $3}
}
| sql_id openb DISTINCT select_expression_list closeb
{
$$ = &FuncExpr{Name: $1, Distinct: true, Exprs: $4}
}
| table_id '.' reserved_sql_id openb select_expression_list_opt closeb
{
$$ = &FuncExpr{Qualifier: $1, Name: $3, Exprs: $5}
}
/*
Function calls using reserved keywords, with dedicated grammar rules
as a result
*/
function_call_keyword:
LEFT openb select_expression_list closeb
{
$$ = &FuncExpr{Name: NewColIdent("left"), Exprs: $3}
}
| RIGHT openb select_expression_list closeb
{
$$ = &FuncExpr{Name: NewColIdent("right"), Exprs: $3}
}
| CONVERT openb expression ',' convert_type closeb
{
$$ = &ConvertExpr{Expr: $3, Type: $5}
}
| CAST openb expression AS convert_type closeb
{
$$ = &ConvertExpr{Expr: $3, Type: $5}
}
| CONVERT openb expression USING charset closeb
{
$$ = &ConvertUsingExpr{Expr: $3, Type: $5}
}
| MATCH openb select_expression_list closeb AGAINST openb value_expression match_option closeb
{
$$ = &MatchExpr{Columns: $3, Expr: $7, Option: $8}
}
| GROUP_CONCAT openb distinct_opt select_expression_list order_by_opt separator_opt closeb
{
$$ = &GroupConcatExpr{Distinct: $3, Exprs: $4, OrderBy: $5, Separator: $6}
}
| CASE expression_opt when_expression_list else_expression_opt END
{
$$ = &CaseExpr{Expr: $2, Whens: $3, Else: $4}
}
| VALUES openb sql_id closeb
{
$$ = &ValuesFuncExpr{Name: $3}
}
/*
Function calls using non reserved keywords but with special syntax forms.
Dedicated grammar rules are needed because of the special syntax
*/
function_call_nonkeyword:
CURRENT_TIMESTAMP func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("current_timestamp")}
}
| UTC_TIMESTAMP func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("utc_timestamp")}
}
| UTC_TIME func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("utc_time")}
}
| UTC_DATE func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("utc_date")}
}
// now
| LOCALTIME func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("localtime")}
}
// now
| LOCALTIMESTAMP func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("localtimestamp")}
}
// curdate
| CURRENT_DATE func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("current_date")}
}
// curtime
| CURRENT_TIME func_datetime_precision_opt
{
$$ = &FuncExpr{Name: NewColIdent("current_time")}
}
func_datetime_precision_opt:
/* empty */
| openb closeb
/*
Function calls using non reserved keywords with *normal* syntax forms. Because
the names are non-reserved, they need a dedicated rule so as not to conflict
*/
function_call_conflict:
IF openb select_expression_list closeb
{
$$ = &FuncExpr{Name: NewColIdent("if"), Exprs: $3}
}
| DATABASE openb select_expression_list_opt closeb
{
$$ = &FuncExpr{Name: NewColIdent("database"), Exprs: $3}
}
| MOD openb select_expression_list closeb
{
$$ = &FuncExpr{Name: NewColIdent("mod"), Exprs: $3}
}
| REPLACE openb select_expression_list closeb
{
$$ = &FuncExpr{Name: NewColIdent("replace"), Exprs: $3}
}
match_option:
/*empty*/
{
$$ = ""
}
| IN BOOLEAN MODE
{
$$ = BooleanModeStr
}
| IN NATURAL LANGUAGE MODE
{
$$ = NaturalLanguageModeStr
}
| IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION
{
$$ = NaturalLanguageModeWithQueryExpansionStr
}
| WITH QUERY EXPANSION
{
$$ = QueryExpansionStr
}
charset:
ID
{
$$ = string($1)
}
| STRING
{
$$ = string($1)
}
convert_type:
BINARY length_opt
{
$$ = &ConvertType{Type: string($1), Length: $2}
}
| CHAR length_opt charset_opt
{
$$ = &ConvertType{Type: string($1), Length: $2, Charset: $3, Operator: CharacterSetStr}
}
| CHAR length_opt ID
{
$$ = &ConvertType{Type: string($1), Length: $2, Charset: string($3)}
}
| DATE
{
$$ = &ConvertType{Type: string($1)}
}
| DATETIME length_opt
{
$$ = &ConvertType{Type: string($1), Length: $2}
}
| DECIMAL decimal_length_opt
{
$$ = &ConvertType{Type: string($1)}
$$.Length = $2.Length
$$.Scale = $2.Scale
}
| JSON
{
$$ = &ConvertType{Type: string($1)}
}
| NCHAR length_opt
{
$$ = &ConvertType{Type: string($1), Length: $2}
}
| SIGNED
{
$$ = &ConvertType{Type: string($1)}
}
| SIGNED INTEGER
{
$$ = &ConvertType{Type: string($1)}
}
| TIME length_opt
{
$$ = &ConvertType{Type: string($1), Length: $2}
}
| UNSIGNED
{
$$ = &ConvertType{Type: string($1)}
}
| UNSIGNED INTEGER
{
$$ = &ConvertType{Type: string($1)}
}
expression_opt:
{
$$ = nil
}
| expression
{
$$ = $1
}
separator_opt:
{
$$ = string("")
}
| SEPARATOR STRING
{
$$ = " separator '" + string($2) + "'"
}
when_expression_list:
when_expression
{
$$ = []*When{$1}
}
| when_expression_list when_expression
{
$$ = append($1, $2)
}
when_expression:
WHEN expression THEN expression
{
$$ = &When{Cond: $2, Val: $4}
}
else_expression_opt:
{
$$ = nil
}
| ELSE expression
{
$$ = $2
}
column_name:
sql_id
{
$$ = &ColName{Name: $1}
}
| table_id '.' reserved_sql_id
{
$$ = &ColName{Qualifier: TableName{Name: $1}, Name: $3}
}
| table_id '.' reserved_table_id '.' reserved_sql_id
{
$$ = &ColName{Qualifier: TableName{Qualifier: $1, Name: $3}, Name: $5}
}
value:
STRING
{
$$ = NewStrVal($1)
}
| HEX
{
$$ = NewHexVal($1)
}
| INTEGRAL
{
$$ = NewIntVal($1)
}
| FLOAT
{
$$ = NewFloatVal($1)
}
| HEXNUM
{
$$ = NewHexNum($1)
}
| VALUE_ARG
{
$$ = NewValArg($1)
}
| NULL
{
$$ = &NullVal{}
}
num_val:
sql_id
{
// TODO(sougou): Deprecate this construct.
if $1.Lowered() != "value" {
yylex.Error("expecting value after next")
return 1
}
$$ = NewIntVal([]byte("1"))
}
| INTEGRAL VALUES
{
$$ = NewIntVal($1)
}
| VALUE_ARG VALUES
{
$$ = NewValArg($1)
}
group_by_opt:
{
$$ = nil
}
| GROUP BY expression_list
{
$$ = $3
}
having_opt:
{
$$ = nil
}
| HAVING expression
{
$$ = $2
}
order_by_opt:
{
$$ = nil
}
| ORDER BY order_list
{
$$ = $3
}
order_list:
order
{
$$ = OrderBy{$1}
}
| order_list ',' order
{
$$ = append($1, $3)
}
order:
expression asc_desc_opt
{
$$ = &Order{Expr: $1, Direction: $2}
}
asc_desc_opt:
{
$$ = AscScr
}
| ASC
{
$$ = AscScr
}
| DESC
{
$$ = DescScr
}
limit_opt:
{
$$ = nil
}
| LIMIT expression
{
$$ = &Limit{Rowcount: $2}
}
| LIMIT expression ',' expression
{
$$ = &Limit{Offset: $2, Rowcount: $4}
}
| LIMIT expression OFFSET expression
{
$$ = &Limit{Offset: $4, Rowcount: $2}
}
lock_opt:
{
$$ = ""
}
| FOR UPDATE
{
$$ = ForUpdateStr
}
| LOCK IN SHARE MODE
{
$$ = ShareModeStr
}
// insert_data expands all combinations into a single rule.
// This avoids a shift/reduce conflict while encountering the
// following two possible constructs:
// insert into t1(a, b) (select * from t2)
// insert into t1(select * from t2)
// Because the rules are together, the parser can keep shifting
// the tokens until it disambiguates a as sql_id and select as keyword.
insert_data:
VALUES tuple_list
{
$$ = &Insert{Rows: $2}
}
| select_statement
{
$$ = &Insert{Rows: $1}
}
| openb select_statement closeb
{
// Drop the redundant parenthesis.
$$ = &Insert{Rows: $2}
}
| openb ins_column_list closeb VALUES tuple_list
{
$$ = &Insert{Columns: $2, Rows: $5}
}
| openb ins_column_list closeb select_statement
{
$$ = &Insert{Columns: $2, Rows: $4}
}
| openb ins_column_list closeb openb select_statement closeb
{
// Drop the redundant parenthesis.
$$ = &Insert{Columns: $2, Rows: $5}
}
ins_column_list:
sql_id
{
$$ = Columns{$1}
}
| sql_id '.' sql_id
{
$$ = Columns{$3}
}
| ins_column_list ',' sql_id
{
$$ = append($$, $3)
}
| ins_column_list ',' sql_id '.' sql_id
{
$$ = append($$, $5)
}
on_dup_opt:
{
$$ = nil
}
| ON DUPLICATE KEY UPDATE update_list
{
$$ = $5
}
tuple_list:
tuple_or_empty
{
$$ = Values{$1}
}
| tuple_list ',' tuple_or_empty
{
$$ = append($1, $3)
}
tuple_or_empty:
row_tuple
{
$$ = $1
}
| openb closeb
{
$$ = ValTuple{}
}
row_tuple:
openb expression_list closeb
{
$$ = ValTuple($2)
}
tuple_expression:
row_tuple
{
if len($1) == 1 {
$$ = &ParenExpr{$1[0]}
} else {
$$ = $1
}
}
update_list:
update_expression
{
$$ = UpdateExprs{$1}
}
| update_list ',' update_expression
{
$$ = append($1, $3)
}
update_expression:
column_name '=' expression
{
$$ = &UpdateExpr{Name: $1, Expr: $3}
}
set_list:
set_expression
{
$$ = SetExprs{$1}
}
| set_list ',' set_expression
{
$$ = append($1, $3)
}
set_expression:
set_opt_vals
{
$$ = $1
}
| set_session_or_global set_opt_vals
{
$2.Scope = $1
$$ = $2
}
set_opt_vals:
reserved_sql_id '=' ON
{
$$ = &SetExpr{Type: $1, Val: &OptVal{Value: NewStrVal([]byte("on"))}}
}
| reserved_sql_id '=' OFF
{
$$ = &SetExpr{Type: $1, Val: &OptVal{Value: NewStrVal([]byte("off"))}}
}
| reserved_sql_id '=' expression
{
$$ = &SetExpr{Type: $1, Val: &OptVal{Value: $3}}
}
| charset_or_character_set charset_value
{
$$ = &SetExpr{Type: NewColIdent(string($1)), Val: &OptVal{Value: $2}}
}
| NAMES charset_value collate_opt
{
$$ = &SetExpr{Type: NewColIdent(string($1)), Val: &OptVal{Value: &CollateExpr{Expr: $2, Charset: $3}}}
}
charset_or_character_set:
CHARSET
| CHARACTER SET
{
$$ = []byte("charset")
}
charset_value:
sql_id
{
$$ = NewStrVal([]byte($1.String()))
}
| STRING
{
$$ = NewStrVal($1)
}
| DEFAULT
{
$$ = &Default{}
}
txn_list:
TRANSACTION set_txn_vals
{
$$ = SetExprs{&SetExpr{Type: NewColIdent(string($1)), Val: $2}}
}
| set_session_or_global TRANSACTION set_txn_vals
{
$$ = SetExprs{&SetExpr{Scope: $1, Type: NewColIdent(string($2)), Val: $3}}
}
set_txn_vals:
isolation_level access_mode_opt
{
$$ = &TxnVal{Level: $1, Mode: $2}
}
| access_mode isolation_level_opt
{
$$ = &TxnVal{Level: $2, Mode: $1}
}
isolation_level_opt:
/* empty */
{
$$ = ""
}
| ',' isolation_level
{
$$ = $2
}
isolation_level:
ISOLATION LEVEL isolation_types
{
$$ = $3
}
isolation_types:
REPEATABLE READ
{
$$ = RepeatableRead
}
| READ COMMITTED
{
$$ = ReadCommitted
}
| READ UNCOMMITTED
{
$$ = ReadUncommitted
}
| SERIALIZABLE
{
$$ = Serializable
}
access_mode_opt:
/* empty */
{
$$ = ""
}
| ',' access_mode
{
$$ = $2
}
access_mode:
READ WRITE
{
$$ = TxReadWrite
}
| READ ONLY
{
$$ = TxReadOnly
}
set_session_or_global:
LOCAL
{
$$ = SessionStr
}
| SESSION
{
$$ = SessionStr
}
| GLOBAL
{
$$ = GlobalStr
}
for_from:
FOR
| FROM
exists_opt:
{
$$ = 0
}
| IF EXISTS
{
$$ = 1
}
not_exists_opt:
{
$$ = 0
}
| IF NOT EXISTS
{
$$ = 1
}
ignore_opt:
{
$$ = ""
}
| IGNORE
{
$$ = IgnoreStr
}
non_rename_operation:
ALTER
{
$$ = struct{}{}
}
| AUTO_INCREMENT
{
$$ = struct{}{}
}
| CHARACTER
{
$$ = struct{}{}
}
| COMMENT_KEYWORD
{
$$ = struct{}{}
}
| DEFAULT
{
$$ = struct{}{}
}
| DROP
{
$$ = struct{}{}
}
| ORDER
{
$$ = struct{}{}
}
| CONVERT
{
$$ = struct{}{}
}
| UNUSED
{
$$ = struct{}{}
}
| ID
{
$$ = struct{}{}
}
to_opt:
{
$$ = struct{}{}
}
| TO
{
$$ = struct{}{}
}
| AS
{
$$ = struct{}{}
}
index_opt:
INDEX
{
$$ = struct{}{}
}
| KEY
{
$$ = struct{}{}
}
constraint_opt:
{
$$ = IndexStr
}
| UNIQUE
{
$$ = UniqueStr
}
sql_id:
ID
{
$$ = NewColIdent(string($1))
}
| non_reserved_keyword
{
$$ = NewColIdent(string($1))
}
reserved_sql_id:
sql_id
| reserved_keyword
{
$$ = NewColIdent(string($1))
}
table_id:
ID
{
$$ = NewTableIdent(string($1))
}
| non_reserved_keyword
{
$$ = NewTableIdent(string($1))
}
reserved_table_id:
table_id
| reserved_keyword
{
$$ = NewTableIdent(string($1))
}
/*
These are not all necessarily reserved in MySQL, but some are.
These are more importantly reserved because they may conflict with our grammar.
If you want to move one that is not reserved in MySQL (i.e. ESCAPE) to the
non_reserved_keywords, you'll need to deal with any conflicts.
Sorted alphabetically
*/
reserved_keyword:
AND
| AS
| ASC
| AUTO_INCREMENT
| BETWEEN
| BIGINT
| BINARY
| BLOB
| BY
| CASE
| CHAR
| CHARACTER
| CHARSET
| COLLATE
| COLUMNS
| COMPRESSION
| CONVERT
| CREATE
| CROSS
| CURRENT_DATE
| CURRENT_TIME
| CURRENT_TIMESTAMP
| DATABASE
| DATABASES
| DECIMAL
| DEFAULT
| DELETE
| DESC
| DESCRIBE
| DISTINCT
| DIV
| DROP
| ELSE
| END
| ENGINES
| ESCAPE
| EXISTS
| EXPLAIN
| FALSE
| FOR
| FORCE
| FROM
| FULL
| GROUP
| HAVING
| IF
| IGNORE
| IN
| INDEX
| INNER
| INSERT
| INT
| INTEGER
| INTERVAL
| INTO
| IS
| JOIN
| KEY
| LEFT
| LIKE
| LIMIT
| LOCALTIME
| LOCALTIMESTAMP
| LOCK
| LONGBLOB
| LONGTEXT
| MATCH
| MEDIUMBLOB
| MEDIUMINT
| MEDIUMTEXT
| MOD
| NATURAL
| NEXT
// next should be doable as non-reserved, but is not due to the special `select next num_val` query that vitess supports
| NOT
| NULL
| NUMERIC
| OFF
| ON
| OPTIMIZE
| OR
| ORDER
| OUTER
| QUERYZ
| PRIMARY
| PROCESSLIST
| REAL
| REGEXP
| RENAME
| REPLACE
| RIGHT
| SELECT
| SEPARATOR
| SET
| SHOW
| SMALLINT
| STRAIGHT_JOIN
| TABLE
| TABLES
| TINYBLOB
| TINYINT
| TINYTEXT
| THEN
| TO
| TRUE
| TXNZ
| UNION
| UNIQUE
| UNSIGNED
| UPDATE
| USE
| USING
| UTC_DATE
| UTC_TIME
| UTC_TIMESTAMP
| VALUES
| VARBINARY
| VARCHAR
| VERSIONS
| WITH
| WHEN
| WHERE
| ZEROFILL
/*
These are non-reserved Vitess, because they don't cause conflicts in the grammar.
Some of them may be reserved in MySQL. The good news is we backtick quote them
when we rewrite the query, so no issue should arise.
Sorted alphabetically
*/
non_reserved_keyword:
AGAINST
| ALGORITHM
| AVG_ROW_LENGTH
| BIT
| BOOL
| BOOLEAN
| CLEANUP
| COMMENT_KEYWORD
| COLUMN_FORMAT
| CONNECTION
| DATA
| DATE
| DATETIME
| DELAY_KEY_WRITE
| DIRECTORY
| DISK
| DOUBLE
| DUPLICATE
| DYNAMIC
| ENUM
| ENGINE
| EXPANSION
| FIELDS
| FIXED
| FLOAT_TYPE
| FULLTEXT
| GEOMETRY
| GEOMETRYCOLLECTION
| GLOBAL
| INSERT_METHOD
| JSON
| KEY_BLOCK_SIZE
| LANGUAGE
| LAST_INSERT_ID
| LINESTRING
| MAX_ROWS
| MODE
| MEMORY
| MIN_ROWS
| MULTILINESTRING
| MULTIPOINT
| MULTIPOLYGON
| NCHAR
| OFFSET
| PACK_KEYS
| PASSWORD
| POINT
| POLYGON
| QUERY
| REPAIR
| ROW_FORMAT
| SHARE
| SIGNED
| SINGLE
| STATUS
| STORAGE
| TEXT
| TIME
| TIMESTAMP
| TRUNCATE
| UNUSED
| VIEW
| YEAR
| RADON
| ATTACH
| DETACH
| ATTACHLIST
| RESHARD
openb:
'('
{
if incNesting(yylex) {
yylex.Error("max nesting level reached")
return 1
}
}
closeb:
')'
{
decNesting(yylex)
}
force_eof:
{
forceEOF(yylex)
}
ddl_force_eof:
{
forceEOF(yylex)
}
| openb
{
forceEOF(yylex)
}
| reserved_sql_id
{
forceEOF(yylex)
}
%%
Go
1
https://gitee.com/tym_hmm/mysql-mydumper.git
git@gitee.com:tym_hmm/mysql-mydumper.git
tym_hmm
mysql-mydumper
mysql-mydumper
v1.0.4

搜索帮助