parser.y 291 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015
  1. %{
  2. // Copyright 2013 The ql Authors. All rights reserved.
  3. // Use of this source code is governed by a BSD-style
  4. // license that can be found in the LICENSES/QL-LICENSE file.
  5. // Copyright 2015 PingCAP, Inc.
  6. //
  7. // Licensed under the Apache License, Version 2.0 (the "License");
  8. // you may not use this file except in compliance with the License.
  9. // You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software
  14. // distributed under the License is distributed on an "AS IS" BASIS,
  15. // See the License for the specific language governing permissions and
  16. // limitations under the License.
  17. // Initial yacc source generated by ebnf2y[1]
  18. // at 2013-10-04 23:10:47.861401015 +0200 CEST
  19. //
  20. // $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _
  21. //
  22. // [1]: http://github.com/cznic/ebnf2y
  23. package parser
  24. import (
  25. "strings"
  26. "github.com/pingcap/parser/mysql"
  27. "github.com/pingcap/parser/ast"
  28. "github.com/pingcap/parser/model"
  29. "github.com/pingcap/parser/opcode"
  30. "github.com/pingcap/parser/auth"
  31. "github.com/pingcap/parser/charset"
  32. "github.com/pingcap/parser/types"
  33. )
  34. %}
  35. %union {
  36. offset int // offset
  37. item interface{}
  38. ident string
  39. expr ast.ExprNode
  40. statement ast.StmtNode
  41. }
  42. %token <ident>
  43. /*yy:token "%c" */
  44. identifier "identifier"
  45. /*yy:token "_%c" */
  46. underscoreCS "UNDERSCORE_CHARSET"
  47. /*yy:token "\"%c\"" */
  48. stringLit "string literal"
  49. singleAtIdentifier "identifier with single leading at"
  50. doubleAtIdentifier "identifier with double leading at"
  51. invalid "a special token never used by parser, used by lexer to indicate error"
  52. hintComment "an optimizer hint"
  53. andand "&&"
  54. pipes "||"
  55. /* The following tokens belong to ODBCDateTimeType. */
  56. odbcDateType "d"
  57. odbcTimeType "t"
  58. odbcTimestampType "ts"
  59. /* The following tokens belong to ReservedKeyword. Notice: make sure these tokens are contained in ReservedKeyword. */
  60. add "ADD"
  61. all "ALL"
  62. alter "ALTER"
  63. analyze "ANALYZE"
  64. and "AND"
  65. as "AS"
  66. asc "ASC"
  67. between "BETWEEN"
  68. bigIntType "BIGINT"
  69. binaryType "BINARY"
  70. blobType "BLOB"
  71. both "BOTH"
  72. by "BY"
  73. call "CALL"
  74. cascade "CASCADE"
  75. caseKwd "CASE"
  76. change "CHANGE"
  77. character "CHARACTER"
  78. charType "CHAR"
  79. check "CHECK"
  80. collate "COLLATE"
  81. column "COLUMN"
  82. constraint "CONSTRAINT"
  83. convert "CONVERT"
  84. create "CREATE"
  85. cross "CROSS"
  86. cumeDist "CUME_DIST"
  87. currentDate "CURRENT_DATE"
  88. currentTime "CURRENT_TIME"
  89. currentTs "CURRENT_TIMESTAMP"
  90. currentUser "CURRENT_USER"
  91. currentRole "CURRENT_ROLE"
  92. database "DATABASE"
  93. databases "DATABASES"
  94. dayHour "DAY_HOUR"
  95. dayMicrosecond "DAY_MICROSECOND"
  96. dayMinute "DAY_MINUTE"
  97. daySecond "DAY_SECOND"
  98. decimalType "DECIMAL"
  99. defaultKwd "DEFAULT"
  100. delayed "DELAYED"
  101. deleteKwd "DELETE"
  102. denseRank "DENSE_RANK"
  103. desc "DESC"
  104. describe "DESCRIBE"
  105. distinct "DISTINCT"
  106. distinctRow "DISTINCTROW"
  107. div "DIV"
  108. doubleType "DOUBLE"
  109. drop "DROP"
  110. dual "DUAL"
  111. elseKwd "ELSE"
  112. enclosed "ENCLOSED"
  113. escaped "ESCAPED"
  114. exists "EXISTS"
  115. explain "EXPLAIN"
  116. except "EXCEPT"
  117. falseKwd "FALSE"
  118. fetch "FETCH"
  119. firstValue "FIRST_VALUE"
  120. floatType "FLOAT"
  121. forKwd "FOR"
  122. force "FORCE"
  123. foreign "FOREIGN"
  124. from "FROM"
  125. fulltext "FULLTEXT"
  126. generated "GENERATED"
  127. grant "GRANT"
  128. group "GROUP"
  129. groups "GROUPS"
  130. having "HAVING"
  131. highPriority "HIGH_PRIORITY"
  132. hourMicrosecond "HOUR_MICROSECOND"
  133. hourMinute "HOUR_MINUTE"
  134. hourSecond "HOUR_SECOND"
  135. ifKwd "IF"
  136. ignore "IGNORE"
  137. in "IN"
  138. index "INDEX"
  139. infile "INFILE"
  140. inner "INNER"
  141. integerType "INTEGER"
  142. intersect "INTERSECT"
  143. interval "INTERVAL"
  144. into "INTO"
  145. outfile "OUTFILE"
  146. is "IS"
  147. insert "INSERT"
  148. intType "INT"
  149. int1Type "INT1"
  150. int2Type "INT2"
  151. int3Type "INT3"
  152. int4Type "INT4"
  153. int8Type "INT8"
  154. join "JOIN"
  155. key "KEY"
  156. keys "KEYS"
  157. kill "KILL"
  158. lag "LAG"
  159. lastValue "LAST_VALUE"
  160. lead "LEAD"
  161. leading "LEADING"
  162. left "LEFT"
  163. like "LIKE"
  164. limit "LIMIT"
  165. lines "LINES"
  166. linear "LINEAR"
  167. load "LOAD"
  168. localTime "LOCALTIME"
  169. localTs "LOCALTIMESTAMP"
  170. lock "LOCK"
  171. longblobType "LONGBLOB"
  172. longtextType "LONGTEXT"
  173. lowPriority "LOW_PRIORITY"
  174. match "MATCH"
  175. maxValue "MAXVALUE"
  176. mediumblobType "MEDIUMBLOB"
  177. mediumIntType "MEDIUMINT"
  178. mediumtextType "MEDIUMTEXT"
  179. minuteMicrosecond "MINUTE_MICROSECOND"
  180. minuteSecond "MINUTE_SECOND"
  181. mod "MOD"
  182. not "NOT"
  183. noWriteToBinLog "NO_WRITE_TO_BINLOG"
  184. nthValue "NTH_VALUE"
  185. ntile "NTILE"
  186. null "NULL"
  187. numericType "NUMERIC"
  188. on "ON"
  189. optimize "OPTIMIZE"
  190. option "OPTION"
  191. optionally "OPTIONALLY"
  192. or "OR"
  193. order "ORDER"
  194. outer "OUTER"
  195. over "OVER"
  196. partition "PARTITION"
  197. percentRank "PERCENT_RANK"
  198. placement "PLACEMENT"
  199. precisionType "PRECISION"
  200. primary "PRIMARY"
  201. procedure "PROCEDURE"
  202. rangeKwd "RANGE"
  203. rank "RANK"
  204. read "READ"
  205. realType "REAL"
  206. recursive "RECURSIVE"
  207. references "REFERENCES"
  208. regexpKwd "REGEXP"
  209. release "RELEASE"
  210. rename "RENAME"
  211. repeat "REPEAT"
  212. replace "REPLACE"
  213. require "REQUIRE"
  214. restrict "RESTRICT"
  215. revoke "REVOKE"
  216. right "RIGHT"
  217. rlike "RLIKE"
  218. row "ROW"
  219. rows "ROWS"
  220. rowNumber "ROW_NUMBER"
  221. secondMicrosecond "SECOND_MICROSECOND"
  222. selectKwd "SELECT"
  223. set "SET"
  224. show "SHOW"
  225. smallIntType "SMALLINT"
  226. spatial "SPATIAL"
  227. sql "SQL"
  228. sqlBigResult "SQL_BIG_RESULT"
  229. sqlCalcFoundRows "SQL_CALC_FOUND_ROWS"
  230. sqlSmallResult "SQL_SMALL_RESULT"
  231. ssl "SSL"
  232. starting "STARTING"
  233. statsExtended "STATS_EXTENDED"
  234. straightJoin "STRAIGHT_JOIN"
  235. tableKwd "TABLE"
  236. tableSample "TABLESAMPLE"
  237. stored "STORED"
  238. terminated "TERMINATED"
  239. then "THEN"
  240. tinyblobType "TINYBLOB"
  241. tinyIntType "TINYINT"
  242. tinytextType "TINYTEXT"
  243. to "TO"
  244. trailing "TRAILING"
  245. trigger "TRIGGER"
  246. trueKwd "TRUE"
  247. unique "UNIQUE"
  248. union "UNION"
  249. unlock "UNLOCK"
  250. unsigned "UNSIGNED"
  251. update "UPDATE"
  252. usage "USAGE"
  253. use "USE"
  254. using "USING"
  255. utcDate "UTC_DATE"
  256. utcTimestamp "UTC_TIMESTAMP"
  257. utcTime "UTC_TIME"
  258. values "VALUES"
  259. long "LONG"
  260. varcharType "VARCHAR"
  261. varcharacter "VARCHARACTER"
  262. varbinaryType "VARBINARY"
  263. varying "VARYING"
  264. virtual "VIRTUAL"
  265. when "WHEN"
  266. where "WHERE"
  267. write "WRITE"
  268. window "WINDOW"
  269. with "WITH"
  270. xor "XOR"
  271. yearMonth "YEAR_MONTH"
  272. zerofill "ZEROFILL"
  273. natural "NATURAL"
  274. /* The following tokens belong to UnReservedKeyword. Notice: make sure these tokens are contained in UnReservedKeyword. */
  275. account "ACCOUNT"
  276. action "ACTION"
  277. advise "ADVISE"
  278. after "AFTER"
  279. against "AGAINST"
  280. ago "AGO"
  281. algorithm "ALGORITHM"
  282. always "ALWAYS"
  283. any "ANY"
  284. ascii "ASCII"
  285. autoIdCache "AUTO_ID_CACHE"
  286. autoIncrement "AUTO_INCREMENT"
  287. autoRandom "AUTO_RANDOM"
  288. autoRandomBase "AUTO_RANDOM_BASE"
  289. avg "AVG"
  290. avgRowLength "AVG_ROW_LENGTH"
  291. backend "BACKEND"
  292. backup "BACKUP"
  293. backups "BACKUPS"
  294. begin "BEGIN"
  295. bernoulli "BERNOULLI"
  296. binding "BINDING"
  297. bindings "BINDINGS"
  298. binlog "BINLOG"
  299. bitType "BIT"
  300. block "BLOCK"
  301. booleanType "BOOLEAN"
  302. boolType "BOOL"
  303. btree "BTREE"
  304. byteType "BYTE"
  305. cache "CACHE"
  306. capture "CAPTURE"
  307. cascaded "CASCADED"
  308. causal "CAUSAL"
  309. chain "CHAIN"
  310. charsetKwd "CHARSET"
  311. checkpoint "CHECKPOINT"
  312. checksum "CHECKSUM"
  313. cipher "CIPHER"
  314. cleanup "CLEANUP"
  315. client "CLIENT"
  316. clientErrorsSummary "CLIENT_ERRORS_SUMMARY"
  317. coalesce "COALESCE"
  318. collation "COLLATION"
  319. columnFormat "COLUMN_FORMAT"
  320. columns "COLUMNS"
  321. config "CONFIG"
  322. comment "COMMENT"
  323. commit "COMMIT"
  324. committed "COMMITTED"
  325. compact "COMPACT"
  326. compressed "COMPRESSED"
  327. compression "COMPRESSION"
  328. concurrency "CONCURRENCY"
  329. connection "CONNECTION"
  330. consistency "CONSISTENCY"
  331. consistent "CONSISTENT"
  332. constraints "CONSTRAINTS"
  333. context "CONTEXT"
  334. cpu "CPU"
  335. csvBackslashEscape "CSV_BACKSLASH_ESCAPE"
  336. csvDelimiter "CSV_DELIMITER"
  337. csvHeader "CSV_HEADER"
  338. csvNotNull "CSV_NOT_NULL"
  339. csvNull "CSV_NULL"
  340. csvSeparator "CSV_SEPARATOR"
  341. csvTrimLastSeparators "CSV_TRIM_LAST_SEPARATORS"
  342. current "CURRENT"
  343. clustered "CLUSTERED"
  344. cycle "CYCLE"
  345. data "DATA"
  346. datetimeType "DATETIME"
  347. dateType "DATE"
  348. day "DAY"
  349. deallocate "DEALLOCATE"
  350. definer "DEFINER"
  351. delayKeyWrite "DELAY_KEY_WRITE"
  352. directory "DIRECTORY"
  353. disable "DISABLE"
  354. discard "DISCARD"
  355. disk "DISK"
  356. do "DO"
  357. duplicate "DUPLICATE"
  358. dynamic "DYNAMIC"
  359. enable "ENABLE"
  360. encryption "ENCRYPTION"
  361. end "END"
  362. enforced "ENFORCED"
  363. engine "ENGINE"
  364. engines "ENGINES"
  365. enum "ENUM"
  366. errorKwd "ERROR"
  367. escape "ESCAPE"
  368. event "EVENT"
  369. events "EVENTS"
  370. evolve "EVOLVE"
  371. exchange "EXCHANGE"
  372. exclusive "EXCLUSIVE"
  373. execute "EXECUTE"
  374. expansion "EXPANSION"
  375. expire "EXPIRE"
  376. extended "EXTENDED"
  377. faultsSym "FAULTS"
  378. fields "FIELDS"
  379. file "FILE"
  380. first "FIRST"
  381. fixed "FIXED"
  382. flush "FLUSH"
  383. following "FOLLOWING"
  384. format "FORMAT"
  385. full "FULL"
  386. function "FUNCTION"
  387. general "GENERAL"
  388. global "GLOBAL"
  389. grants "GRANTS"
  390. hash "HASH"
  391. histogram "HISTOGRAM"
  392. history "HISTORY"
  393. hosts "HOSTS"
  394. hour "HOUR"
  395. identified "IDENTIFIED"
  396. identSQLErrors "ERRORS"
  397. importKwd "IMPORT"
  398. imports "IMPORTS"
  399. increment "INCREMENT"
  400. incremental "INCREMENTAL"
  401. indexes "INDEXES"
  402. insertMethod "INSERT_METHOD"
  403. instance "INSTANCE"
  404. invisible "INVISIBLE"
  405. invoker "INVOKER"
  406. io "IO"
  407. ipc "IPC"
  408. isolation "ISOLATION"
  409. issuer "ISSUER"
  410. jsonType "JSON"
  411. keyBlockSize "KEY_BLOCK_SIZE"
  412. labels "LABELS"
  413. language "LANGUAGE"
  414. last "LAST"
  415. lastBackup "LAST_BACKUP"
  416. lastval "LASTVAL"
  417. less "LESS"
  418. level "LEVEL"
  419. list "LIST"
  420. local "LOCAL"
  421. locked "LOCKED"
  422. location "LOCATION"
  423. logs "LOGS"
  424. master "MASTER"
  425. max_idxnum "MAX_IDXNUM"
  426. max_minutes "MAX_MINUTES"
  427. maxConnectionsPerHour "MAX_CONNECTIONS_PER_HOUR"
  428. maxQueriesPerHour "MAX_QUERIES_PER_HOUR"
  429. maxRows "MAX_ROWS"
  430. maxUpdatesPerHour "MAX_UPDATES_PER_HOUR"
  431. maxUserConnections "MAX_USER_CONNECTIONS"
  432. mb "MB"
  433. memory "MEMORY"
  434. merge "MERGE"
  435. microsecond "MICROSECOND"
  436. minRows "MIN_ROWS"
  437. minute "MINUTE"
  438. minValue "MINVALUE"
  439. mode "MODE"
  440. modify "MODIFY"
  441. month "MONTH"
  442. names "NAMES"
  443. national "NATIONAL"
  444. ncharType "NCHAR"
  445. never "NEVER"
  446. next "NEXT"
  447. nextval "NEXTVAL"
  448. no "NO"
  449. nocache "NOCACHE"
  450. nocycle "NOCYCLE"
  451. nodegroup "NODEGROUP"
  452. nomaxvalue "NOMAXVALUE"
  453. nominvalue "NOMINVALUE"
  454. nonclustered "NONCLUSTERED"
  455. none "NONE"
  456. nowait "NOWAIT"
  457. nvarcharType "NVARCHAR"
  458. nulls "NULLS"
  459. off "OFF"
  460. offset "OFFSET"
  461. onDuplicate "ON_DUPLICATE"
  462. online "ONLINE"
  463. only "ONLY"
  464. open "OPEN"
  465. optional "OPTIONAL"
  466. packKeys "PACK_KEYS"
  467. pageSym "PAGE"
  468. parser "PARSER"
  469. partial "PARTIAL"
  470. partitioning "PARTITIONING"
  471. partitions "PARTITIONS"
  472. password "PASSWORD"
  473. percent "PERCENT"
  474. per_db "PER_DB"
  475. per_table "PER_TABLE"
  476. pipesAsOr
  477. plugins "PLUGINS"
  478. policy "POLICY"
  479. preSplitRegions "PRE_SPLIT_REGIONS"
  480. preceding "PRECEDING"
  481. prepare "PREPARE"
  482. privileges "PRIVILEGES"
  483. process "PROCESS"
  484. processlist "PROCESSLIST"
  485. profile "PROFILE"
  486. profiles "PROFILES"
  487. proxy "PROXY"
  488. purge "PURGE"
  489. quarter "QUARTER"
  490. queries "QUERIES"
  491. query "QUERY"
  492. quick "QUICK"
  493. rateLimit "RATE_LIMIT"
  494. rebuild "REBUILD"
  495. recover "RECOVER"
  496. redundant "REDUNDANT"
  497. reload "RELOAD"
  498. remove "REMOVE"
  499. reorganize "REORGANIZE"
  500. repair "REPAIR"
  501. repeatable "REPEATABLE"
  502. replica "REPLICA"
  503. replicas "REPLICAS"
  504. replication "REPLICATION"
  505. required "REQUIRED"
  506. respect "RESPECT"
  507. restart "RESTART"
  508. restore "RESTORE"
  509. restores "RESTORES"
  510. resume "RESUME"
  511. reverse "REVERSE"
  512. role "ROLE"
  513. rollback "ROLLBACK"
  514. routine "ROUTINE"
  515. rowCount "ROW_COUNT"
  516. rowFormat "ROW_FORMAT"
  517. rtree "RTREE"
  518. san "SAN"
  519. second "SECOND"
  520. secondaryEngine "SECONDARY_ENGINE"
  521. secondaryLoad "SECONDARY_LOAD"
  522. secondaryUnload "SECONDARY_UNLOAD"
  523. security "SECURITY"
  524. sendCredentialsToTiKV "SEND_CREDENTIALS_TO_TIKV"
  525. separator "SEPARATOR"
  526. sequence "SEQUENCE"
  527. serial "SERIAL"
  528. serializable "SERIALIZABLE"
  529. session "SESSION"
  530. setval "SETVAL"
  531. shardRowIDBits "SHARD_ROW_ID_BITS"
  532. share "SHARE"
  533. shared "SHARED"
  534. shutdown "SHUTDOWN"
  535. signed "SIGNED"
  536. simple "SIMPLE"
  537. skip "SKIP"
  538. skipSchemaFiles "SKIP_SCHEMA_FILES"
  539. slave "SLAVE"
  540. slow "SLOW"
  541. snapshot "SNAPSHOT"
  542. some "SOME"
  543. source "SOURCE"
  544. sqlBufferResult "SQL_BUFFER_RESULT"
  545. sqlCache "SQL_CACHE"
  546. sqlNoCache "SQL_NO_CACHE"
  547. sqlTsiDay "SQL_TSI_DAY"
  548. sqlTsiHour "SQL_TSI_HOUR"
  549. sqlTsiMinute "SQL_TSI_MINUTE"
  550. sqlTsiMonth "SQL_TSI_MONTH"
  551. sqlTsiQuarter "SQL_TSI_QUARTER"
  552. sqlTsiSecond "SQL_TSI_SECOND"
  553. sqlTsiWeek "SQL_TSI_WEEK"
  554. sqlTsiYear "SQL_TSI_YEAR"
  555. start "START"
  556. statsAutoRecalc "STATS_AUTO_RECALC"
  557. statsPersistent "STATS_PERSISTENT"
  558. statsSamplePages "STATS_SAMPLE_PAGES"
  559. status "STATUS"
  560. storage "STORAGE"
  561. strictFormat "STRICT_FORMAT"
  562. subject "SUBJECT"
  563. subpartition "SUBPARTITION"
  564. subpartitions "SUBPARTITIONS"
  565. super "SUPER"
  566. swaps "SWAPS"
  567. switchesSym "SWITCHES"
  568. system "SYSTEM"
  569. systemTime "SYSTEM_TIME"
  570. tableChecksum "TABLE_CHECKSUM"
  571. tables "TABLES"
  572. tablespace "TABLESPACE"
  573. temporary "TEMPORARY"
  574. temptable "TEMPTABLE"
  575. textType "TEXT"
  576. than "THAN"
  577. tikvImporter "TIKV_IMPORTER"
  578. timestampType "TIMESTAMP"
  579. timeType "TIME"
  580. tp "TYPE"
  581. trace "TRACE"
  582. traditional "TRADITIONAL"
  583. transaction "TRANSACTION"
  584. triggers "TRIGGERS"
  585. truncate "TRUNCATE"
  586. unbounded "UNBOUNDED"
  587. uncommitted "UNCOMMITTED"
  588. undefined "UNDEFINED"
  589. unicodeSym "UNICODE"
  590. unknown "UNKNOWN"
  591. user "USER"
  592. validation "VALIDATION"
  593. value "VALUE"
  594. variables "VARIABLES"
  595. view "VIEW"
  596. visible "VISIBLE"
  597. warnings "WARNINGS"
  598. week "WEEK"
  599. weightString "WEIGHT_STRING"
  600. without "WITHOUT"
  601. x509 "X509"
  602. yearType "YEAR"
  603. wait "WAIT"
  604. /* The following tokens belong to NotKeywordToken. Notice: make sure these tokens are contained in NotKeywordToken. */
  605. addDate "ADDDATE"
  606. approxCountDistinct "APPROX_COUNT_DISTINCT"
  607. approxPercentile "APPROX_PERCENTILE"
  608. bitAnd "BIT_AND"
  609. bitOr "BIT_OR"
  610. bitXor "BIT_XOR"
  611. bound "BOUND"
  612. cast "CAST"
  613. copyKwd "COPY"
  614. curTime "CURTIME"
  615. dateAdd "DATE_ADD"
  616. dateSub "DATE_SUB"
  617. exact "EXACT"
  618. extract "EXTRACT"
  619. flashback "FLASHBACK"
  620. getFormat "GET_FORMAT"
  621. groupConcat "GROUP_CONCAT"
  622. next_row_id "NEXT_ROW_ID"
  623. inplace "INPLACE"
  624. instant "INSTANT"
  625. internal "INTERNAL"
  626. min "MIN"
  627. max "MAX"
  628. now "NOW"
  629. position "POSITION"
  630. recent "RECENT"
  631. running "RUNNING"
  632. s3 "S3"
  633. staleness "STALENESS"
  634. std "STD"
  635. stddev "STDDEV"
  636. stddevPop "STDDEV_POP"
  637. stddevSamp "STDDEV_SAMP"
  638. stop "STOP"
  639. strict "STRICT"
  640. strong "STRONG"
  641. subDate "SUBDATE"
  642. sum "SUM"
  643. substring "SUBSTRING"
  644. timestampAdd "TIMESTAMPADD"
  645. timestampDiff "TIMESTAMPDIFF"
  646. tokudbDefault "TOKUDB_DEFAULT"
  647. tokudbFast "TOKUDB_FAST"
  648. tokudbLzma "TOKUDB_LZMA"
  649. tokudbQuickLZ "TOKUDB_QUICKLZ"
  650. tokudbSnappy "TOKUDB_SNAPPY"
  651. tokudbSmall "TOKUDB_SMALL"
  652. tokudbUncompressed "TOKUDB_UNCOMPRESSED"
  653. tokudbZlib "TOKUDB_ZLIB"
  654. top "TOP"
  655. trim "TRIM"
  656. variance "VARIANCE"
  657. varPop "VAR_POP"
  658. varSamp "VAR_SAMP"
  659. exprPushdownBlacklist "EXPR_PUSHDOWN_BLACKLIST"
  660. optRuleBlacklist "OPT_RULE_BLACKLIST"
  661. jsonArrayagg "JSON_ARRAYAGG"
  662. jsonObjectAgg "JSON_OBJECTAGG"
  663. tls "TLS"
  664. follower "FOLLOWER"
  665. leader "LEADER"
  666. learner "LEARNER"
  667. voter "VOTER"
  668. /* The following tokens belong to TiDBKeyword. Notice: make sure these tokens are contained in TiDBKeyword. */
  669. admin "ADMIN"
  670. buckets "BUCKETS"
  671. builtins "BUILTINS"
  672. cancel "CANCEL"
  673. cardinality "CARDINALITY"
  674. cmSketch "CMSKETCH"
  675. correlation "CORRELATION"
  676. ddl "DDL"
  677. dependency "DEPENDENCY"
  678. depth "DEPTH"
  679. drainer "DRAINER"
  680. jobs "JOBS"
  681. job "JOB"
  682. nodeID "NODE_ID"
  683. nodeState "NODE_STATE"
  684. optimistic "OPTIMISTIC"
  685. pessimistic "PESSIMISTIC"
  686. pump "PUMP"
  687. samples "SAMPLES"
  688. statistics "STATISTICS"
  689. stats "STATS"
  690. statsMeta "STATS_META"
  691. statsHistograms "STATS_HISTOGRAMS"
  692. statsBuckets "STATS_BUCKETS"
  693. statsHealthy "STATS_HEALTHY"
  694. statsTopN "STATS_TOPN"
  695. telemetry "TELEMETRY"
  696. telemetryID "TELEMETRY_ID"
  697. tidb "TIDB"
  698. tiFlash "TIFLASH"
  699. topn "TOPN"
  700. split "SPLIT"
  701. width "WIDTH"
  702. reset "RESET"
  703. regions "REGIONS"
  704. region "REGION"
  705. builtinAddDate
  706. builtinBitAnd
  707. builtinBitOr
  708. builtinBitXor
  709. builtinCast
  710. builtinCount
  711. builtinApproxCountDistinct
  712. builtinApproxPercentile
  713. builtinCurDate
  714. builtinCurTime
  715. builtinDateAdd
  716. builtinDateSub
  717. builtinExtract
  718. builtinGroupConcat
  719. builtinMax
  720. builtinMin
  721. builtinNow
  722. builtinPosition
  723. builtinSubDate
  724. builtinSubstring
  725. builtinSum
  726. builtinSysDate
  727. builtinStddevPop
  728. builtinStddevSamp
  729. builtinTrim
  730. builtinUser
  731. builtinVarPop
  732. builtinVarSamp
  733. %token <item>
  734. /*yy:token "1.%d" */
  735. floatLit "floating-point literal"
  736. /*yy:token "1.%d" */
  737. decLit "decimal literal"
  738. /*yy:token "%d" */
  739. intLit "integer literal"
  740. /*yy:token "%x" */
  741. hexLit "hexadecimal literal"
  742. /*yy:token "%b" */
  743. bitLit "bit literal"
  744. andnot "&^"
  745. assignmentEq ":="
  746. eq "="
  747. ge ">="
  748. le "<="
  749. jss "->"
  750. juss "->>"
  751. lsh "<<"
  752. neq "!="
  753. neqSynonym "<>"
  754. nulleq "<=>"
  755. paramMarker "?"
  756. rsh ">>"
  757. %token not2
  758. %type <expr>
  759. Expression "expression"
  760. MaxValueOrExpression "maxvalue or expression"
  761. BoolPri "boolean primary expression"
  762. ExprOrDefault "expression or default"
  763. PredicateExpr "Predicate expression factor"
  764. SetExpr "Set variable statement value's expression"
  765. BitExpr "bit expression"
  766. SimpleExpr "simple expression"
  767. SimpleIdent "Simple Identifier expression"
  768. SumExpr "aggregate functions"
  769. FunctionCallGeneric "Function call with Identifier"
  770. FunctionCallKeyword "Function call with keyword as function name"
  771. FunctionCallNonKeyword "Function call with nonkeyword as function name"
  772. Literal "literal value"
  773. Variable "User or system variable"
  774. SystemVariable "System defined variable name"
  775. UserVariable "User defined variable name"
  776. SubSelect "Sub Select"
  777. SubSelect2 "Sub Select2"
  778. StringLiteral "text literal"
  779. ExpressionOpt "Optional expression"
  780. SignedLiteral "Literal or NumLiteral with sign"
  781. DefaultValueExpr "DefaultValueExpr(Now or Signed Literal)"
  782. NowSymOptionFraction "NowSym with optional fraction part"
  783. CharsetNameOrDefault "Character set name or default"
  784. NextValueForSequence "Default nextval expression"
  785. FunctionNameSequence "Function with sequence function call"
  786. WindowFuncCall "WINDOW function call"
  787. RepeatableOpt "Repeatable optional in sample clause"
  788. ProcedureCall "Procedure call with Identifier or identifier"
  789. %type <statement>
  790. AdminStmt "Check table statement or show ddl statement"
  791. AlterDatabaseStmt "Alter database statement"
  792. AlterTableStmt "Alter table statement"
  793. AlterUserStmt "Alter user statement"
  794. AlterImportStmt "ALTER IMPORT statement"
  795. AlterInstanceStmt "Alter instance statement"
  796. AlterSequenceStmt "Alter sequence statement"
  797. AnalyzeTableStmt "Analyze table statement"
  798. BeginTransactionStmt "BEGIN TRANSACTION statement"
  799. BinlogStmt "Binlog base64 statement"
  800. BRIEStmt "BACKUP or RESTORE statement"
  801. CommitStmt "COMMIT statement"
  802. CreateTableStmt "CREATE TABLE statement"
  803. CreateViewStmt "CREATE VIEW statement"
  804. CreateUserStmt "CREATE User statement"
  805. CreateRoleStmt "CREATE Role statement"
  806. CreateDatabaseStmt "Create Database Statement"
  807. CreateIndexStmt "CREATE INDEX statement"
  808. CreateImportStmt "CREATE IMPORT statement"
  809. CreateBindingStmt "CREATE BINDING statement"
  810. CreateSequenceStmt "CREATE SEQUENCE statement"
  811. CreateStatisticsStmt "CREATE STATISTICS statement"
  812. DoStmt "Do statement"
  813. DropDatabaseStmt "DROP DATABASE statement"
  814. DropImportStmt "DROP IMPORT statement"
  815. DropIndexStmt "DROP INDEX statement"
  816. DropStatisticsStmt "DROP STATISTICS statement"
  817. DropStatsStmt "DROP STATS statement"
  818. DropTableStmt "DROP TABLE statement"
  819. DropSequenceStmt "DROP SEQUENCE statement"
  820. DropUserStmt "DROP USER"
  821. DropRoleStmt "DROP ROLE"
  822. DropViewStmt "DROP VIEW statement"
  823. DropBindingStmt "DROP BINDING statement"
  824. DeallocateStmt "Deallocate prepared statement"
  825. DeleteFromStmt "DELETE FROM statement"
  826. DeleteWithoutUsingStmt "Normal DELETE statement"
  827. DeleteWithUsingStmt "DELETE USING statement"
  828. EmptyStmt "empty statement"
  829. ExecuteStmt "Execute statement"
  830. ExplainStmt "EXPLAIN statement"
  831. ExplainableStmt "explainable statement"
  832. FlushStmt "Flush statement"
  833. FlashbackTableStmt "Flashback table statement"
  834. GrantStmt "Grant statement"
  835. GrantProxyStmt "Grant proxy statement"
  836. GrantRoleStmt "Grant role statement"
  837. InsertIntoStmt "INSERT INTO statement"
  838. CallStmt "CALL statement"
  839. IndexAdviseStmt "INDEX ADVISE statement"
  840. KillStmt "Kill statement"
  841. LoadDataStmt "Load data statement"
  842. LoadStatsStmt "Load statistic statement"
  843. LockTablesStmt "Lock tables statement"
  844. PreparedStmt "PreparedStmt"
  845. PurgeImportStmt "PURGE IMPORT statement that removes a IMPORT task record"
  846. SelectStmt "SELECT statement"
  847. RenameTableStmt "rename table statement"
  848. RenameUserStmt "rename user statement"
  849. ReplaceIntoStmt "REPLACE INTO statement"
  850. RecoverTableStmt "recover table statement"
  851. ResumeImportStmt "RESUME IMPORT statement"
  852. RevokeStmt "Revoke statement"
  853. RevokeRoleStmt "Revoke role statement"
  854. RollbackStmt "ROLLBACK statement"
  855. SplitRegionStmt "Split index region statement"
  856. SetStmt "Set variable statement"
  857. ChangeStmt "Change statement"
  858. SetRoleStmt "Set active role statement"
  859. SetDefaultRoleStmt "Set default statement for some user"
  860. ShowImportStmt "SHOW IMPORT statement"
  861. ShowStmt "Show engines/databases/tables/user/columns/warnings/status statement"
  862. Statement "statement"
  863. StopImportStmt "STOP IMPORT statement"
  864. TraceStmt "TRACE statement"
  865. TraceableStmt "traceable statement"
  866. TruncateTableStmt "TRUNCATE TABLE statement"
  867. UnlockTablesStmt "Unlock tables statement"
  868. UpdateStmt "UPDATE statement"
  869. SetOprStmt "Union/Except/Intersect select statement"
  870. SetOprStmt1 "Union/Except/Intersect select statement1"
  871. SetOprStmt2 "Union/Except/Intersect select statement2"
  872. UseStmt "USE statement"
  873. ShutdownStmt "SHUTDOWN statement"
  874. CreateViewSelectOpt "Select/Union/Except/Intersect statement in CREATE VIEW ... AS SELECT"
  875. BindableStmt "Statement that can be created binding on"
  876. SelectStmtNoWith "Select statement with CTE clause"
  877. UpdateStmtNoWith "Update statement with CTE clause"
  878. %type <item>
  879. AdminShowSlow "Admin Show Slow statement"
  880. AllOrPartitionNameList "All or partition name list"
  881. AlgorithmClause "Alter table algorithm"
  882. AlterTablePartitionOpt "Alter table partition option"
  883. AlterTableSpec "Alter table specification"
  884. AlterTableSpecList "Alter table specification list"
  885. AlterTableSpecListOpt "Alter table specification list optional"
  886. AlterSequenceOption "Alter sequence option"
  887. AlterSequenceOptionList "Alter sequence option list"
  888. AnalyzeOption "Analyze option"
  889. AnalyzeOptionList "Analyze option list"
  890. AnalyzeOptionListOpt "Optional analyze option list"
  891. AnyOrAll "Any or All for subquery"
  892. Assignment "assignment"
  893. AssignmentList "assignment list"
  894. AssignmentListOpt "assignment list opt"
  895. AuthOption "User auth option"
  896. Boolean "Boolean (0, 1, false, true)"
  897. OptionalBraces "optional braces"
  898. CastType "Cast function target type"
  899. ClearPasswordExpireOptions "Clear password expire options"
  900. ColumnDef "table column definition"
  901. ColumnDefList "table column definition list"
  902. ColumnName "column name"
  903. ColumnNameOrUserVariable "column name or user variable"
  904. ColumnNameList "column name list"
  905. ColumnNameOrUserVariableList "column name or user variable list"
  906. ColumnList "column list"
  907. ColumnNameListOpt "column name list opt"
  908. IdentList "identifier list"
  909. IdentListWithParenOpt "column name list opt with parentheses"
  910. ColumnNameOrUserVarListOpt "column name or user vairiabe list opt"
  911. ColumnNameOrUserVarListOptWithBrackets "column name or user variable list opt with brackets"
  912. ColumnSetValue "insert statement set value by column name"
  913. ColumnSetValueList "insert statement set value by column name list"
  914. CompareOp "Compare opcode"
  915. ColumnOption "column definition option"
  916. ColumnOptionList "column definition option list"
  917. VirtualOrStored "indicate generated column is stored or not"
  918. ColumnOptionListOpt "optional column definition option list"
  919. CommonTableExpr "Common table expression"
  920. CompletionTypeWithinTransaction "overwrite system variable completion_type within current transaction"
  921. ConnectionOption "single connection options"
  922. ConnectionOptionList "connection options for CREATE USER statement"
  923. ConnectionOptions "optional connection options for CREATE USER statement"
  924. Constraint "table constraint"
  925. ConstraintElem "table constraint element"
  926. ConstraintKeywordOpt "Constraint Keyword or empty"
  927. CreateSequenceOptionListOpt "create sequence list opt"
  928. CreateTableOptionListOpt "create table option list opt"
  929. CreateTableSelectOpt "Select/Union statement in CREATE TABLE ... SELECT"
  930. DatabaseOption "CREATE Database specification"
  931. DatabaseOptionList "CREATE Database specification list"
  932. DatabaseOptionListOpt "CREATE Database specification list opt"
  933. DistinctOpt "Explicit distinct option"
  934. DefaultFalseDistinctOpt "Distinct option which defaults to false"
  935. DefaultTrueDistinctOpt "Distinct option which defaults to true"
  936. BuggyDefaultFalseDistinctOpt "Distinct option which accepts DISTINCT ALL and defaults to false"
  937. RequireClause "Encrypted connections options"
  938. RequireClauseOpt "optional Encrypted connections options"
  939. EqOpt "= or empty"
  940. ErrorHandling "specify exit, replace or skip when meet error"
  941. EscapedTableRef "escaped table reference"
  942. ExpressionList "expression list"
  943. ExtendedPriv "Extended privileges like LOAD FROM S3 or dynamic privileges"
  944. MaxValueOrExpressionList "maxvalue or expression list"
  945. ExpressionListOpt "expression list opt"
  946. FetchFirstOpt "Fetch First/Next Option"
  947. FuncDatetimePrecListOpt "Function datetime precision list opt"
  948. FuncDatetimePrecList "Function datetime precision list"
  949. Field "field expression"
  950. Fields "Fields clause"
  951. FieldList "field expression list"
  952. FlushOption "Flush option"
  953. InstanceOption "Instance option"
  954. FulltextSearchModifierOpt "Fulltext modifier"
  955. PluginNameList "Plugin Name List"
  956. TableRefsClause "Table references clause"
  957. FieldItem "Field item for load data clause"
  958. FieldItemList "Field items for load data clause"
  959. FuncDatetimePrec "Function datetime precision"
  960. GetFormatSelector "{DATE|DATETIME|TIME|TIMESTAMP}"
  961. GlobalScope "The scope of variable"
  962. GroupByClause "GROUP BY clause"
  963. HavingClause "HAVING clause"
  964. HandleRange "handle range"
  965. HandleRangeList "handle range list"
  966. IfExists "If Exists"
  967. IfNotExists "If Not Exists"
  968. IfNotRunning "If Not Running"
  969. IfRunning "If Running"
  970. IgnoreOptional "IGNORE or empty"
  971. ImportTruncate "truncate all data or data related to errors"
  972. IndexHint "index hint"
  973. IndexHintList "index hint list"
  974. IndexHintListOpt "index hint list opt"
  975. IndexHintScope "index hint scope"
  976. IndexHintType "index hint type"
  977. IndexInvisible "index visible/invisible"
  978. IndexKeyTypeOpt "index key type"
  979. IndexLockAndAlgorithmOpt "index lock and algorithm"
  980. IndexNameAndTypeOpt "index name and index type"
  981. IndexNameList "index name list"
  982. IndexOption "Index Option"
  983. IndexOptionList "Index Option List or empty"
  984. IndexType "index type"
  985. IndexName "index name"
  986. IndexTypeName "index type name"
  987. IndexTypeOpt "optional index type"
  988. IndexPartSpecification "Index column name or expression"
  989. IndexPartSpecificationList "List of index column name or expression"
  990. IndexPartSpecificationListOpt "Optional list of index column name or expression"
  991. InsertValues "Rest part of INSERT/REPLACE INTO statement"
  992. JoinTable "join table"
  993. JoinType "join type"
  994. KillOrKillTiDB "Kill or Kill TiDB"
  995. LocationLabelList "location label name list"
  996. LikeTableWithOrWithoutParen "LIKE table_name or ( LIKE table_name )"
  997. LimitClause "LIMIT clause"
  998. LimitOption "Limit option could be integer or parameter marker."
  999. Lines "Lines clause"
  1000. LoadDataSetSpecOpt "Optional load data specification"
  1001. LoadDataSetList "Load data specifications"
  1002. LoadDataSetItem "Single load data specification"
  1003. LocalOpt "Local opt"
  1004. LockClause "Alter table lock clause"
  1005. LogTypeOpt "Optional log type used in FLUSH statements"
  1006. NumLiteral "Num/Int/Float/Decimal Literal"
  1007. NoWriteToBinLogAliasOpt "NO_WRITE_TO_BINLOG alias LOCAL or empty"
  1008. ObjectType "Grant statement object type"
  1009. OnDuplicateKeyUpdate "ON DUPLICATE KEY UPDATE value list"
  1010. DuplicateOpt "[IGNORE|REPLACE] in CREATE TABLE ... SELECT statement or LOAD DATA statement"
  1011. OptErrors "ERRORS or empty"
  1012. OptFull "Full or empty"
  1013. OptTemporary "TEMPORARY or empty"
  1014. OptOrder "Optional ordering keyword: ASC/DESC. Default to ASC"
  1015. Order "Ordering keyword: ASC or DESC"
  1016. OptionLevel "3 levels used by lightning config"
  1017. OrderBy "ORDER BY clause"
  1018. OrReplace "or replace"
  1019. ByItem "BY item"
  1020. OrderByOptional "Optional ORDER BY clause optional"
  1021. ByList "BY list"
  1022. AlterOrderItem "Alter Order item"
  1023. AlterOrderList "Alter Order list"
  1024. QuickOptional "QUICK or empty"
  1025. PartitionDefinition "Partition definition"
  1026. PartitionDefinitionList "Partition definition list"
  1027. PartitionDefinitionListOpt "Partition definition list option"
  1028. PartitionKeyAlgorithmOpt "ALGORITHM = n option for KEY partition"
  1029. PartitionMethod "Partition method"
  1030. PartitionOpt "Partition option"
  1031. PartitionNameList "Partition name list"
  1032. PartitionNameListOpt "table partition names list optional"
  1033. PartitionNumOpt "PARTITION NUM option"
  1034. PartDefValuesOpt "VALUES {LESS THAN {(expr | value_list) | MAXVALUE} | IN {value_list}"
  1035. PartDefOptionList "PartDefOption list"
  1036. PartDefOption "COMMENT [=] xxx | TABLESPACE [=] tablespace_name | ENGINE [=] xxx"
  1037. PasswordExpire "Single password option for create user statement"
  1038. PasswordOrLockOption "Single password or lock option for create user statement"
  1039. PasswordOrLockOptionList "Password or lock options for create user statement"
  1040. PasswordOrLockOptions "Optional password or lock options for create user statement"
  1041. ColumnPosition "Column position [First|After ColumnName]"
  1042. PrepareSQL "Prepare statement sql string"
  1043. Priority "Statement priority"
  1044. PriorityOpt "Statement priority option"
  1045. PrivElem "Privilege element"
  1046. PrivLevel "Privilege scope"
  1047. PrivType "Privilege type"
  1048. ReferDef "Reference definition"
  1049. OnDelete "ON DELETE clause"
  1050. OnUpdate "ON UPDATE clause"
  1051. OnDeleteUpdateOpt "optional ON DELETE and UPDATE clause"
  1052. OptGConcatSeparator "optional GROUP_CONCAT SEPARATOR"
  1053. ReferOpt "reference option"
  1054. ReorganizePartitionRuleOpt "optional reorganize partition partition list and definitions"
  1055. RequireList "require list"
  1056. RequireListElement "require list element"
  1057. Rolename "Rolename"
  1058. RolenameComposed "Rolename that composed with more than 1 symbol"
  1059. RolenameList "RolenameList"
  1060. RolenameWithoutIdent "Rolename except identifier"
  1061. RoleOrPrivElem "Element that may be a Rolename or PrivElem"
  1062. RoleOrPrivElemList "RoleOrPrivElem list"
  1063. RoleSpec "Rolename and auth option"
  1064. RoleSpecList "Rolename and auth option list"
  1065. RowFormat "Row format option"
  1066. RowValue "Row value"
  1067. RowStmt "Row constructor"
  1068. SelectLockOpt "SELECT lock options"
  1069. SelectStmtSQLCache "SELECT statement optional SQL_CAHCE/SQL_NO_CACHE"
  1070. SelectStmtFieldList "SELECT statement field list"
  1071. SelectStmtLimit "SELECT statement LIMIT clause"
  1072. SelectStmtLimitOpt "SELECT statement optional LIMIT clause"
  1073. SelectStmtOpt "Select statement option"
  1074. SelectStmtOpts "Select statement options"
  1075. SelectStmtOptsList "Select statement options list"
  1076. SelectStmtBasic "SELECT statement from constant value"
  1077. SelectStmtFromDualTable "SELECT statement from dual table"
  1078. SelectStmtFromTable "SELECT statement from table"
  1079. SelectStmtGroup "SELECT statement optional GROUP BY clause"
  1080. SelectStmtIntoOption "SELECT statement into clause"
  1081. SequenceOption "Create sequence option"
  1082. SequenceOptionList "Create sequence option list"
  1083. SetRoleOpt "Set role options"
  1084. SetDefaultRoleOpt "Set default role options"
  1085. SetOpr "Set operator contain UNION, EXCEPT and INTERSECT"
  1086. SetOprClause "Union/Except/Intersect select clause"
  1087. SetOprClauseList "Union/Except/Intersect select clause list"
  1088. ShowTargetFilterable "Show target that can be filtered by WHERE or LIKE"
  1089. ShowTableAliasOpt "Show table alias option"
  1090. ShowLikeOrWhereOpt "Show like or where clause option"
  1091. ShowProfileArgsOpt "Show profile args option"
  1092. ShowProfileTypesOpt "Show profile types option"
  1093. ShowProfileType "Show profile type"
  1094. ShowProfileTypes "Show profile types"
  1095. SplitOption "Split Option"
  1096. SplitSyntaxOption "Split syntax Option"
  1097. StatementList "statement list"
  1098. StatsPersistentVal "stats_persistent value"
  1099. StatsType "stats type value"
  1100. StringList "string list"
  1101. SubPartDefinition "SubPartition definition"
  1102. SubPartDefinitionList "SubPartition definition list"
  1103. SubPartDefinitionListOpt "SubPartition definition list optional"
  1104. SubPartitionMethod "SubPartition method"
  1105. SubPartitionOpt "SubPartition option"
  1106. SubPartitionNumOpt "SubPartition NUM option"
  1107. TableAliasRefList "table alias reference list"
  1108. TableAsName "table alias name"
  1109. TableAsNameOpt "table alias name optional"
  1110. TableElement "table definition element"
  1111. TableElementList "table definition element list"
  1112. TableElementListOpt "table definition element list optional"
  1113. TableFactor "table factor"
  1114. TableLock "Table name and lock type"
  1115. TableLockList "Table lock list"
  1116. TableName "Table name"
  1117. TableNameOptWild "Table name with optional wildcard"
  1118. TableNameList "Table name list"
  1119. TableNameListOpt "Table name list opt"
  1120. TableNameListOpt2 "Optional table name list with a preceding TABLE"
  1121. TableOption "create table option"
  1122. TableOptionList "create table option list"
  1123. TableRef "table reference"
  1124. TableRefs "table references"
  1125. TableSampleOpt "table sample clause optional"
  1126. TableSampleMethodOpt "table sample method optional"
  1127. TableSampleUnitOpt "table sample unit optional"
  1128. TableToTable "rename table to table"
  1129. TableToTableList "rename table to table by list"
  1130. TextStringList "text string list"
  1131. TimeUnit "Time unit for 'DATE_ADD', 'DATE_SUB', 'ADDDATE', 'SUBDATE', 'EXTRACT'"
  1132. TimestampUnit "Time unit for 'TIMESTAMPADD' and 'TIMESTAMPDIFF'"
  1133. TimestampBound "Timestamp bound for start transaction with timestamp mode"
  1134. LockType "Table locks type"
  1135. TransactionChar "Transaction characteristic"
  1136. TransactionChars "Transaction characteristic list"
  1137. TrimDirection "Trim string direction"
  1138. SetOprOpt "Union/Except/Intersect Option(empty/ALL/DISTINCT)"
  1139. Username "Username"
  1140. UsernameList "UsernameList"
  1141. UserSpec "Username and auth option"
  1142. UserSpecList "Username and auth option list"
  1143. UserVariableList "User defined variable name list"
  1144. UserToUser "rename user to user"
  1145. UserToUserList "rename user to user by list"
  1146. UsingRoles "UsingRoles is role option for SHOW GRANT"
  1147. Values "values"
  1148. ValuesList "values list"
  1149. ValuesOpt "values optional"
  1150. ValuesStmtList "VALUES statement field list"
  1151. VariableAssignment "set variable value"
  1152. VariableAssignmentList "set variable value list"
  1153. ViewAlgorithm "view algorithm"
  1154. ViewCheckOption "view check option"
  1155. ViewDefiner "view definer"
  1156. ViewName "view name"
  1157. ViewFieldList "create view statement field list"
  1158. ViewSQLSecurity "view sql security"
  1159. WhereClause "WHERE clause"
  1160. WhereClauseOptional "Optional WHERE clause"
  1161. WhenClause "When clause"
  1162. WhenClauseList "When clause list"
  1163. WithClustered "With Clustered Index Enabled"
  1164. WithClause "With Clause"
  1165. WithList "With list"
  1166. WithReadLockOpt "With Read Lock opt"
  1167. WithGrantOptionOpt "With Grant Option opt"
  1168. WithValidation "with validation"
  1169. WithValidationOpt "optional with validation"
  1170. Writeable "Table writeable status"
  1171. ElseOpt "Optional else clause"
  1172. Type "Types"
  1173. OptExistingWindowName "Optional existing WINDOW name"
  1174. OptFromFirstLast "Optional FROM FIRST/LAST"
  1175. OptLLDefault "Optional LEAD/LAG default"
  1176. OptLeadLagInfo "Optional LEAD/LAG info"
  1177. OptNullTreatment "Optional NULL treatment"
  1178. OptPartitionClause "Optional PARTITION clause"
  1179. OptWild "Optional Wildcard"
  1180. OptWindowOrderByClause "Optional ORDER BY clause in WINDOW"
  1181. OptWindowFrameClause "Optional FRAME clause in WINDOW"
  1182. OptWindowingClause "Optional OVER clause"
  1183. WindowingClause "OVER clause"
  1184. WindowClauseOptional "Optional WINDOW clause"
  1185. WindowDefinitionList "WINDOW definition list"
  1186. WindowDefinition "WINDOW definition"
  1187. WindowFrameUnits "WINDOW frame units"
  1188. WindowFrameBetween "WINDOW frame between"
  1189. WindowFrameBound "WINDOW frame bound"
  1190. WindowFrameExtent "WINDOW frame extent"
  1191. WindowFrameStart "WINDOW frame start"
  1192. WindowName "WINDOW name"
  1193. WindowNameOrSpec "WINDOW name or spec"
  1194. WindowSpec "WINDOW spec"
  1195. WindowSpecDetails "WINDOW spec details"
  1196. BetweenOrNotOp "Between predicate"
  1197. IsOrNotOp "Is predicate"
  1198. InOrNotOp "In predicate"
  1199. LikeOrNotOp "Like predicate"
  1200. RegexpOrNotOp "Regexp predicate"
  1201. NumericType "Numeric types"
  1202. IntegerType "Integer Types types"
  1203. BooleanType "Boolean Types types"
  1204. FixedPointType "Exact value types"
  1205. FloatingPointType "Approximate value types"
  1206. BitValueType "bit value types"
  1207. StringType "String types"
  1208. BlobType "Blob types"
  1209. TextType "Text types"
  1210. DateAndTimeType "Date and Time types"
  1211. OptFieldLen "Field length or empty"
  1212. FieldLen "Field length"
  1213. FieldOpts "Field type definition option list"
  1214. FieldOpt "Field type definition option"
  1215. FloatOpt "Floating-point type option"
  1216. Precision "Floating-point precision option"
  1217. OptBinary "Optional BINARY"
  1218. OptBinMod "Optional BINARY mode"
  1219. OptCharsetWithOptBinary "Optional BINARY or ASCII or UNICODE or BYTE"
  1220. IgnoreLines "Ignore num(int) lines"
  1221. Int64Num "a number that can be safely converted to int64"
  1222. NUM "A number"
  1223. NumList "Some numbers"
  1224. LengthNum "Field length num(uint64)"
  1225. SignedNum "Signed num(int64)"
  1226. TableOptimizerHints "Table level optimizer hints"
  1227. TableOptimizerHintsOpt "Table level optimizer hints option"
  1228. EnforcedOrNot "{ENFORCED|NOT ENFORCED}"
  1229. EnforcedOrNotOpt "Optional {ENFORCED|NOT ENFORCED}"
  1230. EnforcedOrNotOrNotNullOpt "{[ENFORCED|NOT ENFORCED|NOT NULL]}"
  1231. Match "[MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]"
  1232. MatchOpt "optional MATCH clause"
  1233. MaxMinutesOpt "MAX_MINUTES num(int)"
  1234. MaxIndexNumOpt "MAX_IDXNUM clause"
  1235. PerTable "Max index number PER_TABLE"
  1236. PerDB "Max index number PER_DB"
  1237. BRIETables "List of tables or databases for BRIE statements"
  1238. DBNameList "List of database names"
  1239. BRIEOption "Single BRIE option"
  1240. BRIEOptions "List of BRIE options"
  1241. BRIEIntegerOptionName "Name of a BRIE option which takes an integer as input"
  1242. BRIEBooleanOptionName "Name of a BRIE option which takes a boolean as input"
  1243. BRIEStringOptionName "Name of a BRIE option which takes a string as input"
  1244. BRIEKeywordOptionName "Name of a BRIE option which takes a case-insensitive string as input"
  1245. PlacementCount "Placement rules count option"
  1246. PlacementLabelConstraints "Placement rules label constraints option"
  1247. PlacementRole "Placement rules role option"
  1248. PlacementOptions "Placement rules options"
  1249. PlacementSpec "Placement rules specification"
  1250. PlacementSpecList "Placement rules specifications"
  1251. %type <ident>
  1252. AsOpt "AS or EmptyString"
  1253. KeyOrIndex "{KEY|INDEX}"
  1254. ColumnKeywordOpt "Column keyword or empty"
  1255. PrimaryOpt "Optional primary keyword"
  1256. NowSym "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP"
  1257. NowSymFunc "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP/NOW"
  1258. DefaultKwdOpt "optional DEFAULT keyword"
  1259. DatabaseSym "DATABASE or SCHEMA"
  1260. ExplainSym "EXPLAIN or DESCRIBE or DESC"
  1261. RegexpSym "REGEXP or RLIKE"
  1262. IntoOpt "INTO or EmptyString"
  1263. ValueSym "Value or Values"
  1264. NotSym "Not token"
  1265. Char "{CHAR|CHARACTER}"
  1266. NChar "{NCHAR|NATIONAL CHARACTER|NATIONAL CHAR}"
  1267. Varchar "{VARCHAR|VARCHARACTER|CHARACTER VARYING|CHAR VARYING}"
  1268. NVarchar "{NATIONAL VARCHAR|NATIONAL VARCHARACTER|NVARCHAR|NCHAR VARCHAR|NATIONAL CHARACTER VARYING|NATIONAL CHAR VARYING|NCHAR VARYING}"
  1269. Year "{YEAR|SQL_TSI_YEAR}"
  1270. DeallocateSym "Deallocate or drop"
  1271. OuterOpt "optional OUTER clause"
  1272. CrossOpt "Cross join option"
  1273. TablesTerminalSym "{TABLE|TABLES}"
  1274. IsolationLevel "Isolation level"
  1275. ShowIndexKwd "Show index/indexs/key keyword"
  1276. DistinctKwd "DISTINCT/DISTINCTROW keyword"
  1277. FromOrIn "From or In"
  1278. OptTable "Optional table keyword"
  1279. OptInteger "Optional Integer keyword"
  1280. CharsetKw "charset or charater set"
  1281. CommaOpt "optional comma"
  1282. logAnd "logical and operator"
  1283. logOr "logical or operator"
  1284. LinearOpt "linear or empty"
  1285. FieldsOrColumns "Fields or columns"
  1286. StorageMedia "{DISK|MEMORY|DEFAULT}"
  1287. EncryptionOpt "Encryption option 'Y' or 'N'"
  1288. FirstOrNext "FIRST or NEXT"
  1289. RowOrRows "ROW or ROWS"
  1290. %type <ident>
  1291. ODBCDateTimeType "ODBC type keywords for date and time literals"
  1292. Identifier "identifier or unreserved keyword"
  1293. NotKeywordToken "Tokens not mysql keyword but treated specially"
  1294. UnReservedKeyword "MySQL unreserved keywords"
  1295. TiDBKeyword "TiDB added keywords"
  1296. FunctionNameConflict "Built-in function call names which are conflict with keywords"
  1297. FunctionNameOptionalBraces "Function with optional braces, all of them are reserved keywords."
  1298. FunctionNameDatetimePrecision "Function with optional datetime precision, all of them are reserved keywords."
  1299. FunctionNameDateArith "Date arith function call names (date_add or date_sub)"
  1300. FunctionNameDateArithMultiForms "Date arith function call names (adddate or subdate)"
  1301. VariableName "A simple Identifier like xx or the xx.xx form"
  1302. ConfigItemName "A config item like aa or aa.bb or aa.bb-cc.dd"
  1303. AuthString "Password string value"
  1304. CharsetName "Character set name"
  1305. CollationName "Collation name"
  1306. ColumnFormat "Column format"
  1307. DBName "Database Name"
  1308. ExplainFormatType "explain format type"
  1309. FieldAsName "Field alias name"
  1310. FieldAsNameOpt "Field alias name opt"
  1311. FieldTerminator "Field terminator"
  1312. FlashbackToNewName "Flashback to new name"
  1313. HashString "Hashed string"
  1314. LikeEscapeOpt "like escape option"
  1315. LinesTerminated "Lines terminated by"
  1316. OptCharset "Optional Character setting"
  1317. OptCollate "Optional Collate setting"
  1318. PasswordOpt "Password option"
  1319. RoleNameString "role name string"
  1320. ShowDatabaseNameOpt "Show tables/columns statement database name option"
  1321. Starting "Starting by"
  1322. StringName "string literal or identifier"
  1323. StringNameOrBRIEOptionKeyword "string literal or identifier or keyword used for BRIE options"
  1324. Symbol "Constraint Symbol"
  1325. TextString "text string item"
  1326. %precedence empty
  1327. %precedence lowerThanSelectOpt
  1328. %precedence sqlBufferResult
  1329. %precedence sqlBigResult
  1330. %precedence sqlSmallResult
  1331. %precedence sqlCache sqlNoCache
  1332. %precedence lowerThanIntervalKeyword
  1333. %precedence interval
  1334. %precedence next
  1335. %precedence lowerThanValueKeyword
  1336. %precedence value
  1337. %precedence lowerThanStringLitToken
  1338. %precedence stringLit
  1339. %precedence lowerThanSetKeyword
  1340. %precedence set
  1341. %precedence selectKwd
  1342. %precedence lowerThanSelectStmt
  1343. %precedence lowerThanInsertValues
  1344. %precedence insertValues
  1345. %precedence lowerThanCreateTableSelect
  1346. %precedence createTableSelect
  1347. %precedence lowerThanCharsetKwd
  1348. %precedence charsetKwd
  1349. %precedence lowerThanKey
  1350. %precedence key
  1351. %precedence lowerThanLocal
  1352. %precedence local
  1353. %precedence lowerThanRemove
  1354. %precedence remove
  1355. %precedence lowerThenOrder
  1356. %precedence order
  1357. %precedence lowerThanFunction
  1358. %precedence function
  1359. /* A dummy token to force the priority of TableRef production in a join. */
  1360. %left tableRefPriority
  1361. %left join straightJoin inner cross left right full natural
  1362. %precedence lowerThanOn
  1363. %precedence on using
  1364. %right assignmentEq
  1365. %left pipes or pipesAsOr
  1366. %left xor
  1367. %left andand and
  1368. %left between
  1369. %precedence lowerThanEq
  1370. %left eq ge le neq neqSynonym '>' '<' is like in
  1371. %left '|'
  1372. %left '&'
  1373. %left rsh lsh
  1374. %left '-' '+'
  1375. %left '*' '/' '%' div mod
  1376. %left '^'
  1377. %left '~' neg
  1378. %precedence lowerThanNot
  1379. %right not not2
  1380. %right collate
  1381. %right encryption
  1382. %left labels
  1383. %precedence lowerThanParenthese
  1384. %precedence '(' ')'
  1385. %precedence higherThanParenthese
  1386. %precedence quick
  1387. %precedence escape
  1388. %precedence lowerThanComma
  1389. %precedence ','
  1390. %precedence higherThanComma
  1391. %start Start
  1392. %%
  1393. Start:
  1394. StatementList
  1395. /**************************************AlterTableStmt***************************************
  1396. * See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
  1397. *******************************************************************************************/
  1398. AlterTableStmt:
  1399. "ALTER" IgnoreOptional "TABLE" TableName AlterTableSpecListOpt AlterTablePartitionOpt
  1400. {
  1401. specs := $5.([]*ast.AlterTableSpec)
  1402. if $6 != nil {
  1403. specs = append(specs, $6.(*ast.AlterTableSpec))
  1404. }
  1405. $$ = &ast.AlterTableStmt{
  1406. Table: $4.(*ast.TableName),
  1407. Specs: specs,
  1408. }
  1409. }
  1410. | "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList AnalyzeOptionListOpt
  1411. {
  1412. $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, PartitionNames: $7.([]model.CIStr), AnalyzeOpts: $8.([]ast.AnalyzeOpt)}
  1413. }
  1414. | "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt
  1415. {
  1416. $$ = &ast.AnalyzeTableStmt{
  1417. TableNames: []*ast.TableName{$4.(*ast.TableName)},
  1418. PartitionNames: $7.([]model.CIStr),
  1419. IndexNames: $9.([]model.CIStr),
  1420. IndexFlag: true,
  1421. AnalyzeOpts: $10.([]ast.AnalyzeOpt),
  1422. }
  1423. }
  1424. PlacementRole:
  1425. "ROLE" "=" "FOLLOWER"
  1426. {
  1427. $$ = ast.PlacementRoleFollower
  1428. }
  1429. | "ROLE" "=" "LEADER"
  1430. {
  1431. $$ = ast.PlacementRoleLeader
  1432. }
  1433. | "ROLE" "=" "LEARNER"
  1434. {
  1435. $$ = ast.PlacementRoleLearner
  1436. }
  1437. | "ROLE" "=" "VOTER"
  1438. {
  1439. $$ = ast.PlacementRoleVoter
  1440. }
  1441. PlacementCount:
  1442. "REPLICAS" "=" LengthNum
  1443. {
  1444. cnt := $3.(uint64)
  1445. if cnt == 0 {
  1446. yylex.AppendError(yylex.Errorf("Invalid placement option REPLICAS, it is not allowed to be 0"))
  1447. return 1
  1448. }
  1449. $$ = cnt
  1450. }
  1451. PlacementLabelConstraints:
  1452. "CONSTRAINTS" "=" stringLit
  1453. {
  1454. $$ = $3
  1455. }
  1456. PlacementOptions:
  1457. PlacementCount
  1458. {
  1459. $$ = &ast.PlacementSpec{
  1460. Replicas: $1.(uint64),
  1461. }
  1462. }
  1463. | PlacementLabelConstraints
  1464. {
  1465. $$ = &ast.PlacementSpec{
  1466. Constraints: $1.(string),
  1467. }
  1468. }
  1469. | PlacementRole
  1470. {
  1471. $$ = &ast.PlacementSpec{
  1472. Role: $1.(ast.PlacementRole),
  1473. }
  1474. }
  1475. | PlacementOptions PlacementCount
  1476. {
  1477. spec := $1.(*ast.PlacementSpec)
  1478. if spec.Replicas != 0 {
  1479. yylex.AppendError(yylex.Errorf("Duplicate placement option REPLICAS"))
  1480. return 1
  1481. }
  1482. spec.Replicas = $2.(uint64)
  1483. $$ = spec
  1484. }
  1485. | PlacementOptions PlacementLabelConstraints
  1486. {
  1487. spec := $1.(*ast.PlacementSpec)
  1488. if len(spec.Constraints) > 0 {
  1489. yylex.AppendError(yylex.Errorf("Duplicate placement option CONSTRAINTS"))
  1490. return 1
  1491. }
  1492. spec.Constraints = $2.(string)
  1493. $$ = spec
  1494. }
  1495. | PlacementOptions PlacementRole
  1496. {
  1497. spec := $1.(*ast.PlacementSpec)
  1498. if spec.Role != ast.PlacementRoleNone {
  1499. yylex.AppendError(yylex.Errorf("Duplicate placement option ROLE"))
  1500. return 1
  1501. }
  1502. spec.Role = $2.(ast.PlacementRole)
  1503. $$ = spec
  1504. }
  1505. PlacementSpec:
  1506. "ADD" "PLACEMENT" "POLICY" PlacementOptions
  1507. {
  1508. spec := $4.(*ast.PlacementSpec)
  1509. spec.Tp = ast.PlacementAdd
  1510. $$ = spec
  1511. }
  1512. | "ALTER" "PLACEMENT" "POLICY" PlacementOptions
  1513. {
  1514. spec := $4.(*ast.PlacementSpec)
  1515. spec.Tp = ast.PlacementAlter
  1516. $$ = spec
  1517. }
  1518. | "DROP" "PLACEMENT" "POLICY" PlacementRole
  1519. {
  1520. spec := &ast.PlacementSpec{Role: $4.(ast.PlacementRole)}
  1521. spec.Tp = ast.PlacementDrop
  1522. $$ = spec
  1523. }
  1524. PlacementSpecList:
  1525. PlacementSpec
  1526. {
  1527. $$ = []*ast.PlacementSpec{$1.(*ast.PlacementSpec)}
  1528. }
  1529. | PlacementSpecList ',' PlacementSpec
  1530. {
  1531. $$ = append($1.([]*ast.PlacementSpec), $3.(*ast.PlacementSpec))
  1532. }
  1533. AlterTablePartitionOpt:
  1534. PartitionOpt
  1535. {
  1536. if $1 != nil {
  1537. $$ = &ast.AlterTableSpec{
  1538. Tp: ast.AlterTablePartition,
  1539. Partition: $1.(*ast.PartitionOptions),
  1540. }
  1541. } else {
  1542. $$ = nil
  1543. }
  1544. }
  1545. | "REMOVE" "PARTITIONING"
  1546. {
  1547. $$ = &ast.AlterTableSpec{
  1548. Tp: ast.AlterTableRemovePartitioning,
  1549. }
  1550. }
  1551. | "REORGANIZE" "PARTITION" NoWriteToBinLogAliasOpt ReorganizePartitionRuleOpt
  1552. {
  1553. ret := $4.(*ast.AlterTableSpec)
  1554. ret.NoWriteToBinlog = $3.(bool)
  1555. $$ = ret
  1556. }
  1557. LocationLabelList:
  1558. {
  1559. $$ = []string{}
  1560. }
  1561. | "LOCATION" "LABELS" StringList
  1562. {
  1563. $$ = $3
  1564. }
  1565. AlterTableSpec:
  1566. TableOptionList %prec higherThanComma
  1567. {
  1568. $$ = &ast.AlterTableSpec{
  1569. Tp: ast.AlterTableOption,
  1570. Options: $1.([]*ast.TableOption),
  1571. }
  1572. }
  1573. | "SET" "TIFLASH" "REPLICA" LengthNum LocationLabelList
  1574. {
  1575. tiflashReplicaSpec := &ast.TiFlashReplicaSpec{
  1576. Count: $4.(uint64),
  1577. Labels: $5.([]string),
  1578. }
  1579. $$ = &ast.AlterTableSpec{
  1580. Tp: ast.AlterTableSetTiFlashReplica,
  1581. TiFlashReplica: tiflashReplicaSpec,
  1582. }
  1583. }
  1584. | "CONVERT" "TO" CharsetKw CharsetName OptCollate
  1585. {
  1586. op := &ast.AlterTableSpec{
  1587. Tp: ast.AlterTableOption,
  1588. Options: []*ast.TableOption{{Tp: ast.TableOptionCharset, StrValue: $4,
  1589. UintValue: ast.TableOptionCharsetWithConvertTo}},
  1590. }
  1591. if $5 != "" {
  1592. op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5})
  1593. }
  1594. $$ = op
  1595. }
  1596. | "CONVERT" "TO" CharsetKw "DEFAULT" OptCollate
  1597. {
  1598. op := &ast.AlterTableSpec{
  1599. Tp: ast.AlterTableOption,
  1600. Options: []*ast.TableOption{{Tp: ast.TableOptionCharset, Default: true,
  1601. UintValue: ast.TableOptionCharsetWithConvertTo}},
  1602. }
  1603. if $5 != "" {
  1604. op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5})
  1605. }
  1606. $$ = op
  1607. }
  1608. | "ADD" ColumnKeywordOpt IfNotExists ColumnDef ColumnPosition
  1609. {
  1610. $$ = &ast.AlterTableSpec{
  1611. IfNotExists: $3.(bool),
  1612. Tp: ast.AlterTableAddColumns,
  1613. NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)},
  1614. Position: $5.(*ast.ColumnPosition),
  1615. }
  1616. }
  1617. | "ADD" ColumnKeywordOpt IfNotExists '(' TableElementList ')'
  1618. {
  1619. tes := $5.([]interface{})
  1620. var columnDefs []*ast.ColumnDef
  1621. var constraints []*ast.Constraint
  1622. for _, te := range tes {
  1623. switch te := te.(type) {
  1624. case *ast.ColumnDef:
  1625. columnDefs = append(columnDefs, te)
  1626. case *ast.Constraint:
  1627. constraints = append(constraints, te)
  1628. }
  1629. }
  1630. $$ = &ast.AlterTableSpec{
  1631. IfNotExists: $3.(bool),
  1632. Tp: ast.AlterTableAddColumns,
  1633. NewColumns: columnDefs,
  1634. NewConstraints: constraints,
  1635. }
  1636. }
  1637. | "ADD" Constraint
  1638. {
  1639. constraint := $2.(*ast.Constraint)
  1640. $$ = &ast.AlterTableSpec{
  1641. Tp: ast.AlterTableAddConstraint,
  1642. Constraint: constraint,
  1643. }
  1644. }
  1645. | "ADD" "PARTITION" IfNotExists NoWriteToBinLogAliasOpt PartitionDefinitionListOpt
  1646. {
  1647. var defs []*ast.PartitionDefinition
  1648. if $5 != nil {
  1649. defs = $5.([]*ast.PartitionDefinition)
  1650. }
  1651. noWriteToBinlog := $4.(bool)
  1652. if noWriteToBinlog {
  1653. yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now."))
  1654. parser.lastErrorAsWarn()
  1655. }
  1656. $$ = &ast.AlterTableSpec{
  1657. IfNotExists: $3.(bool),
  1658. NoWriteToBinlog: noWriteToBinlog,
  1659. Tp: ast.AlterTableAddPartitions,
  1660. PartDefinitions: defs,
  1661. }
  1662. }
  1663. | "ADD" "PARTITION" IfNotExists NoWriteToBinLogAliasOpt "PARTITIONS" NUM
  1664. {
  1665. noWriteToBinlog := $4.(bool)
  1666. if noWriteToBinlog {
  1667. yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now."))
  1668. parser.lastErrorAsWarn()
  1669. }
  1670. $$ = &ast.AlterTableSpec{
  1671. IfNotExists: $3.(bool),
  1672. NoWriteToBinlog: noWriteToBinlog,
  1673. Tp: ast.AlterTableAddPartitions,
  1674. Num: getUint64FromNUM($6),
  1675. }
  1676. }
  1677. | "ADD" "STATS_EXTENDED" IfNotExists Identifier StatsType '(' ColumnNameList ')'
  1678. {
  1679. statsSpec := &ast.StatisticsSpec{
  1680. StatsName: $4,
  1681. StatsType: $5.(uint8),
  1682. Columns: $7.([]*ast.ColumnName),
  1683. }
  1684. $$ = &ast.AlterTableSpec{
  1685. Tp: ast.AlterTableAddStatistics,
  1686. IfNotExists: $3.(bool),
  1687. Statistics: statsSpec,
  1688. }
  1689. }
  1690. | "ALTER" "PARTITION" Identifier PlacementSpecList %prec lowerThanComma
  1691. {
  1692. $$ = &ast.AlterTableSpec{
  1693. Tp: ast.AlterTableAlterPartition,
  1694. PartitionNames: []model.CIStr{model.NewCIStr($3)},
  1695. PlacementSpecs: $4.([]*ast.PlacementSpec),
  1696. }
  1697. }
  1698. | "CHECK" "PARTITION" AllOrPartitionNameList
  1699. {
  1700. yylex.AppendError(yylex.Errorf("The CHECK PARTITIONING clause is parsed but not implement yet."))
  1701. parser.lastErrorAsWarn()
  1702. ret := &ast.AlterTableSpec{
  1703. Tp: ast.AlterTableCheckPartitions,
  1704. }
  1705. if $3 == nil {
  1706. ret.OnAllPartitions = true
  1707. } else {
  1708. ret.PartitionNames = $3.([]model.CIStr)
  1709. }
  1710. $$ = ret
  1711. }
  1712. | "COALESCE" "PARTITION" NoWriteToBinLogAliasOpt NUM
  1713. {
  1714. noWriteToBinlog := $3.(bool)
  1715. if noWriteToBinlog {
  1716. yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now."))
  1717. parser.lastErrorAsWarn()
  1718. }
  1719. $$ = &ast.AlterTableSpec{
  1720. Tp: ast.AlterTableCoalescePartitions,
  1721. NoWriteToBinlog: noWriteToBinlog,
  1722. Num: getUint64FromNUM($4),
  1723. }
  1724. }
  1725. | "DROP" ColumnKeywordOpt IfExists ColumnName RestrictOrCascadeOpt
  1726. {
  1727. $$ = &ast.AlterTableSpec{
  1728. IfExists: $3.(bool),
  1729. Tp: ast.AlterTableDropColumn,
  1730. OldColumnName: $4.(*ast.ColumnName),
  1731. }
  1732. }
  1733. | "DROP" "PRIMARY" "KEY"
  1734. {
  1735. $$ = &ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey}
  1736. }
  1737. | "DROP" "PARTITION" IfExists PartitionNameList %prec lowerThanComma
  1738. {
  1739. $$ = &ast.AlterTableSpec{
  1740. IfExists: $3.(bool),
  1741. Tp: ast.AlterTableDropPartition,
  1742. PartitionNames: $4.([]model.CIStr),
  1743. }
  1744. }
  1745. | "DROP" "STATS_EXTENDED" IfExists Identifier
  1746. {
  1747. statsSpec := &ast.StatisticsSpec{
  1748. StatsName: $4,
  1749. }
  1750. $$ = &ast.AlterTableSpec{
  1751. Tp: ast.AlterTableDropStatistics,
  1752. IfExists: $3.(bool),
  1753. Statistics: statsSpec,
  1754. }
  1755. }
  1756. | "EXCHANGE" "PARTITION" Identifier "WITH" "TABLE" TableName WithValidationOpt
  1757. {
  1758. $$ = &ast.AlterTableSpec{
  1759. Tp: ast.AlterTableExchangePartition,
  1760. PartitionNames: []model.CIStr{model.NewCIStr($3)},
  1761. NewTable: $6.(*ast.TableName),
  1762. WithValidation: $7.(bool),
  1763. }
  1764. }
  1765. | "TRUNCATE" "PARTITION" AllOrPartitionNameList
  1766. {
  1767. ret := &ast.AlterTableSpec{
  1768. Tp: ast.AlterTableTruncatePartition,
  1769. }
  1770. if $3 == nil {
  1771. ret.OnAllPartitions = true
  1772. } else {
  1773. ret.PartitionNames = $3.([]model.CIStr)
  1774. }
  1775. $$ = ret
  1776. }
  1777. | "OPTIMIZE" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList
  1778. {
  1779. ret := &ast.AlterTableSpec{
  1780. NoWriteToBinlog: $3.(bool),
  1781. Tp: ast.AlterTableOptimizePartition,
  1782. }
  1783. if $4 == nil {
  1784. ret.OnAllPartitions = true
  1785. } else {
  1786. ret.PartitionNames = $4.([]model.CIStr)
  1787. }
  1788. $$ = ret
  1789. }
  1790. | "REPAIR" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList
  1791. {
  1792. ret := &ast.AlterTableSpec{
  1793. NoWriteToBinlog: $3.(bool),
  1794. Tp: ast.AlterTableRepairPartition,
  1795. }
  1796. if $4 == nil {
  1797. ret.OnAllPartitions = true
  1798. } else {
  1799. ret.PartitionNames = $4.([]model.CIStr)
  1800. }
  1801. $$ = ret
  1802. }
  1803. | "IMPORT" "PARTITION" AllOrPartitionNameList "TABLESPACE"
  1804. {
  1805. ret := &ast.AlterTableSpec{
  1806. Tp: ast.AlterTableImportPartitionTablespace,
  1807. }
  1808. if $3 == nil {
  1809. ret.OnAllPartitions = true
  1810. } else {
  1811. ret.PartitionNames = $3.([]model.CIStr)
  1812. }
  1813. $$ = ret
  1814. yylex.AppendError(yylex.Errorf("The IMPORT PARTITION TABLESPACE clause is parsed but ignored by all storage engines."))
  1815. parser.lastErrorAsWarn()
  1816. }
  1817. | "DISCARD" "PARTITION" AllOrPartitionNameList "TABLESPACE"
  1818. {
  1819. ret := &ast.AlterTableSpec{
  1820. Tp: ast.AlterTableDiscardPartitionTablespace,
  1821. }
  1822. if $3 == nil {
  1823. ret.OnAllPartitions = true
  1824. } else {
  1825. ret.PartitionNames = $3.([]model.CIStr)
  1826. }
  1827. $$ = ret
  1828. yylex.AppendError(yylex.Errorf("The DISCARD PARTITION TABLESPACE clause is parsed but ignored by all storage engines."))
  1829. parser.lastErrorAsWarn()
  1830. }
  1831. | "IMPORT" "TABLESPACE"
  1832. {
  1833. ret := &ast.AlterTableSpec{
  1834. Tp: ast.AlterTableImportTablespace,
  1835. }
  1836. $$ = ret
  1837. yylex.AppendError(yylex.Errorf("The IMPORT TABLESPACE clause is parsed but ignored by all storage engines."))
  1838. parser.lastErrorAsWarn()
  1839. }
  1840. | "DISCARD" "TABLESPACE"
  1841. {
  1842. ret := &ast.AlterTableSpec{
  1843. Tp: ast.AlterTableDiscardTablespace,
  1844. }
  1845. $$ = ret
  1846. yylex.AppendError(yylex.Errorf("The DISCARD TABLESPACE clause is parsed but ignored by all storage engines."))
  1847. parser.lastErrorAsWarn()
  1848. }
  1849. | "REBUILD" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList
  1850. {
  1851. ret := &ast.AlterTableSpec{
  1852. Tp: ast.AlterTableRebuildPartition,
  1853. NoWriteToBinlog: $3.(bool),
  1854. }
  1855. if $4 == nil {
  1856. ret.OnAllPartitions = true
  1857. } else {
  1858. ret.PartitionNames = $4.([]model.CIStr)
  1859. }
  1860. $$ = ret
  1861. }
  1862. | "DROP" KeyOrIndex IfExists Identifier
  1863. {
  1864. $$ = &ast.AlterTableSpec{
  1865. IfExists: $3.(bool),
  1866. Tp: ast.AlterTableDropIndex,
  1867. Name: $4,
  1868. }
  1869. }
  1870. | "DROP" "FOREIGN" "KEY" IfExists Symbol
  1871. {
  1872. $$ = &ast.AlterTableSpec{
  1873. IfExists: $4.(bool),
  1874. Tp: ast.AlterTableDropForeignKey,
  1875. Name: $5,
  1876. }
  1877. }
  1878. | "ORDER" "BY" AlterOrderList %prec lowerThenOrder
  1879. {
  1880. $$ = &ast.AlterTableSpec{
  1881. Tp: ast.AlterTableOrderByColumns,
  1882. OrderByList: $3.([]*ast.AlterOrderItem),
  1883. }
  1884. }
  1885. | "DISABLE" "KEYS"
  1886. {
  1887. $$ = &ast.AlterTableSpec{
  1888. Tp: ast.AlterTableDisableKeys,
  1889. }
  1890. }
  1891. | "ENABLE" "KEYS"
  1892. {
  1893. $$ = &ast.AlterTableSpec{
  1894. Tp: ast.AlterTableEnableKeys,
  1895. }
  1896. }
  1897. | "MODIFY" ColumnKeywordOpt IfExists ColumnDef ColumnPosition
  1898. {
  1899. $$ = &ast.AlterTableSpec{
  1900. IfExists: $3.(bool),
  1901. Tp: ast.AlterTableModifyColumn,
  1902. NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)},
  1903. Position: $5.(*ast.ColumnPosition),
  1904. }
  1905. }
  1906. | "CHANGE" ColumnKeywordOpt IfExists ColumnName ColumnDef ColumnPosition
  1907. {
  1908. $$ = &ast.AlterTableSpec{
  1909. IfExists: $3.(bool),
  1910. Tp: ast.AlterTableChangeColumn,
  1911. OldColumnName: $4.(*ast.ColumnName),
  1912. NewColumns: []*ast.ColumnDef{$5.(*ast.ColumnDef)},
  1913. Position: $6.(*ast.ColumnPosition),
  1914. }
  1915. }
  1916. | "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" SignedLiteral
  1917. {
  1918. option := &ast.ColumnOption{Expr: $6}
  1919. colDef := &ast.ColumnDef{
  1920. Name: $3.(*ast.ColumnName),
  1921. Options: []*ast.ColumnOption{option},
  1922. }
  1923. $$ = &ast.AlterTableSpec{
  1924. Tp: ast.AlterTableAlterColumn,
  1925. NewColumns: []*ast.ColumnDef{colDef},
  1926. }
  1927. }
  1928. | "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" '(' Expression ')'
  1929. {
  1930. option := &ast.ColumnOption{Expr: $7}
  1931. colDef := &ast.ColumnDef{
  1932. Name: $3.(*ast.ColumnName),
  1933. Options: []*ast.ColumnOption{option},
  1934. }
  1935. $$ = &ast.AlterTableSpec{
  1936. Tp: ast.AlterTableAlterColumn,
  1937. NewColumns: []*ast.ColumnDef{colDef},
  1938. }
  1939. }
  1940. | "ALTER" ColumnKeywordOpt ColumnName "DROP" "DEFAULT"
  1941. {
  1942. colDef := &ast.ColumnDef{
  1943. Name: $3.(*ast.ColumnName),
  1944. }
  1945. $$ = &ast.AlterTableSpec{
  1946. Tp: ast.AlterTableAlterColumn,
  1947. NewColumns: []*ast.ColumnDef{colDef},
  1948. }
  1949. }
  1950. | "RENAME" "COLUMN" Identifier "TO" Identifier
  1951. {
  1952. oldColName := &ast.ColumnName{Name: model.NewCIStr($3)}
  1953. newColName := &ast.ColumnName{Name: model.NewCIStr($5)}
  1954. $$ = &ast.AlterTableSpec{
  1955. Tp: ast.AlterTableRenameColumn,
  1956. OldColumnName: oldColName,
  1957. NewColumnName: newColName,
  1958. }
  1959. }
  1960. | "RENAME" "TO" TableName
  1961. {
  1962. $$ = &ast.AlterTableSpec{
  1963. Tp: ast.AlterTableRenameTable,
  1964. NewTable: $3.(*ast.TableName),
  1965. }
  1966. }
  1967. | "RENAME" EqOpt TableName
  1968. {
  1969. $$ = &ast.AlterTableSpec{
  1970. Tp: ast.AlterTableRenameTable,
  1971. NewTable: $3.(*ast.TableName),
  1972. }
  1973. }
  1974. | "RENAME" "AS" TableName
  1975. {
  1976. $$ = &ast.AlterTableSpec{
  1977. Tp: ast.AlterTableRenameTable,
  1978. NewTable: $3.(*ast.TableName),
  1979. }
  1980. }
  1981. | "RENAME" KeyOrIndex Identifier "TO" Identifier
  1982. {
  1983. $$ = &ast.AlterTableSpec{
  1984. Tp: ast.AlterTableRenameIndex,
  1985. FromKey: model.NewCIStr($3),
  1986. ToKey: model.NewCIStr($5),
  1987. }
  1988. }
  1989. | LockClause
  1990. {
  1991. $$ = &ast.AlterTableSpec{
  1992. Tp: ast.AlterTableLock,
  1993. LockType: $1.(ast.LockType),
  1994. }
  1995. }
  1996. | Writeable
  1997. {
  1998. $$ = &ast.AlterTableSpec{
  1999. Tp: ast.AlterTableWriteable,
  2000. Writeable: $1.(bool),
  2001. }
  2002. }
  2003. | AlgorithmClause
  2004. {
  2005. // Parse it and ignore it. Just for compatibility.
  2006. $$ = &ast.AlterTableSpec{
  2007. Tp: ast.AlterTableAlgorithm,
  2008. Algorithm: $1.(ast.AlgorithmType),
  2009. }
  2010. }
  2011. | "FORCE"
  2012. {
  2013. // Parse it and ignore it. Just for compatibility.
  2014. $$ = &ast.AlterTableSpec{
  2015. Tp: ast.AlterTableForce,
  2016. }
  2017. }
  2018. | "WITH" "VALIDATION"
  2019. {
  2020. // Parse it and ignore it. Just for compatibility.
  2021. $$ = &ast.AlterTableSpec{
  2022. Tp: ast.AlterTableWithValidation,
  2023. }
  2024. }
  2025. | "WITHOUT" "VALIDATION"
  2026. {
  2027. // Parse it and ignore it. Just for compatibility.
  2028. $$ = &ast.AlterTableSpec{
  2029. Tp: ast.AlterTableWithoutValidation,
  2030. }
  2031. }
  2032. // Added in MySQL 8.0.13, see: https://dev.mysql.com/doc/refman/8.0/en/keywords.html for details
  2033. | "SECONDARY_LOAD"
  2034. {
  2035. // Parse it and ignore it. Just for compatibility.
  2036. $$ = &ast.AlterTableSpec{
  2037. Tp: ast.AlterTableSecondaryLoad,
  2038. }
  2039. yylex.AppendError(yylex.Errorf("The SECONDARY_LOAD clause is parsed but not implement yet."))
  2040. parser.lastErrorAsWarn()
  2041. }
  2042. // Added in MySQL 8.0.13, see: https://dev.mysql.com/doc/refman/8.0/en/keywords.html for details
  2043. | "SECONDARY_UNLOAD"
  2044. {
  2045. // Parse it and ignore it. Just for compatibility.
  2046. $$ = &ast.AlterTableSpec{
  2047. Tp: ast.AlterTableSecondaryUnload,
  2048. }
  2049. yylex.AppendError(yylex.Errorf("The SECONDARY_UNLOAD VALIDATION clause is parsed but not implement yet."))
  2050. parser.lastErrorAsWarn()
  2051. }
  2052. | "ALTER" CheckConstraintKeyword Identifier EnforcedOrNot
  2053. {
  2054. c := &ast.Constraint{
  2055. Name: $3,
  2056. Enforced: $4.(bool),
  2057. }
  2058. $$ = &ast.AlterTableSpec{
  2059. Tp: ast.AlterTableAlterCheck,
  2060. Constraint: c,
  2061. }
  2062. }
  2063. | "DROP" CheckConstraintKeyword Identifier
  2064. {
  2065. // Parse it and ignore it. Just for compatibility.
  2066. c := &ast.Constraint{
  2067. Name: $3,
  2068. }
  2069. $$ = &ast.AlterTableSpec{
  2070. Tp: ast.AlterTableDropCheck,
  2071. Constraint: c,
  2072. }
  2073. }
  2074. | "ALTER" "INDEX" Identifier IndexInvisible
  2075. {
  2076. $$ = &ast.AlterTableSpec{
  2077. Tp: ast.AlterTableIndexInvisible,
  2078. IndexName: model.NewCIStr($3),
  2079. Visibility: $4.(ast.IndexVisibility),
  2080. }
  2081. }
  2082. | PlacementSpecList %prec lowerThanComma
  2083. {
  2084. $$ = &ast.AlterTableSpec{
  2085. Tp: ast.AlterTablePlacement,
  2086. PlacementSpecs: $1.([]*ast.PlacementSpec),
  2087. }
  2088. }
  2089. ReorganizePartitionRuleOpt:
  2090. /* empty */ %prec lowerThanRemove
  2091. {
  2092. ret := &ast.AlterTableSpec{
  2093. Tp: ast.AlterTableReorganizePartition,
  2094. OnAllPartitions: true,
  2095. }
  2096. $$ = ret
  2097. }
  2098. | PartitionNameList "INTO" '(' PartitionDefinitionList ')'
  2099. {
  2100. ret := &ast.AlterTableSpec{
  2101. Tp: ast.AlterTableReorganizePartition,
  2102. PartitionNames: $1.([]model.CIStr),
  2103. PartDefinitions: $4.([]*ast.PartitionDefinition),
  2104. }
  2105. $$ = ret
  2106. }
  2107. AllOrPartitionNameList:
  2108. "ALL"
  2109. {
  2110. $$ = nil
  2111. }
  2112. | PartitionNameList %prec lowerThanComma
  2113. WithValidationOpt:
  2114. {
  2115. $$ = true
  2116. }
  2117. | WithValidation
  2118. WithValidation:
  2119. "WITH" "VALIDATION"
  2120. {
  2121. $$ = true
  2122. }
  2123. | "WITHOUT" "VALIDATION"
  2124. {
  2125. $$ = false
  2126. }
  2127. WithClustered:
  2128. "CLUSTERED"
  2129. {
  2130. $$ = model.PrimaryKeyTypeClustered
  2131. }
  2132. | "NONCLUSTERED"
  2133. {
  2134. $$ = model.PrimaryKeyTypeNonClustered
  2135. }
  2136. AlgorithmClause:
  2137. "ALGORITHM" EqOpt "DEFAULT"
  2138. {
  2139. $$ = ast.AlgorithmTypeDefault
  2140. }
  2141. | "ALGORITHM" EqOpt "COPY"
  2142. {
  2143. $$ = ast.AlgorithmTypeCopy
  2144. }
  2145. | "ALGORITHM" EqOpt "INPLACE"
  2146. {
  2147. $$ = ast.AlgorithmTypeInplace
  2148. }
  2149. | "ALGORITHM" EqOpt "INSTANT"
  2150. {
  2151. $$ = ast.AlgorithmTypeInstant
  2152. }
  2153. | "ALGORITHM" EqOpt identifier
  2154. {
  2155. yylex.AppendError(ErrUnknownAlterAlgorithm.GenWithStackByArgs($1))
  2156. return 1
  2157. }
  2158. LockClause:
  2159. "LOCK" EqOpt "DEFAULT"
  2160. {
  2161. $$ = ast.LockTypeDefault
  2162. }
  2163. | "LOCK" EqOpt Identifier
  2164. {
  2165. id := strings.ToUpper($3)
  2166. if id == "NONE" {
  2167. $$ = ast.LockTypeNone
  2168. } else if id == "SHARED" {
  2169. $$ = ast.LockTypeShared
  2170. } else if id == "EXCLUSIVE" {
  2171. $$ = ast.LockTypeExclusive
  2172. } else {
  2173. yylex.AppendError(ErrUnknownAlterLock.GenWithStackByArgs($3))
  2174. return 1
  2175. }
  2176. }
  2177. Writeable:
  2178. "READ" "WRITE"
  2179. {
  2180. $$ = true
  2181. }
  2182. | "READ" "ONLY"
  2183. {
  2184. $$ = false
  2185. }
  2186. KeyOrIndex:
  2187. "KEY"
  2188. | "INDEX"
  2189. KeyOrIndexOpt:
  2190. {}
  2191. | KeyOrIndex
  2192. ColumnKeywordOpt:
  2193. {}
  2194. | "COLUMN"
  2195. ColumnPosition:
  2196. {
  2197. $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionNone}
  2198. }
  2199. | "FIRST"
  2200. {
  2201. $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionFirst}
  2202. }
  2203. | "AFTER" ColumnName
  2204. {
  2205. $$ = &ast.ColumnPosition{
  2206. Tp: ast.ColumnPositionAfter,
  2207. RelativeColumn: $2.(*ast.ColumnName),
  2208. }
  2209. }
  2210. AlterTableSpecListOpt:
  2211. /* empty */
  2212. {
  2213. $$ = make([]*ast.AlterTableSpec, 0, 1)
  2214. }
  2215. | AlterTableSpecList
  2216. AlterTableSpecList:
  2217. AlterTableSpec
  2218. {
  2219. $$ = []*ast.AlterTableSpec{$1.(*ast.AlterTableSpec)}
  2220. }
  2221. | AlterTableSpecList ',' AlterTableSpec
  2222. {
  2223. $$ = append($1.([]*ast.AlterTableSpec), $3.(*ast.AlterTableSpec))
  2224. }
  2225. PartitionNameList:
  2226. Identifier
  2227. {
  2228. $$ = []model.CIStr{model.NewCIStr($1)}
  2229. }
  2230. | PartitionNameList ',' Identifier
  2231. {
  2232. $$ = append($1.([]model.CIStr), model.NewCIStr($3))
  2233. }
  2234. ConstraintKeywordOpt:
  2235. {
  2236. $$ = nil
  2237. }
  2238. | "CONSTRAINT"
  2239. {
  2240. $$ = nil
  2241. }
  2242. | "CONSTRAINT" Symbol
  2243. {
  2244. $$ = $2
  2245. }
  2246. Symbol:
  2247. Identifier
  2248. /**************************************RenameTableStmt***************************************
  2249. * See http://dev.mysql.com/doc/refman/5.7/en/rename-table.html
  2250. *
  2251. * RENAME TABLE
  2252. * tbl_name TO new_tbl_name
  2253. * [, tbl_name2 TO new_tbl_name2] ...
  2254. *******************************************************************************************/
  2255. RenameTableStmt:
  2256. "RENAME" "TABLE" TableToTableList
  2257. {
  2258. $$ = &ast.RenameTableStmt{
  2259. TableToTables: $3.([]*ast.TableToTable),
  2260. }
  2261. }
  2262. TableToTableList:
  2263. TableToTable
  2264. {
  2265. $$ = []*ast.TableToTable{$1.(*ast.TableToTable)}
  2266. }
  2267. | TableToTableList ',' TableToTable
  2268. {
  2269. $$ = append($1.([]*ast.TableToTable), $3.(*ast.TableToTable))
  2270. }
  2271. TableToTable:
  2272. TableName "TO" TableName
  2273. {
  2274. $$ = &ast.TableToTable{
  2275. OldTable: $1.(*ast.TableName),
  2276. NewTable: $3.(*ast.TableName),
  2277. }
  2278. }
  2279. /**************************************RenameUserStmt***************************************
  2280. * See https://dev.mysql.com/doc/refman/5.7/en/rename-user.html
  2281. *
  2282. * RENAME USER
  2283. * old_user TO new_user
  2284. * [, old_user2 TO new_user2] ...
  2285. *******************************************************************************************/
  2286. RenameUserStmt:
  2287. "RENAME" "USER" UserToUserList
  2288. {
  2289. $$ = &ast.RenameUserStmt{
  2290. UserToUsers: $3.([]*ast.UserToUser),
  2291. }
  2292. }
  2293. UserToUserList:
  2294. UserToUser
  2295. {
  2296. $$ = []*ast.UserToUser{$1.(*ast.UserToUser)}
  2297. }
  2298. | UserToUserList ',' UserToUser
  2299. {
  2300. $$ = append($1.([]*ast.UserToUser), $3.(*ast.UserToUser))
  2301. }
  2302. UserToUser:
  2303. Username "TO" Username
  2304. {
  2305. $$ = &ast.UserToUser{
  2306. OldUser: $1.(*auth.UserIdentity),
  2307. NewUser: $3.(*auth.UserIdentity),
  2308. }
  2309. }
  2310. /*******************************************************************
  2311. *
  2312. * Recover Table Statement
  2313. *
  2314. * Example:
  2315. * RECOVER TABLE t1;
  2316. * RECOVER TABLE BY JOB 100;
  2317. *
  2318. *******************************************************************/
  2319. RecoverTableStmt:
  2320. "RECOVER" "TABLE" "BY" "JOB" Int64Num
  2321. {
  2322. $$ = &ast.RecoverTableStmt{
  2323. JobID: $5.(int64),
  2324. }
  2325. }
  2326. | "RECOVER" "TABLE" TableName
  2327. {
  2328. $$ = &ast.RecoverTableStmt{
  2329. Table: $3.(*ast.TableName),
  2330. }
  2331. }
  2332. | "RECOVER" "TABLE" TableName Int64Num
  2333. {
  2334. $$ = &ast.RecoverTableStmt{
  2335. Table: $3.(*ast.TableName),
  2336. JobNum: $4.(int64),
  2337. }
  2338. }
  2339. /*******************************************************************
  2340. *
  2341. * Flush Back Table Statement
  2342. *
  2343. * Example:
  2344. *
  2345. *******************************************************************/
  2346. FlashbackTableStmt:
  2347. "FLASHBACK" "TABLE" TableName FlashbackToNewName
  2348. {
  2349. $$ = &ast.FlashBackTableStmt{
  2350. Table: $3.(*ast.TableName),
  2351. NewName: $4,
  2352. }
  2353. }
  2354. FlashbackToNewName:
  2355. {
  2356. $$ = ""
  2357. }
  2358. | "TO" Identifier
  2359. {
  2360. $$ = $2
  2361. }
  2362. /*******************************************************************
  2363. *
  2364. * Split index region statement
  2365. *
  2366. * Example:
  2367. * SPLIT TABLE table_name INDEX index_name BY (val1...),(val2...)...
  2368. *
  2369. *******************************************************************/
  2370. SplitRegionStmt:
  2371. "SPLIT" SplitSyntaxOption "TABLE" TableName PartitionNameListOpt SplitOption
  2372. {
  2373. $$ = &ast.SplitRegionStmt{
  2374. SplitSyntaxOpt: $2.(*ast.SplitSyntaxOption),
  2375. Table: $4.(*ast.TableName),
  2376. PartitionNames: $5.([]model.CIStr),
  2377. SplitOpt: $6.(*ast.SplitOption),
  2378. }
  2379. }
  2380. | "SPLIT" SplitSyntaxOption "TABLE" TableName PartitionNameListOpt "INDEX" Identifier SplitOption
  2381. {
  2382. $$ = &ast.SplitRegionStmt{
  2383. SplitSyntaxOpt: $2.(*ast.SplitSyntaxOption),
  2384. Table: $4.(*ast.TableName),
  2385. PartitionNames: $5.([]model.CIStr),
  2386. IndexName: model.NewCIStr($7),
  2387. SplitOpt: $8.(*ast.SplitOption),
  2388. }
  2389. }
  2390. SplitOption:
  2391. "BETWEEN" RowValue "AND" RowValue "REGIONS" Int64Num
  2392. {
  2393. $$ = &ast.SplitOption{
  2394. Lower: $2.([]ast.ExprNode),
  2395. Upper: $4.([]ast.ExprNode),
  2396. Num: $6.(int64),
  2397. }
  2398. }
  2399. | "BY" ValuesList
  2400. {
  2401. $$ = &ast.SplitOption{
  2402. ValueLists: $2.([][]ast.ExprNode),
  2403. }
  2404. }
  2405. SplitSyntaxOption:
  2406. /* empty */
  2407. {
  2408. $$ = &ast.SplitSyntaxOption{}
  2409. }
  2410. | "REGION" "FOR"
  2411. {
  2412. $$ = &ast.SplitSyntaxOption{
  2413. HasRegionFor: true,
  2414. }
  2415. }
  2416. | "PARTITION"
  2417. {
  2418. $$ = &ast.SplitSyntaxOption{
  2419. HasPartition: true,
  2420. }
  2421. }
  2422. | "REGION" "FOR" "PARTITION"
  2423. {
  2424. $$ = &ast.SplitSyntaxOption{
  2425. HasRegionFor: true,
  2426. HasPartition: true,
  2427. }
  2428. }
  2429. AnalyzeTableStmt:
  2430. "ANALYZE" "TABLE" TableNameList AnalyzeOptionListOpt
  2431. {
  2432. $$ = &ast.AnalyzeTableStmt{TableNames: $3.([]*ast.TableName), AnalyzeOpts: $4.([]ast.AnalyzeOpt)}
  2433. }
  2434. | "ANALYZE" "TABLE" TableName "INDEX" IndexNameList AnalyzeOptionListOpt
  2435. {
  2436. $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, IndexNames: $5.([]model.CIStr), IndexFlag: true, AnalyzeOpts: $6.([]ast.AnalyzeOpt)}
  2437. }
  2438. | "ANALYZE" "INCREMENTAL" "TABLE" TableName "INDEX" IndexNameList AnalyzeOptionListOpt
  2439. {
  2440. $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, IndexNames: $6.([]model.CIStr), IndexFlag: true, Incremental: true, AnalyzeOpts: $7.([]ast.AnalyzeOpt)}
  2441. }
  2442. | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList AnalyzeOptionListOpt
  2443. {
  2444. $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, PartitionNames: $5.([]model.CIStr), AnalyzeOpts: $6.([]ast.AnalyzeOpt)}
  2445. }
  2446. | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt
  2447. {
  2448. $$ = &ast.AnalyzeTableStmt{
  2449. TableNames: []*ast.TableName{$3.(*ast.TableName)},
  2450. PartitionNames: $5.([]model.CIStr),
  2451. IndexNames: $7.([]model.CIStr),
  2452. IndexFlag: true,
  2453. AnalyzeOpts: $8.([]ast.AnalyzeOpt),
  2454. }
  2455. }
  2456. | "ANALYZE" "INCREMENTAL" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt
  2457. {
  2458. $$ = &ast.AnalyzeTableStmt{
  2459. TableNames: []*ast.TableName{$4.(*ast.TableName)},
  2460. PartitionNames: $6.([]model.CIStr),
  2461. IndexNames: $8.([]model.CIStr),
  2462. IndexFlag: true,
  2463. Incremental: true,
  2464. AnalyzeOpts: $9.([]ast.AnalyzeOpt),
  2465. }
  2466. }
  2467. | "ANALYZE" "TABLE" TableName "UPDATE" "HISTOGRAM" "ON" ColumnNameList AnalyzeOptionListOpt
  2468. {
  2469. $$ = &ast.AnalyzeTableStmt{
  2470. TableNames: []*ast.TableName{$3.(*ast.TableName)},
  2471. ColumnNames: $7.([]*ast.ColumnName),
  2472. AnalyzeOpts: $8.([]ast.AnalyzeOpt),
  2473. HistogramOperation: ast.HistogramOperationUpdate,
  2474. }
  2475. }
  2476. | "ANALYZE" "TABLE" TableName "DROP" "HISTOGRAM" "ON" ColumnNameList
  2477. {
  2478. $$ = &ast.AnalyzeTableStmt{
  2479. TableNames: []*ast.TableName{$3.(*ast.TableName)},
  2480. ColumnNames: $7.([]*ast.ColumnName),
  2481. HistogramOperation: ast.HistogramOperationDrop,
  2482. }
  2483. }
  2484. AnalyzeOptionListOpt:
  2485. {
  2486. $$ = []ast.AnalyzeOpt{}
  2487. }
  2488. | "WITH" AnalyzeOptionList
  2489. {
  2490. $$ = $2.([]ast.AnalyzeOpt)
  2491. }
  2492. AnalyzeOptionList:
  2493. AnalyzeOption
  2494. {
  2495. $$ = []ast.AnalyzeOpt{$1.(ast.AnalyzeOpt)}
  2496. }
  2497. | AnalyzeOptionList ',' AnalyzeOption
  2498. {
  2499. $$ = append($1.([]ast.AnalyzeOpt), $3.(ast.AnalyzeOpt))
  2500. }
  2501. AnalyzeOption:
  2502. NUM "BUCKETS"
  2503. {
  2504. $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumBuckets, Value: getUint64FromNUM($1)}
  2505. }
  2506. | NUM "TOPN"
  2507. {
  2508. $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumTopN, Value: getUint64FromNUM($1)}
  2509. }
  2510. | NUM "CMSKETCH" "DEPTH"
  2511. {
  2512. $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptCMSketchDepth, Value: getUint64FromNUM($1)}
  2513. }
  2514. | NUM "CMSKETCH" "WIDTH"
  2515. {
  2516. $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptCMSketchWidth, Value: getUint64FromNUM($1)}
  2517. }
  2518. | NUM "SAMPLES"
  2519. {
  2520. $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumSamples, Value: getUint64FromNUM($1)}
  2521. }
  2522. /*******************************************************************************************/
  2523. Assignment:
  2524. ColumnName eq ExprOrDefault
  2525. {
  2526. $$ = &ast.Assignment{Column: $1.(*ast.ColumnName), Expr: $3}
  2527. }
  2528. AssignmentList:
  2529. Assignment
  2530. {
  2531. $$ = []*ast.Assignment{$1.(*ast.Assignment)}
  2532. }
  2533. | AssignmentList ',' Assignment
  2534. {
  2535. $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment))
  2536. }
  2537. AssignmentListOpt:
  2538. /* EMPTY */
  2539. {
  2540. $$ = []*ast.Assignment{}
  2541. }
  2542. | AssignmentList
  2543. BeginTransactionStmt:
  2544. "BEGIN"
  2545. {
  2546. $$ = &ast.BeginStmt{}
  2547. }
  2548. | "BEGIN" "PESSIMISTIC"
  2549. {
  2550. $$ = &ast.BeginStmt{
  2551. Mode: ast.Pessimistic,
  2552. }
  2553. }
  2554. | "BEGIN" "OPTIMISTIC"
  2555. {
  2556. $$ = &ast.BeginStmt{
  2557. Mode: ast.Optimistic,
  2558. }
  2559. }
  2560. | "START" "TRANSACTION"
  2561. {
  2562. $$ = &ast.BeginStmt{}
  2563. }
  2564. | "START" "TRANSACTION" "READ" "WRITE"
  2565. {
  2566. $$ = &ast.BeginStmt{}
  2567. }
  2568. | "START" "TRANSACTION" "WITH" "CONSISTENT" "SNAPSHOT"
  2569. {
  2570. $$ = &ast.BeginStmt{}
  2571. }
  2572. | "START" "TRANSACTION" "READ" "ONLY"
  2573. {
  2574. $$ = &ast.BeginStmt{
  2575. ReadOnly: true,
  2576. }
  2577. }
  2578. | "START" "TRANSACTION" "READ" "ONLY" "WITH" "TIMESTAMP" "BOUND" TimestampBound
  2579. {
  2580. $$ = &ast.BeginStmt{
  2581. ReadOnly: true,
  2582. Bound: $8.(*ast.TimestampBound),
  2583. }
  2584. }
  2585. | "START" "TRANSACTION" "WITH" "CAUSAL" "CONSISTENCY" "ONLY"
  2586. {
  2587. $$ = &ast.BeginStmt{
  2588. CausalConsistencyOnly: true,
  2589. }
  2590. }
  2591. TimestampBound:
  2592. "STRONG"
  2593. {
  2594. $$ = &ast.TimestampBound{
  2595. Mode: ast.TimestampBoundStrong,
  2596. }
  2597. }
  2598. | "READ" "TIMESTAMP" Expression
  2599. {
  2600. $$ = &ast.TimestampBound{
  2601. Mode: ast.TimestampBoundReadTimestamp,
  2602. Timestamp: $3.(ast.ExprNode),
  2603. }
  2604. }
  2605. | "MIN" "READ" "TIMESTAMP" Expression
  2606. {
  2607. $$ = &ast.TimestampBound{
  2608. Mode: ast.TimestampBoundMinReadTimestamp,
  2609. Timestamp: $4.(ast.ExprNode),
  2610. }
  2611. }
  2612. | "MAX" "STALENESS" Expression
  2613. {
  2614. $$ = &ast.TimestampBound{
  2615. Mode: ast.TimestampBoundMaxStaleness,
  2616. Timestamp: $3.(ast.ExprNode),
  2617. }
  2618. }
  2619. | "EXACT" "STALENESS" Expression
  2620. {
  2621. $$ = &ast.TimestampBound{
  2622. Mode: ast.TimestampBoundExactStaleness,
  2623. Timestamp: $3.(ast.ExprNode),
  2624. }
  2625. }
  2626. BinlogStmt:
  2627. "BINLOG" stringLit
  2628. {
  2629. $$ = &ast.BinlogStmt{Str: $2}
  2630. }
  2631. ColumnDefList:
  2632. ColumnDef
  2633. {
  2634. $$ = []*ast.ColumnDef{$1.(*ast.ColumnDef)}
  2635. }
  2636. | ColumnDefList ',' ColumnDef
  2637. {
  2638. $$ = append($1.([]*ast.ColumnDef), $3.(*ast.ColumnDef))
  2639. }
  2640. ColumnDef:
  2641. ColumnName Type ColumnOptionListOpt
  2642. {
  2643. colDef := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType), Options: $3.([]*ast.ColumnOption)}
  2644. if !colDef.Validate() {
  2645. yylex.AppendError(yylex.Errorf("Invalid column definition"))
  2646. return 1
  2647. }
  2648. $$ = colDef
  2649. }
  2650. | ColumnName "SERIAL" ColumnOptionListOpt
  2651. {
  2652. // TODO: check flen 0
  2653. tp := types.NewFieldType(mysql.TypeLonglong)
  2654. options := []*ast.ColumnOption{{Tp: ast.ColumnOptionNotNull}, {Tp: ast.ColumnOptionAutoIncrement}, {Tp: ast.ColumnOptionUniqKey}}
  2655. options = append(options, $3.([]*ast.ColumnOption)...)
  2656. tp.Flag |= mysql.UnsignedFlag
  2657. colDef := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: tp, Options: options}
  2658. if !colDef.Validate() {
  2659. yylex.AppendError(yylex.Errorf("Invalid column definition"))
  2660. return 1
  2661. }
  2662. $$ = colDef
  2663. }
  2664. ColumnName:
  2665. Identifier
  2666. {
  2667. $$ = &ast.ColumnName{Name: model.NewCIStr($1)}
  2668. }
  2669. | Identifier '.' Identifier
  2670. {
  2671. $$ = &ast.ColumnName{Table: model.NewCIStr($1), Name: model.NewCIStr($3)}
  2672. }
  2673. | Identifier '.' Identifier '.' Identifier
  2674. {
  2675. $$ = &ast.ColumnName{Schema: model.NewCIStr($1), Table: model.NewCIStr($3), Name: model.NewCIStr($5)}
  2676. }
  2677. ColumnNameList:
  2678. ColumnName
  2679. {
  2680. $$ = []*ast.ColumnName{$1.(*ast.ColumnName)}
  2681. }
  2682. | ColumnNameList ',' ColumnName
  2683. {
  2684. $$ = append($1.([]*ast.ColumnName), $3.(*ast.ColumnName))
  2685. }
  2686. ColumnNameListOpt:
  2687. /* EMPTY */
  2688. {
  2689. $$ = []*ast.ColumnName{}
  2690. }
  2691. | ColumnNameList
  2692. IdentListWithParenOpt:
  2693. /* EMPTY */
  2694. {
  2695. $$ = []model.CIStr{}
  2696. }
  2697. | '(' IdentList ')'
  2698. {
  2699. $$ = $2
  2700. }
  2701. IdentList:
  2702. Identifier
  2703. {
  2704. $$ = []model.CIStr{model.NewCIStr($1)}
  2705. }
  2706. | IdentList ',' Identifier
  2707. {
  2708. $$ = append($1.([]model.CIStr), model.NewCIStr($3))
  2709. }
  2710. ColumnNameOrUserVarListOpt:
  2711. /* EMPTY */
  2712. {
  2713. $$ = []*ast.ColumnNameOrUserVar{}
  2714. }
  2715. | ColumnNameOrUserVariableList
  2716. ColumnNameOrUserVariableList:
  2717. ColumnNameOrUserVariable
  2718. {
  2719. $$ = []*ast.ColumnNameOrUserVar{$1.(*ast.ColumnNameOrUserVar)}
  2720. }
  2721. | ColumnNameOrUserVariableList ',' ColumnNameOrUserVariable
  2722. {
  2723. $$ = append($1.([]*ast.ColumnNameOrUserVar), $3.(*ast.ColumnNameOrUserVar))
  2724. }
  2725. ColumnNameOrUserVariable:
  2726. ColumnName
  2727. {
  2728. $$ = &ast.ColumnNameOrUserVar{ColumnName: $1.(*ast.ColumnName)}
  2729. }
  2730. | UserVariable
  2731. {
  2732. $$ = &ast.ColumnNameOrUserVar{UserVar: $1.(*ast.VariableExpr)}
  2733. }
  2734. ColumnNameOrUserVarListOptWithBrackets:
  2735. /* EMPTY */
  2736. {
  2737. $$ = []*ast.ColumnNameOrUserVar{}
  2738. }
  2739. | '(' ColumnNameOrUserVarListOpt ')'
  2740. {
  2741. $$ = $2.([]*ast.ColumnNameOrUserVar)
  2742. }
  2743. CommitStmt:
  2744. "COMMIT"
  2745. {
  2746. $$ = &ast.CommitStmt{}
  2747. }
  2748. | "COMMIT" CompletionTypeWithinTransaction
  2749. {
  2750. $$ = &ast.CommitStmt{CompletionType: $2.(ast.CompletionType)}
  2751. }
  2752. PrimaryOpt:
  2753. {}
  2754. | "PRIMARY"
  2755. NotSym:
  2756. not
  2757. | not2
  2758. {
  2759. $$ = "NOT"
  2760. }
  2761. EnforcedOrNot:
  2762. "ENFORCED"
  2763. {
  2764. $$ = true
  2765. }
  2766. | NotSym "ENFORCED"
  2767. {
  2768. $$ = false
  2769. }
  2770. EnforcedOrNotOpt:
  2771. %prec lowerThanNot
  2772. {
  2773. $$ = true
  2774. }
  2775. | EnforcedOrNot
  2776. EnforcedOrNotOrNotNullOpt:
  2777. // This branch is needed to workaround the need of a lookahead of 2 for the grammar:
  2778. //
  2779. // { [NOT] NULL | CHECK(...) [NOT] ENFORCED } ...
  2780. NotSym "NULL"
  2781. {
  2782. $$ = 0
  2783. }
  2784. | EnforcedOrNotOpt
  2785. {
  2786. if $1.(bool) {
  2787. $$ = 1
  2788. } else {
  2789. $$ = 2
  2790. }
  2791. }
  2792. ColumnOption:
  2793. NotSym "NULL"
  2794. {
  2795. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNotNull}
  2796. }
  2797. | "NULL"
  2798. {
  2799. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNull}
  2800. }
  2801. | "AUTO_INCREMENT"
  2802. {
  2803. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoIncrement}
  2804. }
  2805. | PrimaryOpt "KEY"
  2806. {
  2807. // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY
  2808. // can also be specified as just KEY when given in a column definition.
  2809. // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
  2810. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey}
  2811. }
  2812. | PrimaryOpt "KEY" WithClustered
  2813. {
  2814. // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY
  2815. // can also be specified as just KEY when given in a column definition.
  2816. // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
  2817. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey, PrimaryKeyTp: $3.(model.PrimaryKeyType)}
  2818. }
  2819. | "UNIQUE" %prec lowerThanKey
  2820. {
  2821. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey}
  2822. }
  2823. | "UNIQUE" "KEY"
  2824. {
  2825. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey}
  2826. }
  2827. | "DEFAULT" DefaultValueExpr
  2828. {
  2829. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionDefaultValue, Expr: $2}
  2830. }
  2831. | "SERIAL" "DEFAULT" "VALUE"
  2832. {
  2833. $$ = []*ast.ColumnOption{{Tp: ast.ColumnOptionNotNull}, {Tp: ast.ColumnOptionAutoIncrement}, {Tp: ast.ColumnOptionUniqKey}}
  2834. }
  2835. | "ON" "UPDATE" NowSymOptionFraction
  2836. {
  2837. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionOnUpdate, Expr: $3}
  2838. }
  2839. | "COMMENT" stringLit
  2840. {
  2841. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionComment, Expr: ast.NewValueExpr($2, "", "")}
  2842. }
  2843. | ConstraintKeywordOpt "CHECK" '(' Expression ')' EnforcedOrNotOrNotNullOpt
  2844. {
  2845. // See https://dev.mysql.com/doc/refman/5.7/en/create-table.html
  2846. // The CHECK clause is parsed but ignored by all storage engines.
  2847. // See the branch named `EnforcedOrNotOrNotNullOpt`.
  2848. optionCheck := &ast.ColumnOption{
  2849. Tp: ast.ColumnOptionCheck,
  2850. Expr: $4,
  2851. Enforced: true,
  2852. }
  2853. // Keep the column type check constraint name.
  2854. if $1 != nil {
  2855. optionCheck.ConstraintName = $1.(string)
  2856. }
  2857. switch $6.(int) {
  2858. case 0:
  2859. $$ = []*ast.ColumnOption{optionCheck, {Tp: ast.ColumnOptionNotNull}}
  2860. case 1:
  2861. optionCheck.Enforced = true
  2862. $$ = optionCheck
  2863. case 2:
  2864. optionCheck.Enforced = false
  2865. $$ = optionCheck
  2866. default:
  2867. }
  2868. }
  2869. | GeneratedAlways "AS" '(' Expression ')' VirtualOrStored
  2870. {
  2871. startOffset := parser.startOffset(&yyS[yypt-2])
  2872. endOffset := parser.endOffset(&yyS[yypt-1])
  2873. expr := $4
  2874. expr.SetText(parser.src[startOffset:endOffset])
  2875. $$ = &ast.ColumnOption{
  2876. Tp: ast.ColumnOptionGenerated,
  2877. Expr: expr,
  2878. Stored: $6.(bool),
  2879. }
  2880. }
  2881. | ReferDef
  2882. {
  2883. $$ = &ast.ColumnOption{
  2884. Tp: ast.ColumnOptionReference,
  2885. Refer: $1.(*ast.ReferenceDef),
  2886. }
  2887. }
  2888. | "COLLATE" CollationName
  2889. {
  2890. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionCollate, StrValue: $2}
  2891. }
  2892. | "COLUMN_FORMAT" ColumnFormat
  2893. {
  2894. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionColumnFormat, StrValue: $2}
  2895. }
  2896. | "STORAGE" StorageMedia
  2897. {
  2898. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionStorage, StrValue: $2}
  2899. yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines."))
  2900. parser.lastErrorAsWarn()
  2901. }
  2902. | "AUTO_RANDOM" OptFieldLen
  2903. {
  2904. $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoRandom, AutoRandomBitLength: $2.(int)}
  2905. }
  2906. StorageMedia:
  2907. "DEFAULT"
  2908. | "DISK"
  2909. | "MEMORY"
  2910. ColumnFormat:
  2911. "DEFAULT"
  2912. {
  2913. $$ = "DEFAULT"
  2914. }
  2915. | "FIXED"
  2916. {
  2917. $$ = "FIXED"
  2918. }
  2919. | "DYNAMIC"
  2920. {
  2921. $$ = "DYNAMIC"
  2922. }
  2923. GeneratedAlways:
  2924. | "GENERATED" "ALWAYS"
  2925. VirtualOrStored:
  2926. {
  2927. $$ = false
  2928. }
  2929. | "VIRTUAL"
  2930. {
  2931. $$ = false
  2932. }
  2933. | "STORED"
  2934. {
  2935. $$ = true
  2936. }
  2937. ColumnOptionList:
  2938. ColumnOption
  2939. {
  2940. if columnOption, ok := $1.(*ast.ColumnOption); ok {
  2941. $$ = []*ast.ColumnOption{columnOption}
  2942. } else {
  2943. $$ = $1
  2944. }
  2945. }
  2946. | ColumnOptionList ColumnOption
  2947. {
  2948. if columnOption, ok := $2.(*ast.ColumnOption); ok {
  2949. $$ = append($1.([]*ast.ColumnOption), columnOption)
  2950. } else {
  2951. $$ = append($1.([]*ast.ColumnOption), $2.([]*ast.ColumnOption)...)
  2952. }
  2953. }
  2954. ColumnOptionListOpt:
  2955. {
  2956. $$ = []*ast.ColumnOption{}
  2957. }
  2958. | ColumnOptionList
  2959. ConstraintElem:
  2960. "PRIMARY" "KEY" IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList
  2961. {
  2962. c := &ast.Constraint{
  2963. Tp: ast.ConstraintPrimaryKey,
  2964. Keys: $5.([]*ast.IndexPartSpecification),
  2965. Name: $3.([]interface{})[0].(*ast.NullString).String,
  2966. IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty,
  2967. }
  2968. if $7 != nil {
  2969. c.Option = $7.(*ast.IndexOption)
  2970. }
  2971. if indexType := $3.([]interface{})[1]; indexType != nil {
  2972. if c.Option == nil {
  2973. c.Option = &ast.IndexOption{}
  2974. }
  2975. c.Option.Tp = indexType.(model.IndexType)
  2976. }
  2977. $$ = c
  2978. }
  2979. | "FULLTEXT" KeyOrIndexOpt IndexName '(' IndexPartSpecificationList ')' IndexOptionList
  2980. {
  2981. c := &ast.Constraint{
  2982. Tp: ast.ConstraintFulltext,
  2983. Keys: $5.([]*ast.IndexPartSpecification),
  2984. Name: $3.(*ast.NullString).String,
  2985. IsEmptyIndex: $3.(*ast.NullString).Empty,
  2986. }
  2987. if $7 != nil {
  2988. c.Option = $7.(*ast.IndexOption)
  2989. }
  2990. $$ = c
  2991. }
  2992. | KeyOrIndex IfNotExists IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList
  2993. {
  2994. c := &ast.Constraint{
  2995. IfNotExists: $2.(bool),
  2996. Tp: ast.ConstraintIndex,
  2997. Keys: $5.([]*ast.IndexPartSpecification),
  2998. Name: $3.([]interface{})[0].(*ast.NullString).String,
  2999. IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty,
  3000. }
  3001. if $7 != nil {
  3002. c.Option = $7.(*ast.IndexOption)
  3003. }
  3004. if indexType := $3.([]interface{})[1]; indexType != nil {
  3005. if c.Option == nil {
  3006. c.Option = &ast.IndexOption{}
  3007. }
  3008. c.Option.Tp = indexType.(model.IndexType)
  3009. }
  3010. $$ = c
  3011. }
  3012. | "UNIQUE" KeyOrIndexOpt IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList
  3013. {
  3014. c := &ast.Constraint{
  3015. Tp: ast.ConstraintUniq,
  3016. Keys: $5.([]*ast.IndexPartSpecification),
  3017. Name: $3.([]interface{})[0].(*ast.NullString).String,
  3018. IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty,
  3019. }
  3020. if $7 != nil {
  3021. c.Option = $7.(*ast.IndexOption)
  3022. }
  3023. if indexType := $3.([]interface{})[1]; indexType != nil {
  3024. if c.Option == nil {
  3025. c.Option = &ast.IndexOption{}
  3026. }
  3027. c.Option.Tp = indexType.(model.IndexType)
  3028. }
  3029. $$ = c
  3030. }
  3031. | "FOREIGN" "KEY" IfNotExists IndexName '(' IndexPartSpecificationList ')' ReferDef
  3032. {
  3033. $$ = &ast.Constraint{
  3034. IfNotExists: $3.(bool),
  3035. Tp: ast.ConstraintForeignKey,
  3036. Keys: $6.([]*ast.IndexPartSpecification),
  3037. Name: $4.(*ast.NullString).String,
  3038. Refer: $8.(*ast.ReferenceDef),
  3039. IsEmptyIndex: $4.(*ast.NullString).Empty,
  3040. }
  3041. }
  3042. | "CHECK" '(' Expression ')' EnforcedOrNotOpt
  3043. {
  3044. $$ = &ast.Constraint{
  3045. Tp: ast.ConstraintCheck,
  3046. Expr: $3.(ast.ExprNode),
  3047. Enforced: $5.(bool),
  3048. }
  3049. }
  3050. Match:
  3051. "MATCH" "FULL"
  3052. {
  3053. $$ = ast.MatchFull
  3054. }
  3055. | "MATCH" "PARTIAL"
  3056. {
  3057. $$ = ast.MatchPartial
  3058. }
  3059. | "MATCH" "SIMPLE"
  3060. {
  3061. $$ = ast.MatchSimple
  3062. }
  3063. MatchOpt:
  3064. {
  3065. $$ = ast.MatchNone
  3066. }
  3067. | Match
  3068. {
  3069. $$ = $1
  3070. yylex.AppendError(yylex.Errorf("The MATCH clause is parsed but ignored by all storage engines."))
  3071. parser.lastErrorAsWarn()
  3072. }
  3073. ReferDef:
  3074. "REFERENCES" TableName IndexPartSpecificationListOpt MatchOpt OnDeleteUpdateOpt
  3075. {
  3076. onDeleteUpdate := $5.([2]interface{})
  3077. $$ = &ast.ReferenceDef{
  3078. Table: $2.(*ast.TableName),
  3079. IndexPartSpecifications: $3.([]*ast.IndexPartSpecification),
  3080. OnDelete: onDeleteUpdate[0].(*ast.OnDeleteOpt),
  3081. OnUpdate: onDeleteUpdate[1].(*ast.OnUpdateOpt),
  3082. Match: $4.(ast.MatchType),
  3083. }
  3084. }
  3085. OnDelete:
  3086. "ON" "DELETE" ReferOpt
  3087. {
  3088. $$ = &ast.OnDeleteOpt{ReferOpt: $3.(ast.ReferOptionType)}
  3089. }
  3090. OnUpdate:
  3091. "ON" "UPDATE" ReferOpt
  3092. {
  3093. $$ = &ast.OnUpdateOpt{ReferOpt: $3.(ast.ReferOptionType)}
  3094. }
  3095. OnDeleteUpdateOpt:
  3096. %prec lowerThanOn
  3097. {
  3098. $$ = [2]interface{}{&ast.OnDeleteOpt{}, &ast.OnUpdateOpt{}}
  3099. }
  3100. | OnDelete %prec lowerThanOn
  3101. {
  3102. $$ = [2]interface{}{$1, &ast.OnUpdateOpt{}}
  3103. }
  3104. | OnUpdate %prec lowerThanOn
  3105. {
  3106. $$ = [2]interface{}{&ast.OnDeleteOpt{}, $1}
  3107. }
  3108. | OnDelete OnUpdate
  3109. {
  3110. $$ = [2]interface{}{$1, $2}
  3111. }
  3112. | OnUpdate OnDelete
  3113. {
  3114. $$ = [2]interface{}{$2, $1}
  3115. }
  3116. ReferOpt:
  3117. "RESTRICT"
  3118. {
  3119. $$ = ast.ReferOptionRestrict
  3120. }
  3121. | "CASCADE"
  3122. {
  3123. $$ = ast.ReferOptionCascade
  3124. }
  3125. | "SET" "NULL"
  3126. {
  3127. $$ = ast.ReferOptionSetNull
  3128. }
  3129. | "NO" "ACTION"
  3130. {
  3131. $$ = ast.ReferOptionNoAction
  3132. }
  3133. | "SET" "DEFAULT"
  3134. {
  3135. $$ = ast.ReferOptionSetDefault
  3136. yylex.AppendError(yylex.Errorf("The SET DEFAULT clause is parsed but ignored by all storage engines."))
  3137. parser.lastErrorAsWarn()
  3138. }
  3139. /*
  3140. * The DEFAULT clause specifies a default value for a column.
  3141. * With one exception, the default value must be a constant;
  3142. * it cannot be a function or an expression. This means, for example,
  3143. * that you cannot set the default for a date column to be the value of
  3144. * a function such as NOW() or CURRENT_DATE. The exception is that you
  3145. * can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP or DATETIME column.
  3146. *
  3147. * See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
  3148. * https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L6832
  3149. */
  3150. DefaultValueExpr:
  3151. NowSymOptionFraction
  3152. | SignedLiteral
  3153. | NextValueForSequence
  3154. NowSymOptionFraction:
  3155. NowSym
  3156. {
  3157. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
  3158. }
  3159. | NowSymFunc '(' ')'
  3160. {
  3161. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
  3162. }
  3163. | NowSymFunc '(' NUM ')'
  3164. {
  3165. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP"), Args: []ast.ExprNode{ast.NewValueExpr($3, parser.charset, parser.collation)}}
  3166. }
  3167. NextValueForSequence:
  3168. "NEXT" "VALUE" forKwd TableName
  3169. {
  3170. objNameExpr := &ast.TableNameExpr{
  3171. Name: $4.(*ast.TableName),
  3172. }
  3173. $$ = &ast.FuncCallExpr{
  3174. FnName: model.NewCIStr(ast.NextVal),
  3175. Args: []ast.ExprNode{objNameExpr},
  3176. }
  3177. }
  3178. | "NEXTVAL" '(' TableName ')'
  3179. {
  3180. objNameExpr := &ast.TableNameExpr{
  3181. Name: $3.(*ast.TableName),
  3182. }
  3183. $$ = &ast.FuncCallExpr{
  3184. FnName: model.NewCIStr(ast.NextVal),
  3185. Args: []ast.ExprNode{objNameExpr},
  3186. }
  3187. }
  3188. /*
  3189. * See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_localtime
  3190. * TODO: Process other three keywords
  3191. */
  3192. NowSymFunc:
  3193. "CURRENT_TIMESTAMP"
  3194. | "LOCALTIME"
  3195. | "LOCALTIMESTAMP"
  3196. | builtinNow
  3197. NowSym:
  3198. "CURRENT_TIMESTAMP"
  3199. | "LOCALTIME"
  3200. | "LOCALTIMESTAMP"
  3201. SignedLiteral:
  3202. Literal
  3203. {
  3204. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  3205. }
  3206. | '+' NumLiteral
  3207. {
  3208. $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: ast.NewValueExpr($2, parser.charset, parser.collation)}
  3209. }
  3210. | '-' NumLiteral
  3211. {
  3212. $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: ast.NewValueExpr($2, parser.charset, parser.collation)}
  3213. }
  3214. NumLiteral:
  3215. intLit
  3216. | floatLit
  3217. | decLit
  3218. StatsType:
  3219. "CARDINALITY"
  3220. {
  3221. $$ = ast.StatsTypeCardinality
  3222. }
  3223. | "DEPENDENCY"
  3224. {
  3225. $$ = ast.StatsTypeDependency
  3226. }
  3227. | "CORRELATION"
  3228. {
  3229. $$ = ast.StatsTypeCorrelation
  3230. }
  3231. CreateStatisticsStmt:
  3232. "CREATE" "STATISTICS" IfNotExists Identifier '(' StatsType ')' "ON" TableName '(' ColumnNameList ')'
  3233. {
  3234. $$ = &ast.CreateStatisticsStmt{
  3235. IfNotExists: $3.(bool),
  3236. StatsName: $4,
  3237. StatsType: $6.(uint8),
  3238. Table: $9.(*ast.TableName),
  3239. Columns: $11.([]*ast.ColumnName),
  3240. }
  3241. }
  3242. DropStatisticsStmt:
  3243. "DROP" "STATISTICS" Identifier
  3244. {
  3245. $$ = &ast.DropStatisticsStmt{StatsName: $3}
  3246. }
  3247. /**************************************CreateIndexStmt***************************************
  3248. * See https://dev.mysql.com/doc/refman/8.0/en/create-index.html
  3249. *
  3250. * TYPE type_name is recognized as a synonym for USING type_name. However, USING is the preferred form.
  3251. *
  3252. * CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
  3253. * [index_type]
  3254. * ON tbl_name (key_part,...)
  3255. * [index_option]
  3256. * [algorithm_option | lock_option] ...
  3257. *
  3258. * key_part: {col_name [(length)] | (expr)} [ASC | DESC]
  3259. *
  3260. * index_option:
  3261. * KEY_BLOCK_SIZE [=] value
  3262. * | index_type
  3263. * | WITH PARSER parser_name
  3264. * | COMMENT 'string'
  3265. * | {VISIBLE | INVISIBLE}
  3266. *
  3267. * index_type:
  3268. * USING {BTREE | HASH}
  3269. *
  3270. * algorithm_option:
  3271. * ALGORITHM [=] {DEFAULT | INPLACE | COPY}
  3272. *
  3273. * lock_option:
  3274. * LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}
  3275. *******************************************************************************************/
  3276. CreateIndexStmt:
  3277. "CREATE" IndexKeyTypeOpt "INDEX" IfNotExists Identifier IndexTypeOpt "ON" TableName '(' IndexPartSpecificationList ')' IndexOptionList IndexLockAndAlgorithmOpt
  3278. {
  3279. var indexOption *ast.IndexOption
  3280. if $12 != nil {
  3281. indexOption = $12.(*ast.IndexOption)
  3282. if indexOption.Tp == model.IndexTypeInvalid {
  3283. if $6 != nil {
  3284. indexOption.Tp = $6.(model.IndexType)
  3285. }
  3286. }
  3287. } else {
  3288. indexOption = &ast.IndexOption{}
  3289. if $6 != nil {
  3290. indexOption.Tp = $6.(model.IndexType)
  3291. }
  3292. }
  3293. var indexLockAndAlgorithm *ast.IndexLockAndAlgorithm
  3294. if $13 != nil {
  3295. indexLockAndAlgorithm = $13.(*ast.IndexLockAndAlgorithm)
  3296. if indexLockAndAlgorithm.LockTp == ast.LockTypeDefault && indexLockAndAlgorithm.AlgorithmTp == ast.AlgorithmTypeDefault {
  3297. indexLockAndAlgorithm = nil
  3298. }
  3299. }
  3300. $$ = &ast.CreateIndexStmt{
  3301. IfNotExists: $4.(bool),
  3302. IndexName: $5,
  3303. Table: $8.(*ast.TableName),
  3304. IndexPartSpecifications: $10.([]*ast.IndexPartSpecification),
  3305. IndexOption: indexOption,
  3306. KeyType: $2.(ast.IndexKeyType),
  3307. LockAlg: indexLockAndAlgorithm,
  3308. }
  3309. }
  3310. IndexPartSpecificationListOpt:
  3311. {
  3312. $$ = ([]*ast.IndexPartSpecification)(nil)
  3313. }
  3314. | '(' IndexPartSpecificationList ')'
  3315. {
  3316. $$ = $2
  3317. }
  3318. IndexPartSpecificationList:
  3319. IndexPartSpecification
  3320. {
  3321. $$ = []*ast.IndexPartSpecification{$1.(*ast.IndexPartSpecification)}
  3322. }
  3323. | IndexPartSpecificationList ',' IndexPartSpecification
  3324. {
  3325. $$ = append($1.([]*ast.IndexPartSpecification), $3.(*ast.IndexPartSpecification))
  3326. }
  3327. IndexPartSpecification:
  3328. ColumnName OptFieldLen OptOrder
  3329. {
  3330. // Order is parsed but just ignored as MySQL did.
  3331. $$ = &ast.IndexPartSpecification{Column: $1.(*ast.ColumnName), Length: $2.(int)}
  3332. }
  3333. | '(' Expression ')' OptOrder
  3334. {
  3335. $$ = &ast.IndexPartSpecification{Expr: $2}
  3336. }
  3337. IndexLockAndAlgorithmOpt:
  3338. {
  3339. $$ = nil
  3340. }
  3341. | LockClause
  3342. {
  3343. $$ = &ast.IndexLockAndAlgorithm{
  3344. LockTp: $1.(ast.LockType),
  3345. AlgorithmTp: ast.AlgorithmTypeDefault,
  3346. }
  3347. }
  3348. | AlgorithmClause
  3349. {
  3350. $$ = &ast.IndexLockAndAlgorithm{
  3351. LockTp: ast.LockTypeDefault,
  3352. AlgorithmTp: $1.(ast.AlgorithmType),
  3353. }
  3354. }
  3355. | LockClause AlgorithmClause
  3356. {
  3357. $$ = &ast.IndexLockAndAlgorithm{
  3358. LockTp: $1.(ast.LockType),
  3359. AlgorithmTp: $2.(ast.AlgorithmType),
  3360. }
  3361. }
  3362. | AlgorithmClause LockClause
  3363. {
  3364. $$ = &ast.IndexLockAndAlgorithm{
  3365. LockTp: $2.(ast.LockType),
  3366. AlgorithmTp: $1.(ast.AlgorithmType),
  3367. }
  3368. }
  3369. IndexKeyTypeOpt:
  3370. {
  3371. $$ = ast.IndexKeyTypeNone
  3372. }
  3373. | "UNIQUE"
  3374. {
  3375. $$ = ast.IndexKeyTypeUnique
  3376. }
  3377. | "SPATIAL"
  3378. {
  3379. $$ = ast.IndexKeyTypeSpatial
  3380. }
  3381. | "FULLTEXT"
  3382. {
  3383. $$ = ast.IndexKeyTypeFullText
  3384. }
  3385. /**************************************AlterDatabaseStmt***************************************
  3386. * See https://dev.mysql.com/doc/refman/5.7/en/alter-database.html
  3387. * 'ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME' is not supported yet.
  3388. *
  3389. * ALTER {DATABASE | SCHEMA} [db_name]
  3390. * alter_specification ...
  3391. *
  3392. * alter_specification:
  3393. * [DEFAULT] CHARACTER SET [=] charset_name
  3394. * | [DEFAULT] COLLATE [=] collation_name
  3395. * | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'}
  3396. *******************************************************************************************/
  3397. AlterDatabaseStmt:
  3398. "ALTER" DatabaseSym DBName DatabaseOptionList
  3399. {
  3400. $$ = &ast.AlterDatabaseStmt{
  3401. Name: $3,
  3402. AlterDefaultDatabase: false,
  3403. Options: $4.([]*ast.DatabaseOption),
  3404. }
  3405. }
  3406. | "ALTER" DatabaseSym DatabaseOptionList
  3407. {
  3408. $$ = &ast.AlterDatabaseStmt{
  3409. Name: "",
  3410. AlterDefaultDatabase: true,
  3411. Options: $3.([]*ast.DatabaseOption),
  3412. }
  3413. }
  3414. /*******************************************************************
  3415. *
  3416. * Create Database Statement
  3417. * CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
  3418. * [create_specification] ...
  3419. *
  3420. * create_specification:
  3421. * [DEFAULT] CHARACTER SET [=] charset_name
  3422. * | [DEFAULT] COLLATE [=] collation_name
  3423. * | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'}
  3424. *******************************************************************/
  3425. CreateDatabaseStmt:
  3426. "CREATE" DatabaseSym IfNotExists DBName DatabaseOptionListOpt
  3427. {
  3428. $$ = &ast.CreateDatabaseStmt{
  3429. IfNotExists: $3.(bool),
  3430. Name: $4,
  3431. Options: $5.([]*ast.DatabaseOption),
  3432. }
  3433. }
  3434. DBName:
  3435. Identifier
  3436. DatabaseOption:
  3437. DefaultKwdOpt CharsetKw EqOpt CharsetName
  3438. {
  3439. $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCharset, Value: $4}
  3440. }
  3441. | DefaultKwdOpt "COLLATE" EqOpt CollationName
  3442. {
  3443. $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCollate, Value: $4}
  3444. }
  3445. | DefaultKwdOpt "ENCRYPTION" EqOpt EncryptionOpt
  3446. {
  3447. $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionEncryption, Value: $4}
  3448. }
  3449. DatabaseOptionListOpt:
  3450. {
  3451. $$ = []*ast.DatabaseOption{}
  3452. }
  3453. | DatabaseOptionList
  3454. DatabaseOptionList:
  3455. DatabaseOption
  3456. {
  3457. $$ = []*ast.DatabaseOption{$1.(*ast.DatabaseOption)}
  3458. }
  3459. | DatabaseOptionList DatabaseOption
  3460. {
  3461. $$ = append($1.([]*ast.DatabaseOption), $2.(*ast.DatabaseOption))
  3462. }
  3463. /*******************************************************************
  3464. *
  3465. * Create Table Statement
  3466. *
  3467. * Example:
  3468. * CREATE TABLE Persons
  3469. * (
  3470. * P_Id int NOT NULL,
  3471. * LastName varchar(255) NOT NULL,
  3472. * FirstName varchar(255),
  3473. * Address varchar(255),
  3474. * City varchar(255),
  3475. * PRIMARY KEY (P_Id)
  3476. * )
  3477. *******************************************************************/
  3478. CreateTableStmt:
  3479. "CREATE" OptTemporary "TABLE" IfNotExists TableName TableElementListOpt CreateTableOptionListOpt PartitionOpt DuplicateOpt AsOpt CreateTableSelectOpt
  3480. {
  3481. stmt := $6.(*ast.CreateTableStmt)
  3482. stmt.Table = $5.(*ast.TableName)
  3483. stmt.IfNotExists = $4.(bool)
  3484. stmt.IsTemporary = $2.(bool)
  3485. stmt.Options = $7.([]*ast.TableOption)
  3486. if $8 != nil {
  3487. stmt.Partition = $8.(*ast.PartitionOptions)
  3488. }
  3489. stmt.OnDuplicate = $9.(ast.OnDuplicateKeyHandlingType)
  3490. stmt.Select = $11.(*ast.CreateTableStmt).Select
  3491. $$ = stmt
  3492. }
  3493. | "CREATE" OptTemporary "TABLE" IfNotExists TableName LikeTableWithOrWithoutParen
  3494. {
  3495. $$ = &ast.CreateTableStmt{
  3496. Table: $5.(*ast.TableName),
  3497. ReferTable: $6.(*ast.TableName),
  3498. IfNotExists: $4.(bool),
  3499. IsTemporary: $2.(bool),
  3500. }
  3501. }
  3502. DefaultKwdOpt:
  3503. %prec lowerThanCharsetKwd
  3504. {}
  3505. | "DEFAULT"
  3506. PartitionOpt:
  3507. {
  3508. $$ = nil
  3509. }
  3510. | "PARTITION" "BY" PartitionMethod PartitionNumOpt SubPartitionOpt PartitionDefinitionListOpt
  3511. {
  3512. method := $3.(*ast.PartitionMethod)
  3513. method.Num = $4.(uint64)
  3514. sub, _ := $5.(*ast.PartitionMethod)
  3515. defs, _ := $6.([]*ast.PartitionDefinition)
  3516. opt := &ast.PartitionOptions{
  3517. PartitionMethod: *method,
  3518. Sub: sub,
  3519. Definitions: defs,
  3520. }
  3521. if err := opt.Validate(); err != nil {
  3522. yylex.AppendError(err)
  3523. return 1
  3524. }
  3525. $$ = opt
  3526. }
  3527. SubPartitionMethod:
  3528. LinearOpt "KEY" PartitionKeyAlgorithmOpt '(' ColumnNameListOpt ')'
  3529. {
  3530. $$ = &ast.PartitionMethod{
  3531. Tp: model.PartitionTypeKey,
  3532. Linear: len($1) != 0,
  3533. ColumnNames: $5.([]*ast.ColumnName),
  3534. }
  3535. }
  3536. | LinearOpt "HASH" '(' BitExpr ')'
  3537. {
  3538. $$ = &ast.PartitionMethod{
  3539. Tp: model.PartitionTypeHash,
  3540. Linear: len($1) != 0,
  3541. Expr: $4.(ast.ExprNode),
  3542. }
  3543. }
  3544. PartitionKeyAlgorithmOpt:
  3545. /* empty */
  3546. {}
  3547. | "ALGORITHM" '=' NUM
  3548. {}
  3549. PartitionMethod:
  3550. SubPartitionMethod
  3551. | "RANGE" '(' BitExpr ')'
  3552. {
  3553. $$ = &ast.PartitionMethod{
  3554. Tp: model.PartitionTypeRange,
  3555. Expr: $3.(ast.ExprNode),
  3556. }
  3557. }
  3558. | "RANGE" FieldsOrColumns '(' ColumnNameList ')'
  3559. {
  3560. $$ = &ast.PartitionMethod{
  3561. Tp: model.PartitionTypeRange,
  3562. ColumnNames: $4.([]*ast.ColumnName),
  3563. }
  3564. }
  3565. | "LIST" '(' BitExpr ')'
  3566. {
  3567. $$ = &ast.PartitionMethod{
  3568. Tp: model.PartitionTypeList,
  3569. Expr: $3.(ast.ExprNode),
  3570. }
  3571. }
  3572. | "LIST" FieldsOrColumns '(' ColumnNameList ')'
  3573. {
  3574. $$ = &ast.PartitionMethod{
  3575. Tp: model.PartitionTypeList,
  3576. ColumnNames: $4.([]*ast.ColumnName),
  3577. }
  3578. }
  3579. | "SYSTEM_TIME" "INTERVAL" Expression TimeUnit
  3580. {
  3581. $$ = &ast.PartitionMethod{
  3582. Tp: model.PartitionTypeSystemTime,
  3583. Expr: $3.(ast.ExprNode),
  3584. Unit: $4.(ast.TimeUnitType),
  3585. }
  3586. }
  3587. | "SYSTEM_TIME" "LIMIT" LengthNum
  3588. {
  3589. $$ = &ast.PartitionMethod{
  3590. Tp: model.PartitionTypeSystemTime,
  3591. Limit: $3.(uint64),
  3592. }
  3593. }
  3594. | "SYSTEM_TIME"
  3595. {
  3596. $$ = &ast.PartitionMethod{
  3597. Tp: model.PartitionTypeSystemTime,
  3598. }
  3599. }
  3600. LinearOpt:
  3601. {
  3602. $$ = ""
  3603. }
  3604. | "LINEAR"
  3605. SubPartitionOpt:
  3606. {
  3607. $$ = nil
  3608. }
  3609. | "SUBPARTITION" "BY" SubPartitionMethod SubPartitionNumOpt
  3610. {
  3611. method := $3.(*ast.PartitionMethod)
  3612. method.Num = $4.(uint64)
  3613. $$ = method
  3614. }
  3615. SubPartitionNumOpt:
  3616. {
  3617. $$ = uint64(0)
  3618. }
  3619. | "SUBPARTITIONS" LengthNum
  3620. {
  3621. res := $2.(uint64)
  3622. if res == 0 {
  3623. yylex.AppendError(ast.ErrNoParts.GenWithStackByArgs("subpartitions"))
  3624. return 1
  3625. }
  3626. $$ = res
  3627. }
  3628. PartitionNumOpt:
  3629. {
  3630. $$ = uint64(0)
  3631. }
  3632. | "PARTITIONS" LengthNum
  3633. {
  3634. res := $2.(uint64)
  3635. if res == 0 {
  3636. yylex.AppendError(ast.ErrNoParts.GenWithStackByArgs("partitions"))
  3637. return 1
  3638. }
  3639. $$ = res
  3640. }
  3641. PartitionDefinitionListOpt:
  3642. /* empty */ %prec lowerThanCreateTableSelect
  3643. {
  3644. $$ = nil
  3645. }
  3646. | '(' PartitionDefinitionList ')'
  3647. {
  3648. $$ = $2.([]*ast.PartitionDefinition)
  3649. }
  3650. PartitionDefinitionList:
  3651. PartitionDefinition
  3652. {
  3653. $$ = []*ast.PartitionDefinition{$1.(*ast.PartitionDefinition)}
  3654. }
  3655. | PartitionDefinitionList ',' PartitionDefinition
  3656. {
  3657. $$ = append($1.([]*ast.PartitionDefinition), $3.(*ast.PartitionDefinition))
  3658. }
  3659. PartitionDefinition:
  3660. "PARTITION" Identifier PartDefValuesOpt PartDefOptionList SubPartDefinitionListOpt
  3661. {
  3662. $$ = &ast.PartitionDefinition{
  3663. Name: model.NewCIStr($2),
  3664. Clause: $3.(ast.PartitionDefinitionClause),
  3665. Options: $4.([]*ast.TableOption),
  3666. Sub: $5.([]*ast.SubPartitionDefinition),
  3667. }
  3668. }
  3669. SubPartDefinitionListOpt:
  3670. /*empty*/
  3671. {
  3672. $$ = make([]*ast.SubPartitionDefinition, 0)
  3673. }
  3674. | '(' SubPartDefinitionList ')'
  3675. {
  3676. $$ = $2
  3677. }
  3678. SubPartDefinitionList:
  3679. SubPartDefinition
  3680. {
  3681. $$ = []*ast.SubPartitionDefinition{$1.(*ast.SubPartitionDefinition)}
  3682. }
  3683. | SubPartDefinitionList ',' SubPartDefinition
  3684. {
  3685. list := $1.([]*ast.SubPartitionDefinition)
  3686. $$ = append(list, $3.(*ast.SubPartitionDefinition))
  3687. }
  3688. SubPartDefinition:
  3689. "SUBPARTITION" Identifier PartDefOptionList
  3690. {
  3691. $$ = &ast.SubPartitionDefinition{
  3692. Name: model.NewCIStr($2),
  3693. Options: $3.([]*ast.TableOption),
  3694. }
  3695. }
  3696. PartDefOptionList:
  3697. /*empty*/
  3698. {
  3699. $$ = make([]*ast.TableOption, 0)
  3700. }
  3701. | PartDefOptionList PartDefOption
  3702. {
  3703. list := $1.([]*ast.TableOption)
  3704. $$ = append(list, $2.(*ast.TableOption))
  3705. }
  3706. PartDefOption:
  3707. "COMMENT" EqOpt stringLit
  3708. {
  3709. $$ = &ast.TableOption{Tp: ast.TableOptionComment, StrValue: $3}
  3710. }
  3711. | "ENGINE" EqOpt StringName
  3712. {
  3713. $$ = &ast.TableOption{Tp: ast.TableOptionEngine, StrValue: $3}
  3714. }
  3715. | "STORAGE" "ENGINE" EqOpt StringName
  3716. {
  3717. $$ = &ast.TableOption{Tp: ast.TableOptionEngine, StrValue: $4}
  3718. }
  3719. | "INSERT_METHOD" EqOpt StringName
  3720. {
  3721. $$ = &ast.TableOption{Tp: ast.TableOptionInsertMethod, StrValue: $3}
  3722. }
  3723. | "DATA" "DIRECTORY" EqOpt stringLit
  3724. {
  3725. $$ = &ast.TableOption{Tp: ast.TableOptionDataDirectory, StrValue: $4}
  3726. }
  3727. | "INDEX" "DIRECTORY" EqOpt stringLit
  3728. {
  3729. $$ = &ast.TableOption{Tp: ast.TableOptionIndexDirectory, StrValue: $4}
  3730. }
  3731. | "MAX_ROWS" EqOpt LengthNum
  3732. {
  3733. $$ = &ast.TableOption{Tp: ast.TableOptionMaxRows, UintValue: $3.(uint64)}
  3734. }
  3735. | "MIN_ROWS" EqOpt LengthNum
  3736. {
  3737. $$ = &ast.TableOption{Tp: ast.TableOptionMinRows, UintValue: $3.(uint64)}
  3738. }
  3739. | "TABLESPACE" EqOpt Identifier
  3740. {
  3741. $$ = &ast.TableOption{Tp: ast.TableOptionTablespace, StrValue: $3}
  3742. }
  3743. | "NODEGROUP" EqOpt LengthNum
  3744. {
  3745. $$ = &ast.TableOption{Tp: ast.TableOptionNodegroup, UintValue: $3.(uint64)}
  3746. }
  3747. PartDefValuesOpt:
  3748. {
  3749. $$ = &ast.PartitionDefinitionClauseNone{}
  3750. }
  3751. | "VALUES" "LESS" "THAN" "MAXVALUE"
  3752. {
  3753. $$ = &ast.PartitionDefinitionClauseLessThan{
  3754. Exprs: []ast.ExprNode{&ast.MaxValueExpr{}},
  3755. }
  3756. }
  3757. | "VALUES" "LESS" "THAN" '(' MaxValueOrExpressionList ')'
  3758. {
  3759. $$ = &ast.PartitionDefinitionClauseLessThan{
  3760. Exprs: $5.([]ast.ExprNode),
  3761. }
  3762. }
  3763. | "DEFAULT"
  3764. {
  3765. $$ = &ast.PartitionDefinitionClauseIn{}
  3766. }
  3767. | "VALUES" "IN" '(' MaxValueOrExpressionList ')'
  3768. {
  3769. exprs := $4.([]ast.ExprNode)
  3770. values := make([][]ast.ExprNode, 0, len(exprs))
  3771. for _, expr := range exprs {
  3772. if row, ok := expr.(*ast.RowExpr); ok {
  3773. values = append(values, row.Values)
  3774. } else {
  3775. values = append(values, []ast.ExprNode{expr})
  3776. }
  3777. }
  3778. $$ = &ast.PartitionDefinitionClauseIn{Values: values}
  3779. }
  3780. | "HISTORY"
  3781. {
  3782. $$ = &ast.PartitionDefinitionClauseHistory{Current: false}
  3783. }
  3784. | "CURRENT"
  3785. {
  3786. $$ = &ast.PartitionDefinitionClauseHistory{Current: true}
  3787. }
  3788. DuplicateOpt:
  3789. {
  3790. $$ = ast.OnDuplicateKeyHandlingError
  3791. }
  3792. | "IGNORE"
  3793. {
  3794. $$ = ast.OnDuplicateKeyHandlingIgnore
  3795. }
  3796. | "REPLACE"
  3797. {
  3798. $$ = ast.OnDuplicateKeyHandlingReplace
  3799. }
  3800. AsOpt:
  3801. {}
  3802. | "AS"
  3803. {}
  3804. CreateTableSelectOpt:
  3805. /* empty */
  3806. {
  3807. $$ = &ast.CreateTableStmt{}
  3808. }
  3809. | SetOprStmt1
  3810. {
  3811. $$ = &ast.CreateTableStmt{Select: $1}
  3812. }
  3813. CreateViewSelectOpt:
  3814. SetOprStmt1
  3815. | '(' SetOprStmt1 ')'
  3816. {
  3817. $$ = $2
  3818. }
  3819. LikeTableWithOrWithoutParen:
  3820. "LIKE" TableName
  3821. {
  3822. $$ = $2
  3823. }
  3824. | '(' "LIKE" TableName ')'
  3825. {
  3826. $$ = $3
  3827. }
  3828. /*******************************************************************
  3829. *
  3830. * Create View Statement
  3831. *
  3832. * Example:
  3833. * CREATE VIEW OR REPLACE ALGORITHM = MERGE DEFINER="root@localhost" SQL SECURITY = definer view_name (col1,col2)
  3834. * as select Col1,Col2 from table WITH LOCAL CHECK OPTION
  3835. *******************************************************************/
  3836. CreateViewStmt:
  3837. "CREATE" OrReplace ViewAlgorithm ViewDefiner ViewSQLSecurity "VIEW" ViewName ViewFieldList "AS" CreateViewSelectOpt ViewCheckOption
  3838. {
  3839. startOffset := parser.startOffset(&yyS[yypt-1])
  3840. selStmt := $10.(ast.StmtNode)
  3841. selStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
  3842. x := &ast.CreateViewStmt{
  3843. OrReplace: $2.(bool),
  3844. ViewName: $7.(*ast.TableName),
  3845. Select: selStmt,
  3846. Algorithm: $3.(model.ViewAlgorithm),
  3847. Definer: $4.(*auth.UserIdentity),
  3848. Security: $5.(model.ViewSecurity),
  3849. }
  3850. if $8 != nil {
  3851. x.Cols = $8.([]model.CIStr)
  3852. }
  3853. if $11 != nil {
  3854. x.CheckOption = $11.(model.ViewCheckOption)
  3855. endOffset := parser.startOffset(&yyS[yypt])
  3856. selStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset]))
  3857. } else {
  3858. x.CheckOption = model.CheckOptionCascaded
  3859. }
  3860. $$ = x
  3861. }
  3862. OrReplace:
  3863. /* EMPTY */
  3864. {
  3865. $$ = false
  3866. }
  3867. | "OR" "REPLACE"
  3868. {
  3869. $$ = true
  3870. }
  3871. ViewAlgorithm:
  3872. /* EMPTY */
  3873. {
  3874. $$ = model.AlgorithmUndefined
  3875. }
  3876. | "ALGORITHM" "=" "UNDEFINED"
  3877. {
  3878. $$ = model.AlgorithmUndefined
  3879. }
  3880. | "ALGORITHM" "=" "MERGE"
  3881. {
  3882. $$ = model.AlgorithmMerge
  3883. }
  3884. | "ALGORITHM" "=" "TEMPTABLE"
  3885. {
  3886. $$ = model.AlgorithmTemptable
  3887. }
  3888. ViewDefiner:
  3889. /* EMPTY */
  3890. {
  3891. $$ = &auth.UserIdentity{CurrentUser: true}
  3892. }
  3893. | "DEFINER" "=" Username
  3894. {
  3895. $$ = $3
  3896. }
  3897. ViewSQLSecurity:
  3898. /* EMPTY */
  3899. {
  3900. $$ = model.SecurityDefiner
  3901. }
  3902. | "SQL" "SECURITY" "DEFINER"
  3903. {
  3904. $$ = model.SecurityDefiner
  3905. }
  3906. | "SQL" "SECURITY" "INVOKER"
  3907. {
  3908. $$ = model.SecurityInvoker
  3909. }
  3910. ViewName:
  3911. TableName
  3912. ViewFieldList:
  3913. /* Empty */
  3914. {
  3915. $$ = nil
  3916. }
  3917. | '(' ColumnList ')'
  3918. {
  3919. $$ = $2.([]model.CIStr)
  3920. }
  3921. ColumnList:
  3922. Identifier
  3923. {
  3924. $$ = []model.CIStr{model.NewCIStr($1)}
  3925. }
  3926. | ColumnList ',' Identifier
  3927. {
  3928. $$ = append($1.([]model.CIStr), model.NewCIStr($3))
  3929. }
  3930. ViewCheckOption:
  3931. /* EMPTY */
  3932. {
  3933. $$ = nil
  3934. }
  3935. | "WITH" "CASCADED" "CHECK" "OPTION"
  3936. {
  3937. $$ = model.CheckOptionCascaded
  3938. }
  3939. | "WITH" "LOCAL" "CHECK" "OPTION"
  3940. {
  3941. $$ = model.CheckOptionLocal
  3942. }
  3943. /******************************************************************
  3944. * Do statement
  3945. * See https://dev.mysql.com/doc/refman/5.7/en/do.html
  3946. ******************************************************************/
  3947. DoStmt:
  3948. "DO" ExpressionList
  3949. {
  3950. $$ = &ast.DoStmt{
  3951. Exprs: $2.([]ast.ExprNode),
  3952. }
  3953. }
  3954. /*******************************************************************
  3955. *
  3956. * Delete Statement
  3957. *
  3958. *******************************************************************/
  3959. DeleteWithoutUsingStmt:
  3960. "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional "FROM" TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt WhereClauseOptional OrderByOptional LimitClause
  3961. {
  3962. // Single Table
  3963. tn := $7.(*ast.TableName)
  3964. tn.IndexHints = $10.([]*ast.IndexHint)
  3965. tn.PartitionNames = $8.([]model.CIStr)
  3966. join := &ast.Join{Left: &ast.TableSource{Source: tn, AsName: $9.(model.CIStr)}, Right: nil}
  3967. x := &ast.DeleteStmt{
  3968. TableRefs: &ast.TableRefsClause{TableRefs: join},
  3969. Priority: $3.(mysql.PriorityEnum),
  3970. Quick: $4.(bool),
  3971. IgnoreErr: $5.(bool),
  3972. }
  3973. if $2 != nil {
  3974. x.TableHints = $2.([]*ast.TableOptimizerHint)
  3975. }
  3976. if $11 != nil {
  3977. x.Where = $11.(ast.ExprNode)
  3978. }
  3979. if $12 != nil {
  3980. x.Order = $12.(*ast.OrderByClause)
  3981. }
  3982. if $13 != nil {
  3983. x.Limit = $13.(*ast.Limit)
  3984. }
  3985. $$ = x
  3986. }
  3987. | "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional TableAliasRefList "FROM" TableRefs WhereClauseOptional
  3988. {
  3989. // Multiple Table
  3990. x := &ast.DeleteStmt{
  3991. Priority: $3.(mysql.PriorityEnum),
  3992. Quick: $4.(bool),
  3993. IgnoreErr: $5.(bool),
  3994. IsMultiTable: true,
  3995. BeforeFrom: true,
  3996. Tables: &ast.DeleteTableList{Tables: $6.([]*ast.TableName)},
  3997. TableRefs: &ast.TableRefsClause{TableRefs: $8.(*ast.Join)},
  3998. }
  3999. if $2 != nil {
  4000. x.TableHints = $2.([]*ast.TableOptimizerHint)
  4001. }
  4002. if $9 != nil {
  4003. x.Where = $9.(ast.ExprNode)
  4004. }
  4005. $$ = x
  4006. }
  4007. DeleteWithUsingStmt:
  4008. "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional "FROM" TableAliasRefList "USING" TableRefs WhereClauseOptional
  4009. {
  4010. // Multiple Table
  4011. x := &ast.DeleteStmt{
  4012. Priority: $3.(mysql.PriorityEnum),
  4013. Quick: $4.(bool),
  4014. IgnoreErr: $5.(bool),
  4015. IsMultiTable: true,
  4016. Tables: &ast.DeleteTableList{Tables: $7.([]*ast.TableName)},
  4017. TableRefs: &ast.TableRefsClause{TableRefs: $9.(*ast.Join)},
  4018. }
  4019. if $2 != nil {
  4020. x.TableHints = $2.([]*ast.TableOptimizerHint)
  4021. }
  4022. if $10 != nil {
  4023. x.Where = $10.(ast.ExprNode)
  4024. }
  4025. $$ = x
  4026. }
  4027. DeleteFromStmt:
  4028. DeleteWithoutUsingStmt
  4029. | DeleteWithUsingStmt
  4030. | WithClause DeleteWithoutUsingStmt
  4031. {
  4032. d := $2.(*ast.DeleteStmt)
  4033. d.With = $1.(*ast.WithClause)
  4034. $$ = d
  4035. }
  4036. | WithClause DeleteWithUsingStmt
  4037. {
  4038. d := $2.(*ast.DeleteStmt)
  4039. d.With = $1.(*ast.WithClause)
  4040. $$ = d
  4041. }
  4042. DatabaseSym:
  4043. "DATABASE"
  4044. DropDatabaseStmt:
  4045. "DROP" DatabaseSym IfExists DBName
  4046. {
  4047. $$ = &ast.DropDatabaseStmt{IfExists: $3.(bool), Name: $4}
  4048. }
  4049. /******************************************************************
  4050. * Drop Index Statement
  4051. * See https://dev.mysql.com/doc/refman/8.0/en/drop-index.html
  4052. *
  4053. * DROP INDEX index_name ON tbl_name
  4054. * [algorithm_option | lock_option] ...
  4055. *
  4056. * algorithm_option:
  4057. * ALGORITHM [=] {DEFAULT|INPLACE|COPY}
  4058. *
  4059. * lock_option:
  4060. * LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE}
  4061. ******************************************************************/
  4062. DropIndexStmt:
  4063. "DROP" "INDEX" IfExists Identifier "ON" TableName IndexLockAndAlgorithmOpt
  4064. {
  4065. var indexLockAndAlgorithm *ast.IndexLockAndAlgorithm
  4066. if $7 != nil {
  4067. indexLockAndAlgorithm = $7.(*ast.IndexLockAndAlgorithm)
  4068. if indexLockAndAlgorithm.LockTp == ast.LockTypeDefault && indexLockAndAlgorithm.AlgorithmTp == ast.AlgorithmTypeDefault {
  4069. indexLockAndAlgorithm = nil
  4070. }
  4071. }
  4072. $$ = &ast.DropIndexStmt{IfExists: $3.(bool), IndexName: $4, Table: $6.(*ast.TableName), LockAlg: indexLockAndAlgorithm}
  4073. }
  4074. DropTableStmt:
  4075. "DROP" OptTemporary TableOrTables IfExists TableNameList RestrictOrCascadeOpt
  4076. {
  4077. $$ = &ast.DropTableStmt{IfExists: $4.(bool), Tables: $5.([]*ast.TableName), IsView: false, IsTemporary: $2.(bool)}
  4078. }
  4079. OptTemporary:
  4080. /* empty */
  4081. {
  4082. $$ = false
  4083. }
  4084. | "TEMPORARY"
  4085. {
  4086. $$ = true
  4087. yylex.AppendError(yylex.Errorf("TiDB doesn't support TEMPORARY TABLE, TEMPORARY will be parsed but ignored."))
  4088. parser.lastErrorAsWarn()
  4089. }
  4090. DropViewStmt:
  4091. "DROP" "VIEW" TableNameList RestrictOrCascadeOpt
  4092. {
  4093. $$ = &ast.DropTableStmt{Tables: $3.([]*ast.TableName), IsView: true}
  4094. }
  4095. | "DROP" "VIEW" "IF" "EXISTS" TableNameList RestrictOrCascadeOpt
  4096. {
  4097. $$ = &ast.DropTableStmt{IfExists: true, Tables: $5.([]*ast.TableName), IsView: true}
  4098. }
  4099. DropUserStmt:
  4100. "DROP" "USER" UsernameList
  4101. {
  4102. $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: false, UserList: $3.([]*auth.UserIdentity)}
  4103. }
  4104. | "DROP" "USER" "IF" "EXISTS" UsernameList
  4105. {
  4106. $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: true, UserList: $5.([]*auth.UserIdentity)}
  4107. }
  4108. DropRoleStmt:
  4109. "DROP" "ROLE" RolenameList
  4110. {
  4111. tmp := make([]*auth.UserIdentity, 0, 10)
  4112. roleList := $3.([]*auth.RoleIdentity)
  4113. for _, r := range roleList {
  4114. tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname})
  4115. }
  4116. $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: false, UserList: tmp}
  4117. }
  4118. | "DROP" "ROLE" "IF" "EXISTS" RolenameList
  4119. {
  4120. tmp := make([]*auth.UserIdentity, 0, 10)
  4121. roleList := $5.([]*auth.RoleIdentity)
  4122. for _, r := range roleList {
  4123. tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname})
  4124. }
  4125. $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: true, UserList: tmp}
  4126. }
  4127. DropStatsStmt:
  4128. "DROP" "STATS" TableName
  4129. {
  4130. $$ = &ast.DropStatsStmt{Table: $3.(*ast.TableName)}
  4131. }
  4132. | "DROP" "STATS" TableName "PARTITION" PartitionNameList
  4133. {
  4134. $$ = &ast.DropStatsStmt{
  4135. Table: $3.(*ast.TableName),
  4136. PartitionNames: $5.([]model.CIStr),
  4137. }
  4138. }
  4139. | "DROP" "STATS" TableName "GLOBAL"
  4140. {
  4141. $$ = &ast.DropStatsStmt{
  4142. Table: $3.(*ast.TableName),
  4143. IsGlobalStats: true,
  4144. }
  4145. }
  4146. RestrictOrCascadeOpt:
  4147. {}
  4148. | "RESTRICT"
  4149. | "CASCADE"
  4150. TableOrTables:
  4151. "TABLE"
  4152. | "TABLES"
  4153. EqOpt:
  4154. {}
  4155. | eq
  4156. EmptyStmt:
  4157. /* EMPTY */
  4158. {
  4159. $$ = nil
  4160. }
  4161. TraceStmt:
  4162. "TRACE" TraceableStmt
  4163. {
  4164. $$ = &ast.TraceStmt{
  4165. Stmt: $2,
  4166. Format: "row",
  4167. }
  4168. startOffset := parser.startOffset(&yyS[yypt])
  4169. $2.SetText(string(parser.src[startOffset:]))
  4170. }
  4171. | "TRACE" "FORMAT" "=" stringLit TraceableStmt
  4172. {
  4173. $$ = &ast.TraceStmt{
  4174. Stmt: $5,
  4175. Format: $4,
  4176. }
  4177. startOffset := parser.startOffset(&yyS[yypt])
  4178. $5.SetText(string(parser.src[startOffset:]))
  4179. }
  4180. ExplainSym:
  4181. "EXPLAIN"
  4182. | "DESCRIBE"
  4183. | "DESC"
  4184. ExplainStmt:
  4185. ExplainSym TableName
  4186. {
  4187. $$ = &ast.ExplainStmt{
  4188. Stmt: &ast.ShowStmt{
  4189. Tp: ast.ShowColumns,
  4190. Table: $2.(*ast.TableName),
  4191. },
  4192. }
  4193. }
  4194. | ExplainSym TableName ColumnName
  4195. {
  4196. $$ = &ast.ExplainStmt{
  4197. Stmt: &ast.ShowStmt{
  4198. Tp: ast.ShowColumns,
  4199. Table: $2.(*ast.TableName),
  4200. Column: $3.(*ast.ColumnName),
  4201. },
  4202. }
  4203. }
  4204. | ExplainSym ExplainableStmt
  4205. {
  4206. $$ = &ast.ExplainStmt{
  4207. Stmt: $2,
  4208. Format: "row",
  4209. }
  4210. }
  4211. | ExplainSym "FOR" "CONNECTION" NUM
  4212. {
  4213. $$ = &ast.ExplainForStmt{
  4214. Format: "row",
  4215. ConnectionID: getUint64FromNUM($4),
  4216. }
  4217. }
  4218. | ExplainSym "FORMAT" "=" stringLit "FOR" "CONNECTION" NUM
  4219. {
  4220. $$ = &ast.ExplainForStmt{
  4221. Format: $4,
  4222. ConnectionID: getUint64FromNUM($7),
  4223. }
  4224. }
  4225. | ExplainSym "FORMAT" "=" stringLit ExplainableStmt
  4226. {
  4227. $$ = &ast.ExplainStmt{
  4228. Stmt: $5,
  4229. Format: $4,
  4230. }
  4231. }
  4232. | ExplainSym "FORMAT" "=" ExplainFormatType "FOR" "CONNECTION" NUM
  4233. {
  4234. $$ = &ast.ExplainForStmt{
  4235. Format: $4,
  4236. ConnectionID: getUint64FromNUM($7),
  4237. }
  4238. }
  4239. | ExplainSym "FORMAT" "=" ExplainFormatType ExplainableStmt
  4240. {
  4241. $$ = &ast.ExplainStmt{
  4242. Stmt: $5,
  4243. Format: $4,
  4244. }
  4245. }
  4246. | ExplainSym "ANALYZE" ExplainableStmt
  4247. {
  4248. $$ = &ast.ExplainStmt{
  4249. Stmt: $3,
  4250. Format: "row",
  4251. Analyze: true,
  4252. }
  4253. }
  4254. ExplainFormatType:
  4255. "TRADITIONAL"
  4256. {
  4257. $$ = "row"
  4258. }
  4259. | "JSON"
  4260. {
  4261. $$ = "json"
  4262. }
  4263. /*******************************************************************
  4264. * Backup / restore / import statements
  4265. *
  4266. * BACKUP DATABASE [ * | db1, db2, db3 ] TO 'scheme://location' [ options... ]
  4267. * BACKUP TABLE [ db1.tbl1, db2.tbl2 ] TO 'scheme://location' [ options... ]
  4268. * RESTORE DATABASE [ * | db1, db2, db3 ] FROM 'scheme://location' [ options... ]
  4269. * RESTORE TABLE [ db1.tbl1, db2.tbl2 ] FROM 'scheme://location' [ options... ]
  4270. */
  4271. BRIEStmt:
  4272. "BACKUP" BRIETables "TO" stringLit BRIEOptions
  4273. {
  4274. stmt := $2.(*ast.BRIEStmt)
  4275. stmt.Kind = ast.BRIEKindBackup
  4276. stmt.Storage = $4
  4277. stmt.Options = $5.([]*ast.BRIEOption)
  4278. $$ = stmt
  4279. }
  4280. | "RESTORE" BRIETables "FROM" stringLit BRIEOptions
  4281. {
  4282. stmt := $2.(*ast.BRIEStmt)
  4283. stmt.Kind = ast.BRIEKindRestore
  4284. stmt.Storage = $4
  4285. stmt.Options = $5.([]*ast.BRIEOption)
  4286. $$ = stmt
  4287. }
  4288. BRIETables:
  4289. DatabaseSym '*'
  4290. {
  4291. $$ = &ast.BRIEStmt{}
  4292. }
  4293. | DatabaseSym DBNameList
  4294. {
  4295. $$ = &ast.BRIEStmt{Schemas: $2.([]string)}
  4296. }
  4297. | "TABLE" TableNameList
  4298. {
  4299. $$ = &ast.BRIEStmt{Tables: $2.([]*ast.TableName)}
  4300. }
  4301. DBNameList:
  4302. DBName
  4303. {
  4304. $$ = []string{$1}
  4305. }
  4306. | DBNameList ',' DBName
  4307. {
  4308. $$ = append($1.([]string), $3)
  4309. }
  4310. BRIEOptions:
  4311. %prec empty
  4312. {
  4313. $$ = []*ast.BRIEOption{}
  4314. }
  4315. | BRIEOptions BRIEOption
  4316. {
  4317. $$ = append($1.([]*ast.BRIEOption), $2.(*ast.BRIEOption))
  4318. }
  4319. BRIEIntegerOptionName:
  4320. "CONCURRENCY"
  4321. {
  4322. $$ = ast.BRIEOptionConcurrency
  4323. }
  4324. | "RESUME"
  4325. {
  4326. $$ = ast.BRIEOptionResume
  4327. }
  4328. BRIEBooleanOptionName:
  4329. "SEND_CREDENTIALS_TO_TIKV"
  4330. {
  4331. $$ = ast.BRIEOptionSendCreds
  4332. }
  4333. | "ONLINE"
  4334. {
  4335. $$ = ast.BRIEOptionOnline
  4336. }
  4337. | "CHECKPOINT"
  4338. {
  4339. $$ = ast.BRIEOptionCheckpoint
  4340. }
  4341. | "SKIP_SCHEMA_FILES"
  4342. {
  4343. $$ = ast.BRIEOptionSkipSchemaFiles
  4344. }
  4345. | "STRICT_FORMAT"
  4346. {
  4347. $$ = ast.BRIEOptionStrictFormat
  4348. }
  4349. | "CSV_NOT_NULL"
  4350. {
  4351. $$ = ast.BRIEOptionCSVNotNull
  4352. }
  4353. | "CSV_BACKSLASH_ESCAPE"
  4354. {
  4355. $$ = ast.BRIEOptionCSVBackslashEscape
  4356. }
  4357. | "CSV_TRIM_LAST_SEPARATORS"
  4358. {
  4359. $$ = ast.BRIEOptionCSVTrimLastSeparators
  4360. }
  4361. BRIEStringOptionName:
  4362. "TIKV_IMPORTER"
  4363. {
  4364. $$ = ast.BRIEOptionTiKVImporter
  4365. }
  4366. | "CSV_SEPARATOR"
  4367. {
  4368. $$ = ast.BRIEOptionCSVSeparator
  4369. }
  4370. | "CSV_DELIMITER"
  4371. {
  4372. $$ = ast.BRIEOptionCSVDelimiter
  4373. }
  4374. | "CSV_NULL"
  4375. {
  4376. $$ = ast.BRIEOptionCSVNull
  4377. }
  4378. BRIEKeywordOptionName:
  4379. "BACKEND"
  4380. {
  4381. $$ = ast.BRIEOptionBackend
  4382. }
  4383. | "ON_DUPLICATE"
  4384. {
  4385. $$ = ast.BRIEOptionOnDuplicate
  4386. }
  4387. | "ON" "DUPLICATE"
  4388. {
  4389. $$ = ast.BRIEOptionOnDuplicate
  4390. }
  4391. BRIEOption:
  4392. BRIEIntegerOptionName EqOpt LengthNum
  4393. {
  4394. $$ = &ast.BRIEOption{
  4395. Tp: $1.(ast.BRIEOptionType),
  4396. UintValue: $3.(uint64),
  4397. }
  4398. }
  4399. | BRIEBooleanOptionName EqOpt Boolean
  4400. {
  4401. value := uint64(0)
  4402. if $3.(bool) {
  4403. value = 1
  4404. }
  4405. $$ = &ast.BRIEOption{
  4406. Tp: $1.(ast.BRIEOptionType),
  4407. UintValue: value,
  4408. }
  4409. }
  4410. | BRIEStringOptionName EqOpt stringLit
  4411. {
  4412. $$ = &ast.BRIEOption{
  4413. Tp: $1.(ast.BRIEOptionType),
  4414. StrValue: $3,
  4415. }
  4416. }
  4417. | BRIEKeywordOptionName EqOpt StringNameOrBRIEOptionKeyword
  4418. {
  4419. $$ = &ast.BRIEOption{
  4420. Tp: $1.(ast.BRIEOptionType),
  4421. StrValue: strings.ToLower($3),
  4422. }
  4423. }
  4424. | "SNAPSHOT" EqOpt LengthNum TimestampUnit "AGO"
  4425. {
  4426. unit, err := $4.(ast.TimeUnitType).Duration()
  4427. if err != nil {
  4428. yylex.AppendError(err)
  4429. return 1
  4430. }
  4431. // TODO: check overflow?
  4432. $$ = &ast.BRIEOption{
  4433. Tp: ast.BRIEOptionBackupTimeAgo,
  4434. UintValue: $3.(uint64) * uint64(unit),
  4435. }
  4436. }
  4437. | "SNAPSHOT" EqOpt stringLit
  4438. // not including this into BRIEStringOptionName to avoid shift/reduce conflict
  4439. {
  4440. $$ = &ast.BRIEOption{
  4441. Tp: ast.BRIEOptionBackupTS,
  4442. StrValue: $3,
  4443. }
  4444. }
  4445. | "SNAPSHOT" EqOpt LengthNum
  4446. // not including this into BRIEIntegerOptionName to avoid shift/reduce conflict
  4447. {
  4448. $$ = &ast.BRIEOption{
  4449. Tp: ast.BRIEOptionBackupTSO,
  4450. UintValue: $3.(uint64),
  4451. }
  4452. }
  4453. | "LAST_BACKUP" EqOpt stringLit
  4454. {
  4455. $$ = &ast.BRIEOption{
  4456. Tp: ast.BRIEOptionLastBackupTS,
  4457. StrValue: $3,
  4458. }
  4459. }
  4460. | "LAST_BACKUP" EqOpt LengthNum
  4461. {
  4462. $$ = &ast.BRIEOption{
  4463. Tp: ast.BRIEOptionLastBackupTSO,
  4464. UintValue: $3.(uint64),
  4465. }
  4466. }
  4467. | "RATE_LIMIT" EqOpt LengthNum "MB" '/' "SECOND"
  4468. {
  4469. // TODO: check overflow?
  4470. $$ = &ast.BRIEOption{
  4471. Tp: ast.BRIEOptionRateLimit,
  4472. UintValue: $3.(uint64) * 1048576,
  4473. }
  4474. }
  4475. | "CSV_HEADER" EqOpt FieldsOrColumns
  4476. {
  4477. $$ = &ast.BRIEOption{
  4478. Tp: ast.BRIEOptionCSVHeader,
  4479. UintValue: ast.BRIECSVHeaderIsColumns,
  4480. }
  4481. }
  4482. | "CSV_HEADER" EqOpt LengthNum
  4483. {
  4484. $$ = &ast.BRIEOption{
  4485. Tp: ast.BRIEOptionCSVHeader,
  4486. UintValue: $3.(uint64),
  4487. }
  4488. }
  4489. | "CHECKSUM" EqOpt Boolean
  4490. {
  4491. value := uint64(0)
  4492. if $3.(bool) {
  4493. value = 1
  4494. }
  4495. $$ = &ast.BRIEOption{
  4496. Tp: ast.BRIEOptionChecksum,
  4497. UintValue: value,
  4498. }
  4499. }
  4500. | "CHECKSUM" EqOpt OptionLevel
  4501. {
  4502. $$ = &ast.BRIEOption{
  4503. Tp: ast.BRIEOptionChecksum,
  4504. UintValue: uint64($3.(ast.BRIEOptionLevel)),
  4505. }
  4506. }
  4507. | "ANALYZE" EqOpt Boolean
  4508. {
  4509. value := uint64(0)
  4510. if $3.(bool) {
  4511. value = 1
  4512. }
  4513. $$ = &ast.BRIEOption{
  4514. Tp: ast.BRIEOptionAnalyze,
  4515. UintValue: value,
  4516. }
  4517. }
  4518. | "ANALYZE" EqOpt OptionLevel
  4519. {
  4520. $$ = &ast.BRIEOption{
  4521. Tp: ast.BRIEOptionAnalyze,
  4522. UintValue: uint64($3.(ast.BRIEOptionLevel)),
  4523. }
  4524. }
  4525. LengthNum:
  4526. NUM
  4527. {
  4528. $$ = getUint64FromNUM($1)
  4529. }
  4530. Int64Num:
  4531. NUM
  4532. {
  4533. v, rangeErrMsg := getInt64FromNUM($1)
  4534. if len(rangeErrMsg) != 0 {
  4535. yylex.AppendError(yylex.Errorf(rangeErrMsg))
  4536. return 1
  4537. }
  4538. $$ = v
  4539. }
  4540. NUM:
  4541. intLit
  4542. Boolean:
  4543. NUM
  4544. {
  4545. $$ = $1.(int64) != 0
  4546. }
  4547. | "FALSE"
  4548. {
  4549. $$ = false
  4550. }
  4551. | "TRUE"
  4552. {
  4553. $$ = true
  4554. }
  4555. OptionLevel:
  4556. "OFF"
  4557. {
  4558. $$ = ast.BRIEOptionLevelOff
  4559. }
  4560. | "OPTIONAL"
  4561. {
  4562. $$ = ast.BRIEOptionLevelOptional
  4563. }
  4564. | "REQUIRED"
  4565. {
  4566. $$ = ast.BRIEOptionLevelRequired
  4567. }
  4568. PurgeImportStmt:
  4569. "PURGE" "IMPORT" NUM
  4570. {
  4571. $$ = &ast.PurgeImportStmt{TaskID: getUint64FromNUM($3)}
  4572. }
  4573. /*******************************************************************
  4574. * import statements
  4575. *
  4576. * CREATE IMPORT [IF NOT EXISTS] import_name
  4577. * FROM data_location [REPLACE | SKIP {ALL | CONSTRAINT | DUPLICATE | STRICT}]
  4578. * [options_list]
  4579. * STOP IMPORT [IF RUNNING] import_name
  4580. * RESUME IMPORT [IF NOT RUNNING] import_name
  4581. * ALTER IMPORT import_name
  4582. * [REPLACE | SKIP {ALL | CONSTRAINT | DUPLICATE | STRICT}]
  4583. * [options_list]
  4584. * [TRUNCATE
  4585. * {ALL | ERRORS} [TABLE table_name [, table_name] ...]
  4586. * ]
  4587. * DROP IMPORT [IF EXISTS] import_name
  4588. * SHOW IMPORT import_name [ERRORS] [TABLE table_name [, table_name] ...]
  4589. */
  4590. CreateImportStmt:
  4591. "CREATE" "IMPORT" IfNotExists Identifier "FROM" stringLit ErrorHandling BRIEOptions
  4592. {
  4593. $$ = &ast.CreateImportStmt{
  4594. IfNotExists: $3.(bool),
  4595. Name: $4,
  4596. Storage: $6,
  4597. ErrorHandling: $7.(ast.ErrorHandlingOption),
  4598. Options: $8.([]*ast.BRIEOption),
  4599. }
  4600. }
  4601. StopImportStmt:
  4602. "STOP" "IMPORT" IfRunning Identifier
  4603. {
  4604. $$ = &ast.StopImportStmt{
  4605. IfRunning: $3.(bool),
  4606. Name: $4,
  4607. }
  4608. }
  4609. ResumeImportStmt:
  4610. "RESUME" "IMPORT" IfNotRunning Identifier
  4611. {
  4612. $$ = &ast.ResumeImportStmt{
  4613. IfNotRunning: $3.(bool),
  4614. Name: $4,
  4615. }
  4616. }
  4617. AlterImportStmt:
  4618. "ALTER" "IMPORT" Identifier ErrorHandling BRIEOptions ImportTruncate
  4619. {
  4620. s := &ast.AlterImportStmt{
  4621. Name: $3,
  4622. ErrorHandling: $4.(ast.ErrorHandlingOption),
  4623. Options: $5.([]*ast.BRIEOption),
  4624. }
  4625. if $6 != nil {
  4626. s.Truncate = $6.(*ast.ImportTruncate)
  4627. }
  4628. $$ = s
  4629. }
  4630. DropImportStmt:
  4631. "DROP" "IMPORT" IfExists Identifier
  4632. {
  4633. $$ = &ast.DropImportStmt{
  4634. IfExists: $3.(bool),
  4635. Name: $4,
  4636. }
  4637. }
  4638. ShowImportStmt:
  4639. "SHOW" "IMPORT" Identifier OptErrors TableNameListOpt2
  4640. {
  4641. $$ = &ast.ShowImportStmt{
  4642. Name: $3,
  4643. ErrorsOnly: $4.(bool),
  4644. TableNames: $5.([]*ast.TableName),
  4645. }
  4646. }
  4647. IfRunning:
  4648. {
  4649. $$ = false
  4650. }
  4651. | "IF" "RUNNING"
  4652. {
  4653. $$ = true
  4654. }
  4655. IfNotRunning:
  4656. {
  4657. $$ = false
  4658. }
  4659. | "IF" NotSym "RUNNING"
  4660. {
  4661. $$ = true
  4662. }
  4663. OptErrors:
  4664. {
  4665. $$ = false
  4666. }
  4667. | "ERRORS"
  4668. {
  4669. $$ = true
  4670. }
  4671. ErrorHandling:
  4672. {
  4673. $$ = ast.ErrorHandleError
  4674. }
  4675. | "REPLACE"
  4676. {
  4677. $$ = ast.ErrorHandleReplace
  4678. }
  4679. | "SKIP" "ALL"
  4680. {
  4681. $$ = ast.ErrorHandleSkipAll
  4682. }
  4683. | "SKIP" "CONSTRAINT"
  4684. {
  4685. $$ = ast.ErrorHandleSkipConstraint
  4686. }
  4687. | "SKIP" "DUPLICATE"
  4688. {
  4689. $$ = ast.ErrorHandleSkipDuplicate
  4690. }
  4691. | "SKIP" "STRICT"
  4692. {
  4693. $$ = ast.ErrorHandleSkipStrict
  4694. }
  4695. ImportTruncate:
  4696. {
  4697. $$ = nil
  4698. }
  4699. | "TRUNCATE" "ALL" TableNameListOpt2
  4700. {
  4701. $$ = &ast.ImportTruncate{
  4702. IsErrorsOnly: false,
  4703. TableNames: $3.([]*ast.TableName),
  4704. }
  4705. }
  4706. | "TRUNCATE" "ERRORS" TableNameListOpt2
  4707. {
  4708. $$ = &ast.ImportTruncate{
  4709. IsErrorsOnly: true,
  4710. TableNames: $3.([]*ast.TableName),
  4711. }
  4712. }
  4713. Expression:
  4714. singleAtIdentifier assignmentEq Expression %prec assignmentEq
  4715. {
  4716. v := $1
  4717. v = strings.TrimPrefix(v, "@")
  4718. $$ = &ast.VariableExpr{
  4719. Name: v,
  4720. IsGlobal: false,
  4721. IsSystem: false,
  4722. Value: $3,
  4723. }
  4724. }
  4725. | Expression logOr Expression %prec pipes
  4726. {
  4727. $$ = &ast.BinaryOperationExpr{Op: opcode.LogicOr, L: $1, R: $3}
  4728. }
  4729. | Expression "XOR" Expression %prec xor
  4730. {
  4731. $$ = &ast.BinaryOperationExpr{Op: opcode.LogicXor, L: $1, R: $3}
  4732. }
  4733. | Expression logAnd Expression %prec andand
  4734. {
  4735. $$ = &ast.BinaryOperationExpr{Op: opcode.LogicAnd, L: $1, R: $3}
  4736. }
  4737. | "NOT" Expression %prec not
  4738. {
  4739. expr, ok := $2.(*ast.ExistsSubqueryExpr)
  4740. if ok {
  4741. expr.Not = true
  4742. $$ = $2
  4743. } else {
  4744. $$ = &ast.UnaryOperationExpr{Op: opcode.Not, V: $2}
  4745. }
  4746. }
  4747. | "MATCH" '(' ColumnNameList ')' "AGAINST" '(' BitExpr FulltextSearchModifierOpt ')'
  4748. {
  4749. $$ = &ast.MatchAgainst{
  4750. ColumnNames: $3.([]*ast.ColumnName),
  4751. Against: $7,
  4752. Modifier: ast.FulltextSearchModifier($8.(int)),
  4753. }
  4754. }
  4755. | BoolPri IsOrNotOp trueKwd %prec is
  4756. {
  4757. $$ = &ast.IsTruthExpr{Expr: $1, Not: !$2.(bool), True: int64(1)}
  4758. }
  4759. | BoolPri IsOrNotOp falseKwd %prec is
  4760. {
  4761. $$ = &ast.IsTruthExpr{Expr: $1, Not: !$2.(bool), True: int64(0)}
  4762. }
  4763. | BoolPri IsOrNotOp "UNKNOWN" %prec is
  4764. {
  4765. /* https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_is */
  4766. $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)}
  4767. }
  4768. | BoolPri
  4769. MaxValueOrExpression:
  4770. "MAXVALUE"
  4771. {
  4772. $$ = &ast.MaxValueExpr{}
  4773. }
  4774. | BitExpr
  4775. FulltextSearchModifierOpt:
  4776. /* empty */
  4777. {
  4778. $$ = ast.FulltextSearchModifierNaturalLanguageMode
  4779. }
  4780. | "IN" "NATURAL" "LANGUAGE" "MODE"
  4781. {
  4782. $$ = ast.FulltextSearchModifierNaturalLanguageMode
  4783. }
  4784. | "IN" "NATURAL" "LANGUAGE" "MODE" "WITH" "QUERY" "EXPANSION"
  4785. {
  4786. $$ = ast.FulltextSearchModifierNaturalLanguageMode | ast.FulltextSearchModifierWithQueryExpansion
  4787. }
  4788. | "IN" "BOOLEAN" "MODE"
  4789. {
  4790. $$ = ast.FulltextSearchModifierBooleanMode
  4791. }
  4792. | "WITH" "QUERY" "EXPANSION"
  4793. {
  4794. $$ = ast.FulltextSearchModifierWithQueryExpansion
  4795. }
  4796. logOr:
  4797. pipesAsOr
  4798. | "OR"
  4799. logAnd:
  4800. "&&"
  4801. | "AND"
  4802. ExpressionList:
  4803. Expression
  4804. {
  4805. $$ = []ast.ExprNode{$1}
  4806. }
  4807. | ExpressionList ',' Expression
  4808. {
  4809. $$ = append($1.([]ast.ExprNode), $3)
  4810. }
  4811. MaxValueOrExpressionList:
  4812. MaxValueOrExpression
  4813. {
  4814. $$ = []ast.ExprNode{$1}
  4815. }
  4816. | MaxValueOrExpressionList ',' MaxValueOrExpression
  4817. {
  4818. $$ = append($1.([]ast.ExprNode), $3)
  4819. }
  4820. ExpressionListOpt:
  4821. {
  4822. $$ = []ast.ExprNode{}
  4823. }
  4824. | ExpressionList
  4825. FuncDatetimePrecListOpt:
  4826. {
  4827. $$ = []ast.ExprNode{}
  4828. }
  4829. | FuncDatetimePrecList
  4830. FuncDatetimePrecList:
  4831. intLit
  4832. {
  4833. expr := ast.NewValueExpr($1, parser.charset, parser.collation)
  4834. $$ = []ast.ExprNode{expr}
  4835. }
  4836. BoolPri:
  4837. BoolPri IsOrNotOp "NULL" %prec is
  4838. {
  4839. $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)}
  4840. }
  4841. | BoolPri CompareOp PredicateExpr %prec eq
  4842. {
  4843. $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: $3}
  4844. }
  4845. | BoolPri CompareOp AnyOrAll SubSelect %prec eq
  4846. {
  4847. sq := $4.(*ast.SubqueryExpr)
  4848. sq.MultiRows = true
  4849. $$ = &ast.CompareSubqueryExpr{Op: $2.(opcode.Op), L: $1, R: sq, All: $3.(bool)}
  4850. }
  4851. | BoolPri CompareOp singleAtIdentifier assignmentEq PredicateExpr %prec assignmentEq
  4852. {
  4853. v := $3
  4854. v = strings.TrimPrefix(v, "@")
  4855. variable := &ast.VariableExpr{
  4856. Name: v,
  4857. IsGlobal: false,
  4858. IsSystem: false,
  4859. Value: $5,
  4860. }
  4861. $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: variable}
  4862. }
  4863. | PredicateExpr
  4864. CompareOp:
  4865. ">="
  4866. {
  4867. $$ = opcode.GE
  4868. }
  4869. | '>'
  4870. {
  4871. $$ = opcode.GT
  4872. }
  4873. | "<="
  4874. {
  4875. $$ = opcode.LE
  4876. }
  4877. | '<'
  4878. {
  4879. $$ = opcode.LT
  4880. }
  4881. | "!="
  4882. {
  4883. $$ = opcode.NE
  4884. }
  4885. | "<>"
  4886. {
  4887. $$ = opcode.NE
  4888. }
  4889. | "="
  4890. {
  4891. $$ = opcode.EQ
  4892. }
  4893. | "<=>"
  4894. {
  4895. $$ = opcode.NullEQ
  4896. }
  4897. BetweenOrNotOp:
  4898. "BETWEEN"
  4899. {
  4900. $$ = true
  4901. }
  4902. | NotSym "BETWEEN"
  4903. {
  4904. $$ = false
  4905. }
  4906. IsOrNotOp:
  4907. "IS"
  4908. {
  4909. $$ = true
  4910. }
  4911. | "IS" NotSym
  4912. {
  4913. $$ = false
  4914. }
  4915. InOrNotOp:
  4916. "IN"
  4917. {
  4918. $$ = true
  4919. }
  4920. | NotSym "IN"
  4921. {
  4922. $$ = false
  4923. }
  4924. LikeOrNotOp:
  4925. "LIKE"
  4926. {
  4927. $$ = true
  4928. }
  4929. | NotSym "LIKE"
  4930. {
  4931. $$ = false
  4932. }
  4933. RegexpOrNotOp:
  4934. RegexpSym
  4935. {
  4936. $$ = true
  4937. }
  4938. | NotSym RegexpSym
  4939. {
  4940. $$ = false
  4941. }
  4942. AnyOrAll:
  4943. "ANY"
  4944. {
  4945. $$ = false
  4946. }
  4947. | "SOME"
  4948. {
  4949. $$ = false
  4950. }
  4951. | "ALL"
  4952. {
  4953. $$ = true
  4954. }
  4955. PredicateExpr:
  4956. BitExpr InOrNotOp '(' ExpressionList ')'
  4957. {
  4958. $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), List: $4.([]ast.ExprNode)}
  4959. }
  4960. | BitExpr InOrNotOp SubSelect
  4961. {
  4962. sq := $3.(*ast.SubqueryExpr)
  4963. sq.MultiRows = true
  4964. $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), Sel: sq}
  4965. }
  4966. | BitExpr BetweenOrNotOp BitExpr "AND" PredicateExpr
  4967. {
  4968. $$ = &ast.BetweenExpr{
  4969. Expr: $1,
  4970. Left: $3,
  4971. Right: $5,
  4972. Not: !$2.(bool),
  4973. }
  4974. }
  4975. | BitExpr LikeOrNotOp SimpleExpr LikeEscapeOpt
  4976. {
  4977. escape := $4
  4978. if len(escape) > 1 {
  4979. yylex.AppendError(ErrWrongArguments.GenWithStackByArgs("ESCAPE"))
  4980. return 1
  4981. } else if len(escape) == 0 {
  4982. escape = "\\"
  4983. }
  4984. $$ = &ast.PatternLikeExpr{
  4985. Expr: $1,
  4986. Pattern: $3,
  4987. Not: !$2.(bool),
  4988. Escape: escape[0],
  4989. }
  4990. }
  4991. | BitExpr RegexpOrNotOp SimpleExpr
  4992. {
  4993. $$ = &ast.PatternRegexpExpr{Expr: $1, Pattern: $3, Not: !$2.(bool)}
  4994. }
  4995. | BitExpr
  4996. RegexpSym:
  4997. "REGEXP"
  4998. | "RLIKE"
  4999. LikeEscapeOpt:
  5000. %prec empty
  5001. {
  5002. $$ = "\\"
  5003. }
  5004. | "ESCAPE" stringLit
  5005. {
  5006. $$ = $2
  5007. }
  5008. Field:
  5009. '*'
  5010. {
  5011. $$ = &ast.SelectField{WildCard: &ast.WildCardField{}}
  5012. }
  5013. | Identifier '.' '*'
  5014. {
  5015. wildCard := &ast.WildCardField{Table: model.NewCIStr($1)}
  5016. $$ = &ast.SelectField{WildCard: wildCard}
  5017. }
  5018. | Identifier '.' Identifier '.' '*'
  5019. {
  5020. wildCard := &ast.WildCardField{Schema: model.NewCIStr($1), Table: model.NewCIStr($3)}
  5021. $$ = &ast.SelectField{WildCard: wildCard}
  5022. }
  5023. | Expression FieldAsNameOpt
  5024. {
  5025. expr := $1
  5026. asName := $2
  5027. $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)}
  5028. }
  5029. | '{' Identifier Expression '}' FieldAsNameOpt
  5030. {
  5031. /*
  5032. * ODBC escape syntax.
  5033. * See https://dev.mysql.com/doc/refman/5.7/en/expressions.html
  5034. */
  5035. expr := $3
  5036. asName := $5
  5037. $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)}
  5038. }
  5039. FieldAsNameOpt:
  5040. /* EMPTY */
  5041. {
  5042. $$ = ""
  5043. }
  5044. | FieldAsName
  5045. FieldAsName:
  5046. Identifier
  5047. | "AS" Identifier
  5048. {
  5049. $$ = $2
  5050. }
  5051. | stringLit
  5052. | "AS" stringLit
  5053. {
  5054. $$ = $2
  5055. }
  5056. FieldList:
  5057. Field
  5058. {
  5059. field := $1.(*ast.SelectField)
  5060. field.Offset = parser.startOffset(&yyS[yypt])
  5061. $$ = []*ast.SelectField{field}
  5062. }
  5063. | FieldList ',' Field
  5064. {
  5065. fl := $1.([]*ast.SelectField)
  5066. last := fl[len(fl)-1]
  5067. if last.Expr != nil && last.AsName.O == "" {
  5068. lastEnd := parser.endOffset(&yyS[yypt-1])
  5069. last.SetText(parser.src[last.Offset:lastEnd])
  5070. }
  5071. newField := $3.(*ast.SelectField)
  5072. newField.Offset = parser.startOffset(&yyS[yypt])
  5073. $$ = append(fl, newField)
  5074. }
  5075. GroupByClause:
  5076. "GROUP" "BY" ByList
  5077. {
  5078. $$ = &ast.GroupByClause{Items: $3.([]*ast.ByItem)}
  5079. }
  5080. HavingClause:
  5081. {
  5082. $$ = nil
  5083. }
  5084. | "HAVING" Expression
  5085. {
  5086. $$ = &ast.HavingClause{Expr: $2}
  5087. }
  5088. IfExists:
  5089. {
  5090. $$ = false
  5091. }
  5092. | "IF" "EXISTS"
  5093. {
  5094. $$ = true
  5095. }
  5096. IfNotExists:
  5097. {
  5098. $$ = false
  5099. }
  5100. | "IF" NotSym "EXISTS"
  5101. {
  5102. $$ = true
  5103. }
  5104. IgnoreOptional:
  5105. {
  5106. $$ = false
  5107. }
  5108. | "IGNORE"
  5109. {
  5110. $$ = true
  5111. }
  5112. IndexName:
  5113. {
  5114. $$ = &ast.NullString{
  5115. String: "",
  5116. Empty: false,
  5117. }
  5118. }
  5119. | Identifier
  5120. {
  5121. $$ = &ast.NullString{
  5122. String: $1,
  5123. Empty: len($1) == 0,
  5124. }
  5125. }
  5126. IndexOptionList:
  5127. {
  5128. $$ = nil
  5129. }
  5130. | IndexOptionList IndexOption
  5131. {
  5132. // Merge the options
  5133. if $1 == nil {
  5134. $$ = $2
  5135. } else {
  5136. opt1 := $1.(*ast.IndexOption)
  5137. opt2 := $2.(*ast.IndexOption)
  5138. if len(opt2.Comment) > 0 {
  5139. opt1.Comment = opt2.Comment
  5140. } else if opt2.Tp != 0 {
  5141. opt1.Tp = opt2.Tp
  5142. } else if opt2.KeyBlockSize > 0 {
  5143. opt1.KeyBlockSize = opt2.KeyBlockSize
  5144. } else if len(opt2.ParserName.O) > 0 {
  5145. opt1.ParserName = opt2.ParserName
  5146. } else if opt2.Visibility != ast.IndexVisibilityDefault {
  5147. opt1.Visibility = opt2.Visibility
  5148. } else if opt2.PrimaryKeyTp != model.PrimaryKeyTypeDefault {
  5149. opt1.PrimaryKeyTp = opt2.PrimaryKeyTp
  5150. }
  5151. $$ = opt1
  5152. }
  5153. }
  5154. IndexOption:
  5155. "KEY_BLOCK_SIZE" EqOpt LengthNum
  5156. {
  5157. $$ = &ast.IndexOption{
  5158. KeyBlockSize: $3.(uint64),
  5159. }
  5160. }
  5161. | IndexType
  5162. {
  5163. $$ = &ast.IndexOption{
  5164. Tp: $1.(model.IndexType),
  5165. }
  5166. }
  5167. | "WITH" "PARSER" Identifier
  5168. {
  5169. $$ = &ast.IndexOption{
  5170. ParserName: model.NewCIStr($3),
  5171. }
  5172. yylex.AppendError(yylex.Errorf("The WITH PARASER clause is parsed but ignored by all storage engines."))
  5173. parser.lastErrorAsWarn()
  5174. }
  5175. | "COMMENT" stringLit
  5176. {
  5177. $$ = &ast.IndexOption{
  5178. Comment: $2,
  5179. }
  5180. }
  5181. | IndexInvisible
  5182. {
  5183. $$ = &ast.IndexOption{
  5184. Visibility: $1.(ast.IndexVisibility),
  5185. }
  5186. }
  5187. | WithClustered
  5188. {
  5189. $$ = &ast.IndexOption{
  5190. PrimaryKeyTp: $1.(model.PrimaryKeyType),
  5191. }
  5192. }
  5193. /*
  5194. See: https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L7179
  5195. The syntax for defining an index is:
  5196. ... INDEX [index_name] [USING|TYPE] <index_type> ...
  5197. The problem is that whereas USING is a reserved word, TYPE is not. We can
  5198. still handle it if an index name is supplied, i.e.:
  5199. ... INDEX type TYPE <index_type> ...
  5200. here the index's name is unmbiguously 'type', but for this:
  5201. ... INDEX TYPE <index_type> ...
  5202. it's impossible to know what this actually mean - is 'type' the name or the
  5203. type? For this reason we accept the TYPE syntax only if a name is supplied.
  5204. */
  5205. IndexNameAndTypeOpt:
  5206. IndexName
  5207. {
  5208. $$ = []interface{}{$1, nil}
  5209. }
  5210. | IndexName "USING" IndexTypeName
  5211. {
  5212. $$ = []interface{}{$1, $3}
  5213. }
  5214. | Identifier "TYPE" IndexTypeName
  5215. {
  5216. $$ = []interface{}{&ast.NullString{String: $1, Empty: len($1) == 0}, $3}
  5217. }
  5218. IndexTypeOpt:
  5219. {
  5220. $$ = nil
  5221. }
  5222. | IndexType
  5223. IndexType:
  5224. "USING" IndexTypeName
  5225. {
  5226. $$ = $2
  5227. }
  5228. | "TYPE" IndexTypeName
  5229. {
  5230. $$ = $2
  5231. }
  5232. IndexTypeName:
  5233. "BTREE"
  5234. {
  5235. $$ = model.IndexTypeBtree
  5236. }
  5237. | "HASH"
  5238. {
  5239. $$ = model.IndexTypeHash
  5240. }
  5241. | "RTREE"
  5242. {
  5243. $$ = model.IndexTypeRtree
  5244. }
  5245. IndexInvisible:
  5246. "VISIBLE"
  5247. {
  5248. $$ = ast.IndexVisibilityVisible
  5249. }
  5250. | "INVISIBLE"
  5251. {
  5252. $$ = ast.IndexVisibilityInvisible
  5253. }
  5254. /**********************************Identifier********************************************/
  5255. Identifier:
  5256. identifier
  5257. | UnReservedKeyword
  5258. | NotKeywordToken
  5259. | TiDBKeyword
  5260. UnReservedKeyword:
  5261. "ACTION"
  5262. | "ADVISE"
  5263. | "ASCII"
  5264. | "AUTO_ID_CACHE"
  5265. | "AUTO_INCREMENT"
  5266. | "AFTER"
  5267. | "ALWAYS"
  5268. | "AVG"
  5269. | "BEGIN"
  5270. | "BIT"
  5271. | "BOOL"
  5272. | "BOOLEAN"
  5273. | "BTREE"
  5274. | "BYTE"
  5275. | "CAPTURE"
  5276. | "CAUSAL"
  5277. | "CLEANUP"
  5278. | "CHAIN"
  5279. | "CHARSET"
  5280. | "COLUMNS"
  5281. | "CONFIG"
  5282. | "SAN"
  5283. | "COMMIT"
  5284. | "COMPACT"
  5285. | "COMPRESSED"
  5286. | "CONSISTENCY"
  5287. | "CONSISTENT"
  5288. | "CURRENT"
  5289. | "DATA"
  5290. | "DATE" %prec lowerThanStringLitToken
  5291. | "DATETIME"
  5292. | "DAY"
  5293. | "DEALLOCATE"
  5294. | "DO"
  5295. | "DUPLICATE"
  5296. | "DYNAMIC"
  5297. | "ENCRYPTION"
  5298. | "END"
  5299. | "ENFORCED"
  5300. | "ENGINE"
  5301. | "ENGINES"
  5302. | "ENUM"
  5303. | "ERROR"
  5304. | "ERRORS"
  5305. | "ESCAPE"
  5306. | "EVOLVE"
  5307. | "EXECUTE"
  5308. | "EXTENDED"
  5309. | "FIELDS"
  5310. | "FILE"
  5311. | "FIRST"
  5312. | "FIXED"
  5313. | "FLUSH"
  5314. | "FOLLOWING"
  5315. | "FORMAT"
  5316. | "FULL"
  5317. | "GENERAL"
  5318. | "GLOBAL"
  5319. | "HASH"
  5320. | "HOUR"
  5321. | "INSERT_METHOD"
  5322. | "LESS"
  5323. | "LOCAL"
  5324. | "LAST"
  5325. | "NAMES"
  5326. | "NVARCHAR"
  5327. | "OFFSET"
  5328. | "PACK_KEYS"
  5329. | "PARSER"
  5330. | "PASSWORD" %prec lowerThanEq
  5331. | "PREPARE"
  5332. | "PRE_SPLIT_REGIONS"
  5333. | "PROXY"
  5334. | "QUICK"
  5335. | "REBUILD"
  5336. | "REDUNDANT"
  5337. | "REORGANIZE"
  5338. | "RESTART"
  5339. | "ROLE"
  5340. | "ROLLBACK"
  5341. | "SESSION"
  5342. | "SIGNED"
  5343. | "SHARD_ROW_ID_BITS"
  5344. | "SHUTDOWN"
  5345. | "SNAPSHOT"
  5346. | "START"
  5347. | "STATUS"
  5348. | "OPEN"
  5349. | "SUBPARTITIONS"
  5350. | "SUBPARTITION"
  5351. | "TABLES"
  5352. | "TABLESPACE"
  5353. | "TEXT"
  5354. | "THAN"
  5355. | "TIME" %prec lowerThanStringLitToken
  5356. | "TIMESTAMP" %prec lowerThanStringLitToken
  5357. | "TRACE"
  5358. | "TRANSACTION"
  5359. | "TRUNCATE"
  5360. | "UNBOUNDED"
  5361. | "UNKNOWN"
  5362. | "VALUE" %prec lowerThanValueKeyword
  5363. | "WARNINGS"
  5364. | "YEAR"
  5365. | "MODE"
  5366. | "WEEK"
  5367. | "WEIGHT_STRING"
  5368. | "ANY"
  5369. | "SOME"
  5370. | "USER"
  5371. | "IDENTIFIED"
  5372. | "COLLATION"
  5373. | "COMMENT"
  5374. | "AVG_ROW_LENGTH"
  5375. | "CONNECTION"
  5376. | "CHECKSUM"
  5377. | "COMPRESSION"
  5378. | "KEY_BLOCK_SIZE"
  5379. | "MASTER"
  5380. | "MAX_ROWS"
  5381. | "MIN_ROWS"
  5382. | "NATIONAL"
  5383. | "NCHAR"
  5384. | "ROW_FORMAT"
  5385. | "QUARTER"
  5386. | "GRANTS"
  5387. | "TRIGGERS"
  5388. | "DELAY_KEY_WRITE"
  5389. | "ISOLATION"
  5390. | "JSON"
  5391. | "REPEATABLE"
  5392. | "RESPECT"
  5393. | "COMMITTED"
  5394. | "UNCOMMITTED"
  5395. | "ONLY"
  5396. | "SERIAL"
  5397. | "SERIALIZABLE"
  5398. | "LEVEL"
  5399. | "VARIABLES"
  5400. | "SQL_CACHE"
  5401. | "INDEXES"
  5402. | "PROCESSLIST"
  5403. | "SQL_NO_CACHE"
  5404. | "DISABLE"
  5405. | "ENABLE"
  5406. | "REVERSE"
  5407. | "PRIVILEGES"
  5408. | "NO"
  5409. | "BINLOG"
  5410. | "FUNCTION"
  5411. | "VIEW"
  5412. | "BINDING"
  5413. | "BINDINGS"
  5414. | "MODIFY"
  5415. | "EVENTS"
  5416. | "PARTITIONS"
  5417. | "NONE"
  5418. | "NULLS"
  5419. | "SUPER"
  5420. | "EXCLUSIVE"
  5421. | "STATS_PERSISTENT"
  5422. | "STATS_AUTO_RECALC"
  5423. | "ROW_COUNT"
  5424. | "COALESCE"
  5425. | "MONTH"
  5426. | "PROCESS"
  5427. | "PROFILE"
  5428. | "PROFILES"
  5429. | "MICROSECOND"
  5430. | "MINUTE"
  5431. | "PLUGINS"
  5432. | "PRECEDING"
  5433. | "QUERY"
  5434. | "QUERIES"
  5435. | "SECOND"
  5436. | "SEPARATOR"
  5437. | "SHARE"
  5438. | "SHARED"
  5439. | "SLOW"
  5440. | "MAX_CONNECTIONS_PER_HOUR"
  5441. | "MAX_QUERIES_PER_HOUR"
  5442. | "MAX_UPDATES_PER_HOUR"
  5443. | "MAX_USER_CONNECTIONS"
  5444. | "REPLICATION"
  5445. | "CLIENT"
  5446. | "SLAVE"
  5447. | "RELOAD"
  5448. | "TEMPORARY"
  5449. | "ROUTINE"
  5450. | "EVENT"
  5451. | "ALGORITHM"
  5452. | "DEFINER"
  5453. | "INVOKER"
  5454. | "MERGE"
  5455. | "TEMPTABLE"
  5456. | "UNDEFINED"
  5457. | "SECURITY"
  5458. | "CASCADED"
  5459. | "RECOVER"
  5460. | "CIPHER"
  5461. | "SUBJECT"
  5462. | "ISSUER"
  5463. | "X509"
  5464. | "NEVER"
  5465. | "EXPIRE"
  5466. | "ACCOUNT"
  5467. | "INCREMENTAL"
  5468. | "CPU"
  5469. | "MEMORY"
  5470. | "BLOCK"
  5471. | "IO"
  5472. | "CONTEXT"
  5473. | "SWITCHES"
  5474. | "PAGE"
  5475. | "FAULTS"
  5476. | "IPC"
  5477. | "SWAPS"
  5478. | "SOURCE"
  5479. | "TRADITIONAL"
  5480. | "SQL_BUFFER_RESULT"
  5481. | "DIRECTORY"
  5482. | "HISTOGRAM"
  5483. | "HISTORY"
  5484. | "LIST"
  5485. | "NODEGROUP"
  5486. | "SYSTEM_TIME"
  5487. | "PARTIAL"
  5488. | "SIMPLE"
  5489. | "REMOVE"
  5490. | "PARTITIONING"
  5491. | "STORAGE"
  5492. | "DISK"
  5493. | "STATS_SAMPLE_PAGES"
  5494. | "SECONDARY_ENGINE"
  5495. | "SECONDARY_LOAD"
  5496. | "SECONDARY_UNLOAD"
  5497. | "VALIDATION"
  5498. | "WITHOUT"
  5499. | "RTREE"
  5500. | "EXCHANGE"
  5501. | "COLUMN_FORMAT"
  5502. | "REPAIR"
  5503. | "IMPORT"
  5504. | "IMPORTS"
  5505. | "DISCARD"
  5506. | "TABLE_CHECKSUM"
  5507. | "UNICODE"
  5508. | "AUTO_RANDOM"
  5509. | "AUTO_RANDOM_BASE"
  5510. | "SQL_TSI_DAY"
  5511. | "SQL_TSI_HOUR"
  5512. | "SQL_TSI_MINUTE"
  5513. | "SQL_TSI_MONTH"
  5514. | "SQL_TSI_QUARTER"
  5515. | "SQL_TSI_SECOND"
  5516. | "LANGUAGE"
  5517. | "SQL_TSI_WEEK"
  5518. | "SQL_TSI_YEAR"
  5519. | "INVISIBLE"
  5520. | "VISIBLE"
  5521. | "TYPE"
  5522. | "NOWAIT"
  5523. | "INSTANCE"
  5524. | "REPLICA"
  5525. | "LOCATION"
  5526. | "LABELS"
  5527. | "LOGS"
  5528. | "HOSTS"
  5529. | "AGAINST"
  5530. | "EXPANSION"
  5531. | "INCREMENT"
  5532. | "MINVALUE"
  5533. | "NOMAXVALUE"
  5534. | "NOMINVALUE"
  5535. | "NOCACHE"
  5536. | "CACHE"
  5537. | "CYCLE"
  5538. | "NOCYCLE"
  5539. | "SEQUENCE"
  5540. | "MAX_MINUTES"
  5541. | "MAX_IDXNUM"
  5542. | "PER_TABLE"
  5543. | "PER_DB"
  5544. | "NEXT"
  5545. | "NEXTVAL"
  5546. | "LASTVAL"
  5547. | "SETVAL"
  5548. | "AGO"
  5549. | "BACKUP"
  5550. | "BACKUPS"
  5551. | "CONCURRENCY"
  5552. | "MB"
  5553. | "ONLINE"
  5554. | "RATE_LIMIT"
  5555. | "RESTORE"
  5556. | "RESTORES"
  5557. | "SEND_CREDENTIALS_TO_TIKV"
  5558. | "LAST_BACKUP"
  5559. | "CHECKPOINT"
  5560. | "SKIP_SCHEMA_FILES"
  5561. | "STRICT_FORMAT"
  5562. | "BACKEND"
  5563. | "CSV_BACKSLASH_ESCAPE"
  5564. | "CSV_NOT_NULL"
  5565. | "CSV_TRIM_LAST_SEPARATORS"
  5566. | "CSV_DELIMITER"
  5567. | "CSV_HEADER"
  5568. | "CSV_NULL"
  5569. | "CSV_SEPARATOR"
  5570. | "ON_DUPLICATE"
  5571. | "TIKV_IMPORTER"
  5572. | "CONSTRAINTS"
  5573. | "REPLICAS"
  5574. | "POLICY"
  5575. | "WAIT"
  5576. | "CLIENT_ERRORS_SUMMARY"
  5577. | "BERNOULLI"
  5578. | "SYSTEM"
  5579. | "PERCENT"
  5580. | "RESUME"
  5581. | "OFF"
  5582. | "OPTIONAL"
  5583. | "REQUIRED"
  5584. | "PURGE"
  5585. | "SKIP"
  5586. | "LOCKED"
  5587. | "CLUSTERED"
  5588. | "NONCLUSTERED"
  5589. TiDBKeyword:
  5590. "ADMIN"
  5591. | "BUCKETS"
  5592. | "BUILTINS"
  5593. | "CANCEL"
  5594. | "CARDINALITY"
  5595. | "CMSKETCH"
  5596. | "CORRELATION"
  5597. | "DDL"
  5598. | "DEPENDENCY"
  5599. | "DEPTH"
  5600. | "DRAINER"
  5601. | "JOBS"
  5602. | "JOB"
  5603. | "NODE_ID"
  5604. | "NODE_STATE"
  5605. | "PUMP"
  5606. | "SAMPLES"
  5607. | "STATISTICS"
  5608. | "STATS"
  5609. | "STATS_META"
  5610. | "STATS_HISTOGRAMS"
  5611. | "STATS_TOPN"
  5612. | "STATS_BUCKETS"
  5613. | "STATS_HEALTHY"
  5614. | "TELEMETRY"
  5615. | "TELEMETRY_ID"
  5616. | "TIDB"
  5617. | "TIFLASH"
  5618. | "TOPN"
  5619. | "SPLIT"
  5620. | "OPTIMISTIC"
  5621. | "PESSIMISTIC"
  5622. | "WIDTH"
  5623. | "REGIONS"
  5624. | "REGION"
  5625. | "RESET"
  5626. NotKeywordToken:
  5627. "ADDDATE"
  5628. | "APPROX_COUNT_DISTINCT"
  5629. | "APPROX_PERCENTILE"
  5630. | "BIT_AND"
  5631. | "BIT_OR"
  5632. | "BIT_XOR"
  5633. | "CAST"
  5634. | "COPY"
  5635. | "CURTIME"
  5636. | "DATE_ADD"
  5637. | "DATE_SUB"
  5638. | "EXTRACT"
  5639. | "GET_FORMAT"
  5640. | "GROUP_CONCAT"
  5641. | "INPLACE"
  5642. | "INSTANT"
  5643. | "INTERNAL"
  5644. | "MIN"
  5645. | "MAX"
  5646. | "NOW"
  5647. | "RECENT"
  5648. | "RUNNING"
  5649. | "POSITION"
  5650. | "S3"
  5651. | "STRICT"
  5652. | "SUBDATE"
  5653. | "SUBSTRING"
  5654. | "SUM"
  5655. | "STD"
  5656. | "STDDEV"
  5657. | "STDDEV_POP"
  5658. | "STDDEV_SAMP"
  5659. | "STOP"
  5660. | "VARIANCE"
  5661. | "VAR_POP"
  5662. | "VAR_SAMP"
  5663. | "TIMESTAMPADD"
  5664. | "TIMESTAMPDIFF"
  5665. | "TOKUDB_DEFAULT"
  5666. | "TOKUDB_FAST"
  5667. | "TOKUDB_LZMA"
  5668. | "TOKUDB_QUICKLZ"
  5669. | "TOKUDB_SNAPPY"
  5670. | "TOKUDB_SMALL"
  5671. | "TOKUDB_UNCOMPRESSED"
  5672. | "TOKUDB_ZLIB"
  5673. | "TOP"
  5674. | "TRIM"
  5675. | "NEXT_ROW_ID"
  5676. | "EXPR_PUSHDOWN_BLACKLIST"
  5677. | "OPT_RULE_BLACKLIST"
  5678. | "BOUND"
  5679. | "EXACT"
  5680. | "STALENESS"
  5681. | "STRONG"
  5682. | "FLASHBACK"
  5683. | "JSON_OBJECTAGG"
  5684. | "JSON_ARRAYAGG"
  5685. | "TLS"
  5686. | "FOLLOWER"
  5687. | "LEADER"
  5688. | "LEARNER"
  5689. | "VOTER"
  5690. /************************************************************************************
  5691. *
  5692. * Call Statements
  5693. *
  5694. **********************************************************************************/
  5695. CallStmt:
  5696. "CALL" ProcedureCall
  5697. {
  5698. $$ = &ast.CallStmt{
  5699. Procedure: $2.(*ast.FuncCallExpr),
  5700. }
  5701. }
  5702. ProcedureCall:
  5703. identifier
  5704. {
  5705. $$ = &ast.FuncCallExpr{
  5706. Tp: ast.FuncCallExprTypeGeneric,
  5707. FnName: model.NewCIStr($1),
  5708. Args: []ast.ExprNode{},
  5709. }
  5710. }
  5711. | Identifier '.' Identifier
  5712. {
  5713. $$ = &ast.FuncCallExpr{
  5714. Tp: ast.FuncCallExprTypeGeneric,
  5715. Schema: model.NewCIStr($1),
  5716. FnName: model.NewCIStr($3),
  5717. Args: []ast.ExprNode{},
  5718. }
  5719. }
  5720. | identifier '(' ExpressionListOpt ')'
  5721. {
  5722. $$ = &ast.FuncCallExpr{
  5723. Tp: ast.FuncCallExprTypeGeneric,
  5724. FnName: model.NewCIStr($1),
  5725. Args: $3.([]ast.ExprNode),
  5726. }
  5727. }
  5728. | Identifier '.' Identifier '(' ExpressionListOpt ')'
  5729. {
  5730. $$ = &ast.FuncCallExpr{
  5731. Tp: ast.FuncCallExprTypeGeneric,
  5732. Schema: model.NewCIStr($1),
  5733. FnName: model.NewCIStr($3),
  5734. Args: $5.([]ast.ExprNode),
  5735. }
  5736. }
  5737. /************************************************************************************
  5738. *
  5739. * Insert Statements
  5740. *
  5741. * TODO: support PARTITION
  5742. **********************************************************************************/
  5743. InsertIntoStmt:
  5744. "INSERT" TableOptimizerHintsOpt PriorityOpt IgnoreOptional IntoOpt TableName PartitionNameListOpt InsertValues OnDuplicateKeyUpdate
  5745. {
  5746. x := $8.(*ast.InsertStmt)
  5747. x.Priority = $3.(mysql.PriorityEnum)
  5748. x.IgnoreErr = $4.(bool)
  5749. // Wraps many layers here so that it can be processed the same way as select statement.
  5750. ts := &ast.TableSource{Source: $6.(*ast.TableName)}
  5751. x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}}
  5752. if $9 != nil {
  5753. x.OnDuplicate = $9.([]*ast.Assignment)
  5754. }
  5755. if $2 != nil {
  5756. x.TableHints = $2.([]*ast.TableOptimizerHint)
  5757. }
  5758. x.PartitionNames = $7.([]model.CIStr)
  5759. $$ = x
  5760. }
  5761. IntoOpt:
  5762. {}
  5763. | "INTO"
  5764. InsertValues:
  5765. '(' ColumnNameListOpt ')' ValueSym ValuesList
  5766. {
  5767. $$ = &ast.InsertStmt{
  5768. Columns: $2.([]*ast.ColumnName),
  5769. Lists: $5.([][]ast.ExprNode),
  5770. }
  5771. }
  5772. | '(' ColumnNameListOpt ')' SetOprStmt1
  5773. {
  5774. $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(ast.ResultSetNode)}
  5775. }
  5776. | ValueSym ValuesList %prec insertValues
  5777. {
  5778. $$ = &ast.InsertStmt{Lists: $2.([][]ast.ExprNode)}
  5779. }
  5780. | SetOprStmt1
  5781. {
  5782. $$ = &ast.InsertStmt{Select: $1.(ast.ResultSetNode)}
  5783. }
  5784. | "SET" ColumnSetValueList
  5785. {
  5786. $$ = &ast.InsertStmt{Setlist: $2.([]*ast.Assignment)}
  5787. }
  5788. ValueSym:
  5789. "VALUE"
  5790. | "VALUES"
  5791. ValuesList:
  5792. RowValue
  5793. {
  5794. $$ = [][]ast.ExprNode{$1.([]ast.ExprNode)}
  5795. }
  5796. | ValuesList ',' RowValue
  5797. {
  5798. $$ = append($1.([][]ast.ExprNode), $3.([]ast.ExprNode))
  5799. }
  5800. RowValue:
  5801. '(' ValuesOpt ')'
  5802. {
  5803. $$ = $2
  5804. }
  5805. ValuesOpt:
  5806. {
  5807. $$ = []ast.ExprNode{}
  5808. }
  5809. | Values
  5810. Values:
  5811. Values ',' ExprOrDefault
  5812. {
  5813. $$ = append($1.([]ast.ExprNode), $3)
  5814. }
  5815. | ExprOrDefault
  5816. {
  5817. $$ = []ast.ExprNode{$1}
  5818. }
  5819. ExprOrDefault:
  5820. Expression
  5821. | "DEFAULT"
  5822. {
  5823. $$ = &ast.DefaultExpr{}
  5824. }
  5825. ColumnSetValue:
  5826. ColumnName eq ExprOrDefault
  5827. {
  5828. $$ = &ast.Assignment{
  5829. Column: $1.(*ast.ColumnName),
  5830. Expr: $3,
  5831. }
  5832. }
  5833. ColumnSetValueList:
  5834. {
  5835. $$ = []*ast.Assignment{}
  5836. }
  5837. | ColumnSetValue
  5838. {
  5839. $$ = []*ast.Assignment{$1.(*ast.Assignment)}
  5840. }
  5841. | ColumnSetValueList ',' ColumnSetValue
  5842. {
  5843. $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment))
  5844. }
  5845. /*
  5846. * ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ...
  5847. * See https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
  5848. */
  5849. OnDuplicateKeyUpdate:
  5850. {
  5851. $$ = nil
  5852. }
  5853. | "ON" "DUPLICATE" "KEY" "UPDATE" AssignmentList
  5854. {
  5855. $$ = $5
  5856. }
  5857. /************************************************************************************
  5858. * Replace Statements
  5859. * See https://dev.mysql.com/doc/refman/5.7/en/replace.html
  5860. *
  5861. * TODO: support PARTITION
  5862. **********************************************************************************/
  5863. ReplaceIntoStmt:
  5864. "REPLACE" PriorityOpt IntoOpt TableName PartitionNameListOpt InsertValues
  5865. {
  5866. x := $6.(*ast.InsertStmt)
  5867. x.IsReplace = true
  5868. x.Priority = $2.(mysql.PriorityEnum)
  5869. ts := &ast.TableSource{Source: $4.(*ast.TableName)}
  5870. x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}}
  5871. x.PartitionNames = $5.([]model.CIStr)
  5872. $$ = x
  5873. }
  5874. ODBCDateTimeType:
  5875. "d"
  5876. {
  5877. $$ = ast.DateLiteral
  5878. }
  5879. | "t"
  5880. {
  5881. $$ = ast.TimeLiteral
  5882. }
  5883. | "ts"
  5884. {
  5885. $$ = ast.TimestampLiteral
  5886. }
  5887. Literal:
  5888. "FALSE"
  5889. {
  5890. $$ = ast.NewValueExpr(false, parser.charset, parser.collation)
  5891. }
  5892. | "NULL"
  5893. {
  5894. $$ = ast.NewValueExpr(nil, parser.charset, parser.collation)
  5895. }
  5896. | "TRUE"
  5897. {
  5898. $$ = ast.NewValueExpr(true, parser.charset, parser.collation)
  5899. }
  5900. | floatLit
  5901. {
  5902. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  5903. }
  5904. | decLit
  5905. {
  5906. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  5907. }
  5908. | intLit
  5909. {
  5910. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  5911. }
  5912. | StringLiteral %prec lowerThanStringLitToken
  5913. | "UNDERSCORE_CHARSET" stringLit
  5914. {
  5915. // See https://dev.mysql.com/doc/refman/5.7/en/charset-literal.html
  5916. co, err := charset.GetDefaultCollation($1)
  5917. if err != nil {
  5918. yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", $1))
  5919. return 1
  5920. }
  5921. expr := ast.NewValueExpr($2, parser.charset, parser.collation)
  5922. tp := expr.GetType()
  5923. tp.Charset = $1
  5924. tp.Collate = co
  5925. if tp.Collate == charset.CollationBin {
  5926. tp.Flag |= mysql.BinaryFlag
  5927. }
  5928. $$ = expr
  5929. }
  5930. | hexLit
  5931. {
  5932. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  5933. }
  5934. | bitLit
  5935. {
  5936. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  5937. }
  5938. | "UNDERSCORE_CHARSET" hexLit
  5939. {
  5940. co, err := charset.GetDefaultCollation($1)
  5941. if err != nil {
  5942. yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", $1))
  5943. return 1
  5944. }
  5945. expr := ast.NewValueExpr($2, parser.charset, parser.collation)
  5946. tp := expr.GetType()
  5947. tp.Charset = $1
  5948. tp.Collate = co
  5949. if tp.Collate == charset.CollationBin {
  5950. tp.Flag |= mysql.BinaryFlag
  5951. }
  5952. $$ = expr
  5953. }
  5954. | "UNDERSCORE_CHARSET" bitLit
  5955. {
  5956. co, err := charset.GetDefaultCollation($1)
  5957. if err != nil {
  5958. yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", $1))
  5959. return 1
  5960. }
  5961. expr := ast.NewValueExpr($2, parser.charset, parser.collation)
  5962. tp := expr.GetType()
  5963. tp.Charset = $1
  5964. tp.Collate = co
  5965. if tp.Collate == charset.CollationBin {
  5966. tp.Flag |= mysql.BinaryFlag
  5967. }
  5968. $$ = expr
  5969. }
  5970. StringLiteral:
  5971. stringLit
  5972. {
  5973. expr := ast.NewValueExpr($1, parser.charset, parser.collation)
  5974. $$ = expr
  5975. }
  5976. | StringLiteral stringLit
  5977. {
  5978. valExpr := $1.(ast.ValueExpr)
  5979. strLit := valExpr.GetString()
  5980. expr := ast.NewValueExpr(strLit+$2, parser.charset, parser.collation)
  5981. // Fix #4239, use first string literal as projection name.
  5982. if valExpr.GetProjectionOffset() >= 0 {
  5983. expr.SetProjectionOffset(valExpr.GetProjectionOffset())
  5984. } else {
  5985. expr.SetProjectionOffset(len(strLit))
  5986. }
  5987. $$ = expr
  5988. }
  5989. AlterOrderList:
  5990. AlterOrderItem
  5991. {
  5992. $$ = []*ast.AlterOrderItem{$1.(*ast.AlterOrderItem)}
  5993. }
  5994. | AlterOrderList ',' AlterOrderItem
  5995. {
  5996. $$ = append($1.([]*ast.AlterOrderItem), $3.(*ast.AlterOrderItem))
  5997. }
  5998. AlterOrderItem:
  5999. ColumnName OptOrder
  6000. {
  6001. $$ = &ast.AlterOrderItem{Column: $1.(*ast.ColumnName), Desc: $2.(bool)}
  6002. }
  6003. OrderBy:
  6004. "ORDER" "BY" ByList
  6005. {
  6006. $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)}
  6007. }
  6008. ByList:
  6009. ByItem
  6010. {
  6011. $$ = []*ast.ByItem{$1.(*ast.ByItem)}
  6012. }
  6013. | ByList ',' ByItem
  6014. {
  6015. $$ = append($1.([]*ast.ByItem), $3.(*ast.ByItem))
  6016. }
  6017. ByItem:
  6018. Expression
  6019. {
  6020. expr := $1
  6021. valueExpr, ok := expr.(ast.ValueExpr)
  6022. if ok {
  6023. position, isPosition := valueExpr.GetValue().(int64)
  6024. if isPosition {
  6025. expr = &ast.PositionExpr{N: int(position)}
  6026. }
  6027. }
  6028. $$ = &ast.ByItem{Expr: expr, NullOrder: true}
  6029. }
  6030. | Expression Order
  6031. {
  6032. expr := $1
  6033. valueExpr, ok := expr.(ast.ValueExpr)
  6034. if ok {
  6035. position, isPosition := valueExpr.GetValue().(int64)
  6036. if isPosition {
  6037. expr = &ast.PositionExpr{N: int(position)}
  6038. }
  6039. }
  6040. $$ = &ast.ByItem{Expr: expr, Desc: $2.(bool)}
  6041. }
  6042. Order:
  6043. "ASC"
  6044. {
  6045. $$ = false
  6046. }
  6047. | "DESC"
  6048. {
  6049. $$ = true
  6050. }
  6051. OptOrder:
  6052. /* EMPTY */
  6053. {
  6054. $$ = false // ASC by default
  6055. }
  6056. | "ASC"
  6057. {
  6058. $$ = false
  6059. }
  6060. | "DESC"
  6061. {
  6062. $$ = true
  6063. }
  6064. OrderByOptional:
  6065. {
  6066. $$ = nil
  6067. }
  6068. | OrderBy
  6069. BitExpr:
  6070. BitExpr '|' BitExpr %prec '|'
  6071. {
  6072. $$ = &ast.BinaryOperationExpr{Op: opcode.Or, L: $1, R: $3}
  6073. }
  6074. | BitExpr '&' BitExpr %prec '&'
  6075. {
  6076. $$ = &ast.BinaryOperationExpr{Op: opcode.And, L: $1, R: $3}
  6077. }
  6078. | BitExpr "<<" BitExpr %prec lsh
  6079. {
  6080. $$ = &ast.BinaryOperationExpr{Op: opcode.LeftShift, L: $1, R: $3}
  6081. }
  6082. | BitExpr ">>" BitExpr %prec rsh
  6083. {
  6084. $$ = &ast.BinaryOperationExpr{Op: opcode.RightShift, L: $1, R: $3}
  6085. }
  6086. | BitExpr '+' BitExpr %prec '+'
  6087. {
  6088. $$ = &ast.BinaryOperationExpr{Op: opcode.Plus, L: $1, R: $3}
  6089. }
  6090. | BitExpr '-' BitExpr %prec '-'
  6091. {
  6092. $$ = &ast.BinaryOperationExpr{Op: opcode.Minus, L: $1, R: $3}
  6093. }
  6094. | BitExpr '+' "INTERVAL" Expression TimeUnit %prec '+'
  6095. {
  6096. $$ = &ast.FuncCallExpr{
  6097. FnName: model.NewCIStr("DATE_ADD"),
  6098. Args: []ast.ExprNode{
  6099. $1,
  6100. $4,
  6101. &ast.TimeUnitExpr{Unit: $5.(ast.TimeUnitType)},
  6102. },
  6103. }
  6104. }
  6105. | BitExpr '-' "INTERVAL" Expression TimeUnit %prec '+'
  6106. {
  6107. $$ = &ast.FuncCallExpr{
  6108. FnName: model.NewCIStr("DATE_SUB"),
  6109. Args: []ast.ExprNode{
  6110. $1,
  6111. $4,
  6112. &ast.TimeUnitExpr{Unit: $5.(ast.TimeUnitType)},
  6113. },
  6114. }
  6115. }
  6116. | BitExpr '*' BitExpr %prec '*'
  6117. {
  6118. $$ = &ast.BinaryOperationExpr{Op: opcode.Mul, L: $1, R: $3}
  6119. }
  6120. | BitExpr '/' BitExpr %prec '/'
  6121. {
  6122. $$ = &ast.BinaryOperationExpr{Op: opcode.Div, L: $1, R: $3}
  6123. }
  6124. | BitExpr '%' BitExpr %prec '%'
  6125. {
  6126. $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3}
  6127. }
  6128. | BitExpr "DIV" BitExpr %prec div
  6129. {
  6130. $$ = &ast.BinaryOperationExpr{Op: opcode.IntDiv, L: $1, R: $3}
  6131. }
  6132. | BitExpr "MOD" BitExpr %prec mod
  6133. {
  6134. $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3}
  6135. }
  6136. | BitExpr '^' BitExpr
  6137. {
  6138. $$ = &ast.BinaryOperationExpr{Op: opcode.Xor, L: $1, R: $3}
  6139. }
  6140. | SimpleExpr
  6141. SimpleIdent:
  6142. Identifier
  6143. {
  6144. $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{
  6145. Name: model.NewCIStr($1),
  6146. }}
  6147. }
  6148. | Identifier '.' Identifier
  6149. {
  6150. $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{
  6151. Table: model.NewCIStr($1),
  6152. Name: model.NewCIStr($3),
  6153. }}
  6154. }
  6155. | Identifier '.' Identifier '.' Identifier
  6156. {
  6157. $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{
  6158. Schema: model.NewCIStr($1),
  6159. Table: model.NewCIStr($3),
  6160. Name: model.NewCIStr($5),
  6161. }}
  6162. }
  6163. SimpleExpr:
  6164. SimpleIdent
  6165. | FunctionCallKeyword
  6166. | FunctionCallNonKeyword
  6167. | FunctionCallGeneric
  6168. | SimpleExpr "COLLATE" CollationName
  6169. {
  6170. $$ = &ast.SetCollationExpr{Expr: $1, Collate: $3}
  6171. }
  6172. | WindowFuncCall
  6173. | Literal
  6174. | paramMarker
  6175. {
  6176. $$ = ast.NewParamMarkerExpr(yyS[yypt].offset)
  6177. }
  6178. | Variable
  6179. | SumExpr
  6180. | '!' SimpleExpr %prec neg
  6181. {
  6182. $$ = &ast.UnaryOperationExpr{Op: opcode.Not2, V: $2}
  6183. }
  6184. | '~' SimpleExpr %prec neg
  6185. {
  6186. $$ = &ast.UnaryOperationExpr{Op: opcode.BitNeg, V: $2}
  6187. }
  6188. | '-' SimpleExpr %prec neg
  6189. {
  6190. $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: $2}
  6191. }
  6192. | '+' SimpleExpr %prec neg
  6193. {
  6194. $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: $2}
  6195. }
  6196. | SimpleExpr pipes SimpleExpr
  6197. {
  6198. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.Concat), Args: []ast.ExprNode{$1, $3}}
  6199. }
  6200. | not2 SimpleExpr %prec neg
  6201. {
  6202. $$ = &ast.UnaryOperationExpr{Op: opcode.Not2, V: $2}
  6203. }
  6204. | SubSelect2
  6205. | '(' Expression ')'
  6206. {
  6207. startOffset := parser.startOffset(&yyS[yypt-1])
  6208. endOffset := parser.endOffset(&yyS[yypt])
  6209. expr := $2
  6210. expr.SetText(parser.src[startOffset:endOffset])
  6211. $$ = &ast.ParenthesesExpr{Expr: expr}
  6212. }
  6213. | '(' ExpressionList ',' Expression ')'
  6214. {
  6215. values := append($2.([]ast.ExprNode), $4)
  6216. $$ = &ast.RowExpr{Values: values}
  6217. }
  6218. | "ROW" '(' ExpressionList ',' Expression ')'
  6219. {
  6220. values := append($3.([]ast.ExprNode), $5)
  6221. $$ = &ast.RowExpr{Values: values}
  6222. }
  6223. | "EXISTS" SubSelect
  6224. {
  6225. sq := $2.(*ast.SubqueryExpr)
  6226. sq.Exists = true
  6227. $$ = &ast.ExistsSubqueryExpr{Sel: sq}
  6228. }
  6229. | "BINARY" SimpleExpr %prec neg
  6230. {
  6231. // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#operator_binary
  6232. x := types.NewFieldType(mysql.TypeString)
  6233. x.Charset = charset.CharsetBin
  6234. x.Collate = charset.CharsetBin
  6235. x.Flag |= mysql.BinaryFlag
  6236. $$ = &ast.FuncCastExpr{
  6237. Expr: $2,
  6238. Tp: x,
  6239. FunctionType: ast.CastBinaryOperator,
  6240. }
  6241. }
  6242. | builtinCast '(' Expression "AS" CastType ')'
  6243. {
  6244. /* See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast */
  6245. tp := $5.(*types.FieldType)
  6246. defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.Tp)
  6247. if tp.Flen == types.UnspecifiedLength {
  6248. tp.Flen = defaultFlen
  6249. }
  6250. if tp.Decimal == types.UnspecifiedLength {
  6251. tp.Decimal = defaultDecimal
  6252. }
  6253. explicitCharset := parser.explicitCharset
  6254. parser.explicitCharset = false
  6255. $$ = &ast.FuncCastExpr{
  6256. Expr: $3,
  6257. Tp: tp,
  6258. FunctionType: ast.CastFunction,
  6259. ExplicitCharSet: explicitCharset,
  6260. }
  6261. }
  6262. | "CASE" ExpressionOpt WhenClauseList ElseOpt "END"
  6263. {
  6264. x := &ast.CaseExpr{WhenClauses: $3.([]*ast.WhenClause)}
  6265. if $2 != nil {
  6266. x.Value = $2
  6267. }
  6268. if $4 != nil {
  6269. x.ElseClause = $4.(ast.ExprNode)
  6270. }
  6271. $$ = x
  6272. }
  6273. | "CONVERT" '(' Expression ',' CastType ')'
  6274. {
  6275. // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
  6276. tp := $5.(*types.FieldType)
  6277. defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.Tp)
  6278. if tp.Flen == types.UnspecifiedLength {
  6279. tp.Flen = defaultFlen
  6280. }
  6281. if tp.Decimal == types.UnspecifiedLength {
  6282. tp.Decimal = defaultDecimal
  6283. }
  6284. explicitCharset := parser.explicitCharset
  6285. parser.explicitCharset = false
  6286. $$ = &ast.FuncCastExpr{
  6287. Expr: $3,
  6288. Tp: tp,
  6289. FunctionType: ast.CastConvertFunction,
  6290. ExplicitCharSet: explicitCharset,
  6291. }
  6292. }
  6293. | "CONVERT" '(' Expression "USING" CharsetName ')'
  6294. {
  6295. // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
  6296. charset1 := ast.NewValueExpr($5, "", "")
  6297. $$ = &ast.FuncCallExpr{
  6298. FnName: model.NewCIStr($1),
  6299. Args: []ast.ExprNode{$3, charset1},
  6300. }
  6301. }
  6302. | "DEFAULT" '(' SimpleIdent ')'
  6303. {
  6304. $$ = &ast.DefaultExpr{Name: $3.(*ast.ColumnNameExpr).Name}
  6305. }
  6306. | "VALUES" '(' SimpleIdent ')' %prec lowerThanInsertValues
  6307. {
  6308. $$ = &ast.ValuesExpr{Column: $3.(*ast.ColumnNameExpr)}
  6309. }
  6310. | SimpleIdent jss stringLit
  6311. {
  6312. expr := ast.NewValueExpr($3, parser.charset, parser.collation)
  6313. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}}
  6314. }
  6315. | SimpleIdent juss stringLit
  6316. {
  6317. expr := ast.NewValueExpr($3, parser.charset, parser.collation)
  6318. extract := &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}}
  6319. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONUnquote), Args: []ast.ExprNode{extract}}
  6320. }
  6321. DistinctKwd:
  6322. "DISTINCT"
  6323. | "DISTINCTROW"
  6324. DistinctOpt:
  6325. "ALL"
  6326. {
  6327. $$ = false
  6328. }
  6329. | DistinctKwd
  6330. {
  6331. $$ = true
  6332. }
  6333. DefaultFalseDistinctOpt:
  6334. {
  6335. $$ = false
  6336. }
  6337. | DistinctOpt
  6338. DefaultTrueDistinctOpt:
  6339. {
  6340. $$ = true
  6341. }
  6342. | DistinctOpt
  6343. BuggyDefaultFalseDistinctOpt:
  6344. DefaultFalseDistinctOpt
  6345. | DistinctKwd "ALL"
  6346. {
  6347. $$ = true
  6348. }
  6349. FunctionNameConflict:
  6350. "ASCII"
  6351. | "CHARSET"
  6352. | "COALESCE"
  6353. | "COLLATION"
  6354. | "DATE"
  6355. | "DATABASE"
  6356. | "DAY"
  6357. | "HOUR"
  6358. | "IF"
  6359. | "INTERVAL" %prec lowerThanIntervalKeyword
  6360. | "FORMAT"
  6361. | "LEFT"
  6362. | "MICROSECOND"
  6363. | "MINUTE"
  6364. | "MONTH"
  6365. | builtinNow
  6366. | "QUARTER"
  6367. | "REPEAT"
  6368. | "REPLACE"
  6369. | "REVERSE"
  6370. | "RIGHT"
  6371. | "ROW_COUNT"
  6372. | "SECOND"
  6373. | "TIME"
  6374. | "TIMESTAMP"
  6375. | "TRUNCATE"
  6376. | "USER"
  6377. | "WEEK"
  6378. | "YEAR"
  6379. OptionalBraces:
  6380. {}
  6381. | '(' ')'
  6382. {}
  6383. FunctionNameOptionalBraces:
  6384. "CURRENT_USER"
  6385. | "CURRENT_DATE"
  6386. | "CURRENT_ROLE"
  6387. | "UTC_DATE"
  6388. FunctionNameDatetimePrecision:
  6389. "CURRENT_TIME"
  6390. | "CURRENT_TIMESTAMP"
  6391. | "LOCALTIME"
  6392. | "LOCALTIMESTAMP"
  6393. | "UTC_TIME"
  6394. | "UTC_TIMESTAMP"
  6395. FunctionCallKeyword:
  6396. FunctionNameConflict '(' ExpressionListOpt ')'
  6397. {
  6398. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
  6399. }
  6400. | builtinUser '(' ExpressionListOpt ')'
  6401. {
  6402. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
  6403. }
  6404. | FunctionNameOptionalBraces OptionalBraces
  6405. {
  6406. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)}
  6407. }
  6408. | builtinCurDate '(' ')'
  6409. {
  6410. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)}
  6411. }
  6412. | FunctionNameDatetimePrecision FuncDatetimePrec
  6413. {
  6414. args := []ast.ExprNode{}
  6415. if $2 != nil {
  6416. args = append(args, $2.(ast.ExprNode))
  6417. }
  6418. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: args}
  6419. }
  6420. | "CHAR" '(' ExpressionList ')'
  6421. {
  6422. nilVal := ast.NewValueExpr(nil, parser.charset, parser.collation)
  6423. args := $3.([]ast.ExprNode)
  6424. $$ = &ast.FuncCallExpr{
  6425. FnName: model.NewCIStr(ast.CharFunc),
  6426. Args: append(args, nilVal),
  6427. }
  6428. }
  6429. | "CHAR" '(' ExpressionList "USING" CharsetName ')'
  6430. {
  6431. charset1 := ast.NewValueExpr($5, "", "")
  6432. args := $3.([]ast.ExprNode)
  6433. $$ = &ast.FuncCallExpr{
  6434. FnName: model.NewCIStr(ast.CharFunc),
  6435. Args: append(args, charset1),
  6436. }
  6437. }
  6438. | "DATE" stringLit
  6439. {
  6440. expr := ast.NewValueExpr($2, "", "")
  6441. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.DateLiteral), Args: []ast.ExprNode{expr}}
  6442. }
  6443. | "TIME" stringLit
  6444. {
  6445. expr := ast.NewValueExpr($2, "", "")
  6446. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimeLiteral), Args: []ast.ExprNode{expr}}
  6447. }
  6448. | "TIMESTAMP" stringLit
  6449. {
  6450. expr := ast.NewValueExpr($2, "", "")
  6451. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimestampLiteral), Args: []ast.ExprNode{expr}}
  6452. }
  6453. | "INSERT" '(' ExpressionListOpt ')'
  6454. {
  6455. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.InsertFunc), Args: $3.([]ast.ExprNode)}
  6456. }
  6457. | "MOD" '(' BitExpr ',' BitExpr ')'
  6458. {
  6459. $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $3, R: $5}
  6460. }
  6461. | "PASSWORD" '(' ExpressionListOpt ')'
  6462. {
  6463. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.PasswordFunc), Args: $3.([]ast.ExprNode)}
  6464. }
  6465. | '{' ODBCDateTimeType stringLit '}'
  6466. {
  6467. // This is ODBC syntax for date and time literals.
  6468. // See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-literals.html
  6469. expr := ast.NewValueExpr($3, parser.charset, parser.collation)
  6470. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($2), Args: []ast.ExprNode{expr}}
  6471. }
  6472. FunctionCallNonKeyword:
  6473. builtinCurTime '(' FuncDatetimePrecListOpt ')'
  6474. {
  6475. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
  6476. }
  6477. | builtinSysDate '(' FuncDatetimePrecListOpt ')'
  6478. {
  6479. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
  6480. }
  6481. | FunctionNameDateArithMultiForms '(' Expression ',' Expression ')'
  6482. {
  6483. $$ = &ast.FuncCallExpr{
  6484. FnName: model.NewCIStr($1),
  6485. Args: []ast.ExprNode{
  6486. $3,
  6487. $5,
  6488. &ast.TimeUnitExpr{Unit: ast.TimeUnitDay},
  6489. },
  6490. }
  6491. }
  6492. | FunctionNameDateArithMultiForms '(' Expression ',' "INTERVAL" Expression TimeUnit ')'
  6493. {
  6494. $$ = &ast.FuncCallExpr{
  6495. FnName: model.NewCIStr($1),
  6496. Args: []ast.ExprNode{
  6497. $3,
  6498. $6,
  6499. &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)},
  6500. },
  6501. }
  6502. }
  6503. | FunctionNameDateArith '(' Expression ',' "INTERVAL" Expression TimeUnit ')'
  6504. {
  6505. $$ = &ast.FuncCallExpr{
  6506. FnName: model.NewCIStr($1),
  6507. Args: []ast.ExprNode{
  6508. $3,
  6509. $6,
  6510. &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)},
  6511. },
  6512. }
  6513. }
  6514. | builtinExtract '(' TimeUnit "FROM" Expression ')'
  6515. {
  6516. timeUnit := &ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}
  6517. $$ = &ast.FuncCallExpr{
  6518. FnName: model.NewCIStr($1),
  6519. Args: []ast.ExprNode{timeUnit, $5},
  6520. }
  6521. }
  6522. | "GET_FORMAT" '(' GetFormatSelector ',' Expression ')'
  6523. {
  6524. $$ = &ast.FuncCallExpr{
  6525. FnName: model.NewCIStr($1),
  6526. Args: []ast.ExprNode{
  6527. &ast.GetFormatSelectorExpr{Selector: $3.(ast.GetFormatSelectorType)},
  6528. $5,
  6529. },
  6530. }
  6531. }
  6532. | builtinPosition '(' BitExpr "IN" Expression ')'
  6533. {
  6534. $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: []ast.ExprNode{$3, $5}}
  6535. }
  6536. | builtinSubstring '(' Expression ',' Expression ')'
  6537. {
  6538. $$ = &ast.FuncCallExpr{
  6539. FnName: model.NewCIStr($1),
  6540. Args: []ast.ExprNode{$3, $5},
  6541. }
  6542. }
  6543. | builtinSubstring '(' Expression "FROM" Expression ')'
  6544. {
  6545. $$ = &ast.FuncCallExpr{
  6546. FnName: model.NewCIStr($1),
  6547. Args: []ast.ExprNode{$3, $5},
  6548. }
  6549. }
  6550. | builtinSubstring '(' Expression ',' Expression ',' Expression ')'
  6551. {
  6552. $$ = &ast.FuncCallExpr{
  6553. FnName: model.NewCIStr($1),
  6554. Args: []ast.ExprNode{$3, $5, $7},
  6555. }
  6556. }
  6557. | builtinSubstring '(' Expression "FROM" Expression "FOR" Expression ')'
  6558. {
  6559. $$ = &ast.FuncCallExpr{
  6560. FnName: model.NewCIStr($1),
  6561. Args: []ast.ExprNode{$3, $5, $7},
  6562. }
  6563. }
  6564. | "TIMESTAMPADD" '(' TimestampUnit ',' Expression ',' Expression ')'
  6565. {
  6566. $$ = &ast.FuncCallExpr{
  6567. FnName: model.NewCIStr($1),
  6568. Args: []ast.ExprNode{&ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, $5, $7},
  6569. }
  6570. }
  6571. | "TIMESTAMPDIFF" '(' TimestampUnit ',' Expression ',' Expression ')'
  6572. {
  6573. $$ = &ast.FuncCallExpr{
  6574. FnName: model.NewCIStr($1),
  6575. Args: []ast.ExprNode{&ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, $5, $7},
  6576. }
  6577. }
  6578. | builtinTrim '(' Expression ')'
  6579. {
  6580. $$ = &ast.FuncCallExpr{
  6581. FnName: model.NewCIStr($1),
  6582. Args: []ast.ExprNode{$3},
  6583. }
  6584. }
  6585. | builtinTrim '(' Expression "FROM" Expression ')'
  6586. {
  6587. $$ = &ast.FuncCallExpr{
  6588. FnName: model.NewCIStr($1),
  6589. Args: []ast.ExprNode{$5, $3},
  6590. }
  6591. }
  6592. | builtinTrim '(' TrimDirection "FROM" Expression ')'
  6593. {
  6594. nilVal := ast.NewValueExpr(nil, parser.charset, parser.collation)
  6595. direction := &ast.TrimDirectionExpr{Direction: $3.(ast.TrimDirectionType)}
  6596. $$ = &ast.FuncCallExpr{
  6597. FnName: model.NewCIStr($1),
  6598. Args: []ast.ExprNode{$5, nilVal, direction},
  6599. }
  6600. }
  6601. | builtinTrim '(' TrimDirection Expression "FROM" Expression ')'
  6602. {
  6603. direction := &ast.TrimDirectionExpr{Direction: $3.(ast.TrimDirectionType)}
  6604. $$ = &ast.FuncCallExpr{
  6605. FnName: model.NewCIStr($1),
  6606. Args: []ast.ExprNode{$6, $4, direction},
  6607. }
  6608. }
  6609. | weightString '(' Expression ')'
  6610. {
  6611. $$ = &ast.FuncCallExpr{
  6612. FnName: model.NewCIStr($1),
  6613. Args: []ast.ExprNode{$3},
  6614. }
  6615. }
  6616. | weightString '(' Expression "AS" Char FieldLen ')'
  6617. {
  6618. $$ = &ast.FuncCallExpr{
  6619. FnName: model.NewCIStr($1),
  6620. Args: []ast.ExprNode{$3, ast.NewValueExpr("CHAR", parser.charset, parser.collation), ast.NewValueExpr($6, parser.charset, parser.collation)},
  6621. }
  6622. }
  6623. | weightString '(' Expression "AS" "BINARY" FieldLen ')'
  6624. {
  6625. $$ = &ast.FuncCallExpr{
  6626. FnName: model.NewCIStr($1),
  6627. Args: []ast.ExprNode{$3, ast.NewValueExpr("BINARY", parser.charset, parser.collation), ast.NewValueExpr($6, parser.charset, parser.collation)},
  6628. }
  6629. }
  6630. | FunctionNameSequence
  6631. GetFormatSelector:
  6632. "DATE"
  6633. {
  6634. $$ = ast.GetFormatSelectorDate
  6635. }
  6636. | "DATETIME"
  6637. {
  6638. $$ = ast.GetFormatSelectorDatetime
  6639. }
  6640. | "TIME"
  6641. {
  6642. $$ = ast.GetFormatSelectorTime
  6643. }
  6644. | "TIMESTAMP"
  6645. {
  6646. $$ = ast.GetFormatSelectorDatetime
  6647. }
  6648. FunctionNameDateArith:
  6649. builtinDateAdd
  6650. | builtinDateSub
  6651. FunctionNameDateArithMultiForms:
  6652. builtinAddDate
  6653. | builtinSubDate
  6654. TrimDirection:
  6655. "BOTH"
  6656. {
  6657. $$ = ast.TrimBoth
  6658. }
  6659. | "LEADING"
  6660. {
  6661. $$ = ast.TrimLeading
  6662. }
  6663. | "TRAILING"
  6664. {
  6665. $$ = ast.TrimTrailing
  6666. }
  6667. FunctionNameSequence:
  6668. "LASTVAL" '(' TableName ')'
  6669. {
  6670. objNameExpr := &ast.TableNameExpr{
  6671. Name: $3.(*ast.TableName),
  6672. }
  6673. $$ = &ast.FuncCallExpr{
  6674. FnName: model.NewCIStr(ast.LastVal),
  6675. Args: []ast.ExprNode{objNameExpr},
  6676. }
  6677. }
  6678. | "SETVAL" '(' TableName ',' SignedNum ')'
  6679. {
  6680. objNameExpr := &ast.TableNameExpr{
  6681. Name: $3.(*ast.TableName),
  6682. }
  6683. valueExpr := ast.NewValueExpr($5, parser.charset, parser.collation)
  6684. $$ = &ast.FuncCallExpr{
  6685. FnName: model.NewCIStr(ast.SetVal),
  6686. Args: []ast.ExprNode{objNameExpr, valueExpr},
  6687. }
  6688. }
  6689. | NextValueForSequence
  6690. SumExpr:
  6691. "AVG" '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6692. {
  6693. if $6 != nil {
  6694. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6695. } else {
  6696. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6697. }
  6698. }
  6699. | builtinApproxCountDistinct '(' ExpressionList ')'
  6700. {
  6701. $$ = &ast.AggregateFuncExpr{F: $1, Args: $3.([]ast.ExprNode), Distinct: false}
  6702. }
  6703. | builtinApproxPercentile '(' ExpressionList ')'
  6704. {
  6705. $$ = &ast.AggregateFuncExpr{F: $1, Args: $3.([]ast.ExprNode)}
  6706. }
  6707. | builtinBitAnd '(' Expression ')' OptWindowingClause
  6708. {
  6709. if $5 != nil {
  6710. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
  6711. } else {
  6712. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
  6713. }
  6714. }
  6715. | builtinBitAnd '(' "ALL" Expression ')' OptWindowingClause
  6716. {
  6717. if $6 != nil {
  6718. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
  6719. } else {
  6720. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
  6721. }
  6722. }
  6723. | builtinBitOr '(' Expression ')' OptWindowingClause
  6724. {
  6725. if $5 != nil {
  6726. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
  6727. } else {
  6728. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
  6729. }
  6730. }
  6731. | builtinBitOr '(' "ALL" Expression ')' OptWindowingClause
  6732. {
  6733. if $6 != nil {
  6734. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
  6735. } else {
  6736. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
  6737. }
  6738. }
  6739. | builtinBitXor '(' Expression ')' OptWindowingClause
  6740. {
  6741. if $5 != nil {
  6742. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
  6743. } else {
  6744. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
  6745. }
  6746. }
  6747. | builtinBitXor '(' "ALL" Expression ')' OptWindowingClause
  6748. {
  6749. if $6 != nil {
  6750. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
  6751. } else {
  6752. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
  6753. }
  6754. }
  6755. | builtinCount '(' DistinctKwd ExpressionList ')'
  6756. {
  6757. $$ = &ast.AggregateFuncExpr{F: $1, Args: $4.([]ast.ExprNode), Distinct: true}
  6758. }
  6759. | builtinCount '(' "ALL" Expression ')' OptWindowingClause
  6760. {
  6761. if $6 != nil {
  6762. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
  6763. } else {
  6764. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
  6765. }
  6766. }
  6767. | builtinCount '(' Expression ')' OptWindowingClause
  6768. {
  6769. if $5 != nil {
  6770. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
  6771. } else {
  6772. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
  6773. }
  6774. }
  6775. | builtinCount '(' '*' ')' OptWindowingClause
  6776. {
  6777. args := []ast.ExprNode{ast.NewValueExpr(1, parser.charset, parser.collation)}
  6778. if $5 != nil {
  6779. $$ = &ast.WindowFuncExpr{F: $1, Args: args, Spec: *($5.(*ast.WindowSpec))}
  6780. } else {
  6781. $$ = &ast.AggregateFuncExpr{F: $1, Args: args}
  6782. }
  6783. }
  6784. | builtinGroupConcat '(' BuggyDefaultFalseDistinctOpt ExpressionList OrderByOptional OptGConcatSeparator ')' OptWindowingClause
  6785. {
  6786. args := $4.([]ast.ExprNode)
  6787. args = append(args, $6.(ast.ExprNode))
  6788. if $8 != nil {
  6789. $$ = &ast.WindowFuncExpr{F: $1, Args: args, Distinct: $3.(bool), Spec: *($8.(*ast.WindowSpec))}
  6790. } else {
  6791. agg := &ast.AggregateFuncExpr{F: $1, Args: args, Distinct: $3.(bool)}
  6792. if $5 != nil {
  6793. agg.Order = $5.(*ast.OrderByClause)
  6794. }
  6795. $$ = agg
  6796. }
  6797. }
  6798. | builtinMax '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6799. {
  6800. if $6 != nil {
  6801. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6802. } else {
  6803. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6804. }
  6805. }
  6806. | builtinMin '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6807. {
  6808. if $6 != nil {
  6809. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6810. } else {
  6811. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6812. }
  6813. }
  6814. | builtinSum '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6815. {
  6816. if $6 != nil {
  6817. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6818. } else {
  6819. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6820. }
  6821. }
  6822. | builtinStddevPop '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6823. {
  6824. if $6 != nil {
  6825. $$ = &ast.WindowFuncExpr{F: ast.AggFuncStddevPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6826. } else {
  6827. $$ = &ast.AggregateFuncExpr{F: ast.AggFuncStddevPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6828. }
  6829. }
  6830. | builtinStddevSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6831. {
  6832. if $6 != nil {
  6833. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6834. } else {
  6835. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6836. }
  6837. }
  6838. | builtinVarPop '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6839. {
  6840. if $6 != nil {
  6841. $$ = &ast.WindowFuncExpr{F: ast.AggFuncVarPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
  6842. } else {
  6843. $$ = &ast.AggregateFuncExpr{F: ast.AggFuncVarPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6844. }
  6845. }
  6846. | builtinVarSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
  6847. {
  6848. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
  6849. }
  6850. | "JSON_ARRAYAGG" '(' Expression ')' OptWindowingClause
  6851. {
  6852. if $5 != nil {
  6853. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
  6854. } else {
  6855. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
  6856. }
  6857. }
  6858. | "JSON_ARRAYAGG" '(' "ALL" Expression ')' OptWindowingClause
  6859. {
  6860. if $6 != nil {
  6861. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
  6862. } else {
  6863. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
  6864. }
  6865. }
  6866. | "JSON_OBJECTAGG" '(' Expression ',' Expression ')' OptWindowingClause
  6867. {
  6868. if $7 != nil {
  6869. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}, Spec: *($7.(*ast.WindowSpec))}
  6870. } else {
  6871. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}}
  6872. }
  6873. }
  6874. | "JSON_OBJECTAGG" '(' "ALL" Expression ',' Expression ')' OptWindowingClause
  6875. {
  6876. if $8 != nil {
  6877. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4, $6}, Spec: *($8.(*ast.WindowSpec))}
  6878. } else {
  6879. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4, $6}}
  6880. }
  6881. }
  6882. | "JSON_OBJECTAGG" '(' Expression ',' "ALL" Expression ')' OptWindowingClause
  6883. {
  6884. if $8 != nil {
  6885. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3, $6}, Spec: *($8.(*ast.WindowSpec))}
  6886. } else {
  6887. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3, $6}}
  6888. }
  6889. }
  6890. | "JSON_OBJECTAGG" '(' "ALL" Expression ',' "ALL" Expression ')' OptWindowingClause
  6891. {
  6892. if $9 != nil {
  6893. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4, $7}, Spec: *($9.(*ast.WindowSpec))}
  6894. } else {
  6895. $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4, $7}}
  6896. }
  6897. }
  6898. OptGConcatSeparator:
  6899. {
  6900. $$ = ast.NewValueExpr(",", "", "")
  6901. }
  6902. | "SEPARATOR" stringLit
  6903. {
  6904. $$ = ast.NewValueExpr($2, "", "")
  6905. }
  6906. FunctionCallGeneric:
  6907. identifier '(' ExpressionListOpt ')'
  6908. {
  6909. $$ = &ast.FuncCallExpr{
  6910. FnName: model.NewCIStr($1),
  6911. Args: $3.([]ast.ExprNode),
  6912. }
  6913. }
  6914. | Identifier '.' Identifier '(' ExpressionListOpt ')'
  6915. {
  6916. var tp ast.FuncCallExprType
  6917. if isInTokenMap($3) {
  6918. tp = ast.FuncCallExprTypeKeyword
  6919. } else {
  6920. tp = ast.FuncCallExprTypeGeneric
  6921. }
  6922. $$ = &ast.FuncCallExpr{
  6923. Tp: tp,
  6924. Schema: model.NewCIStr($1),
  6925. FnName: model.NewCIStr($3),
  6926. Args: $5.([]ast.ExprNode),
  6927. }
  6928. }
  6929. FuncDatetimePrec:
  6930. {
  6931. $$ = nil
  6932. }
  6933. | '(' ')'
  6934. {
  6935. $$ = nil
  6936. }
  6937. | '(' intLit ')'
  6938. {
  6939. expr := ast.NewValueExpr($2, parser.charset, parser.collation)
  6940. $$ = expr
  6941. }
  6942. TimeUnit:
  6943. TimestampUnit
  6944. | "SECOND_MICROSECOND"
  6945. {
  6946. $$ = ast.TimeUnitSecondMicrosecond
  6947. }
  6948. | "MINUTE_MICROSECOND"
  6949. {
  6950. $$ = ast.TimeUnitMinuteMicrosecond
  6951. }
  6952. | "MINUTE_SECOND"
  6953. {
  6954. $$ = ast.TimeUnitMinuteSecond
  6955. }
  6956. | "HOUR_MICROSECOND"
  6957. {
  6958. $$ = ast.TimeUnitHourMicrosecond
  6959. }
  6960. | "HOUR_SECOND"
  6961. {
  6962. $$ = ast.TimeUnitHourSecond
  6963. }
  6964. | "HOUR_MINUTE"
  6965. {
  6966. $$ = ast.TimeUnitHourMinute
  6967. }
  6968. | "DAY_MICROSECOND"
  6969. {
  6970. $$ = ast.TimeUnitDayMicrosecond
  6971. }
  6972. | "DAY_SECOND"
  6973. {
  6974. $$ = ast.TimeUnitDaySecond
  6975. }
  6976. | "DAY_MINUTE"
  6977. {
  6978. $$ = ast.TimeUnitDayMinute
  6979. }
  6980. | "DAY_HOUR"
  6981. {
  6982. $$ = ast.TimeUnitDayHour
  6983. }
  6984. | "YEAR_MONTH"
  6985. {
  6986. $$ = ast.TimeUnitYearMonth
  6987. }
  6988. TimestampUnit:
  6989. "MICROSECOND"
  6990. {
  6991. $$ = ast.TimeUnitMicrosecond
  6992. }
  6993. | "SECOND"
  6994. {
  6995. $$ = ast.TimeUnitSecond
  6996. }
  6997. | "MINUTE"
  6998. {
  6999. $$ = ast.TimeUnitMinute
  7000. }
  7001. | "HOUR"
  7002. {
  7003. $$ = ast.TimeUnitHour
  7004. }
  7005. | "DAY"
  7006. {
  7007. $$ = ast.TimeUnitDay
  7008. }
  7009. | "WEEK"
  7010. {
  7011. $$ = ast.TimeUnitWeek
  7012. }
  7013. | "MONTH"
  7014. {
  7015. $$ = ast.TimeUnitMonth
  7016. }
  7017. | "QUARTER"
  7018. {
  7019. $$ = ast.TimeUnitQuarter
  7020. }
  7021. | "YEAR"
  7022. {
  7023. $$ = ast.TimeUnitYear
  7024. }
  7025. | "SQL_TSI_SECOND"
  7026. {
  7027. $$ = ast.TimeUnitSecond
  7028. }
  7029. | "SQL_TSI_MINUTE"
  7030. {
  7031. $$ = ast.TimeUnitMinute
  7032. }
  7033. | "SQL_TSI_HOUR"
  7034. {
  7035. $$ = ast.TimeUnitHour
  7036. }
  7037. | "SQL_TSI_DAY"
  7038. {
  7039. $$ = ast.TimeUnitDay
  7040. }
  7041. | "SQL_TSI_WEEK"
  7042. {
  7043. $$ = ast.TimeUnitWeek
  7044. }
  7045. | "SQL_TSI_MONTH"
  7046. {
  7047. $$ = ast.TimeUnitMonth
  7048. }
  7049. | "SQL_TSI_QUARTER"
  7050. {
  7051. $$ = ast.TimeUnitQuarter
  7052. }
  7053. | "SQL_TSI_YEAR"
  7054. {
  7055. $$ = ast.TimeUnitYear
  7056. }
  7057. ExpressionOpt:
  7058. {
  7059. $$ = nil
  7060. }
  7061. | Expression
  7062. WhenClauseList:
  7063. WhenClause
  7064. {
  7065. $$ = []*ast.WhenClause{$1.(*ast.WhenClause)}
  7066. }
  7067. | WhenClauseList WhenClause
  7068. {
  7069. $$ = append($1.([]*ast.WhenClause), $2.(*ast.WhenClause))
  7070. }
  7071. WhenClause:
  7072. "WHEN" Expression "THEN" Expression
  7073. {
  7074. $$ = &ast.WhenClause{
  7075. Expr: $2,
  7076. Result: $4,
  7077. }
  7078. }
  7079. ElseOpt:
  7080. /* empty */
  7081. {
  7082. $$ = nil
  7083. }
  7084. | "ELSE" Expression
  7085. {
  7086. $$ = $2
  7087. }
  7088. CastType:
  7089. "BINARY" OptFieldLen
  7090. {
  7091. x := types.NewFieldType(mysql.TypeVarString)
  7092. x.Flen = $2.(int) // TODO: Flen should be the flen of expression
  7093. if x.Flen != types.UnspecifiedLength {
  7094. x.Tp = mysql.TypeString
  7095. }
  7096. x.Charset = charset.CharsetBin
  7097. x.Collate = charset.CollationBin
  7098. x.Flag |= mysql.BinaryFlag
  7099. $$ = x
  7100. }
  7101. | Char OptFieldLen OptBinary
  7102. {
  7103. x := types.NewFieldType(mysql.TypeVarString)
  7104. x.Flen = $2.(int) // TODO: Flen should be the flen of expression
  7105. x.Charset = $3.(*ast.OptBinary).Charset
  7106. if $3.(*ast.OptBinary).IsBinary {
  7107. x.Flag |= mysql.BinaryFlag
  7108. x.Charset = charset.CharsetBin
  7109. x.Collate = charset.CollationBin
  7110. } else if x.Charset != "" {
  7111. co, err := charset.GetDefaultCollation(x.Charset)
  7112. if err != nil {
  7113. yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", x.Charset))
  7114. return 1
  7115. }
  7116. x.Collate = co
  7117. parser.explicitCharset = true
  7118. } else {
  7119. x.Charset = parser.charset
  7120. x.Collate = parser.collation
  7121. }
  7122. $$ = x
  7123. }
  7124. | "DATE"
  7125. {
  7126. x := types.NewFieldType(mysql.TypeDate)
  7127. x.Charset = charset.CharsetBin
  7128. x.Collate = charset.CollationBin
  7129. x.Flag |= mysql.BinaryFlag
  7130. $$ = x
  7131. }
  7132. | "DATETIME" OptFieldLen
  7133. {
  7134. x := types.NewFieldType(mysql.TypeDatetime)
  7135. x.Flen, _ = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDatetime)
  7136. x.Decimal = $2.(int)
  7137. if x.Decimal > 0 {
  7138. x.Flen = x.Flen + 1 + x.Decimal
  7139. }
  7140. x.Charset = charset.CharsetBin
  7141. x.Collate = charset.CollationBin
  7142. x.Flag |= mysql.BinaryFlag
  7143. $$ = x
  7144. }
  7145. | "DECIMAL" FloatOpt
  7146. {
  7147. fopt := $2.(*ast.FloatOpt)
  7148. x := types.NewFieldType(mysql.TypeNewDecimal)
  7149. x.Flen = fopt.Flen
  7150. x.Decimal = fopt.Decimal
  7151. x.Charset = charset.CharsetBin
  7152. x.Collate = charset.CollationBin
  7153. x.Flag |= mysql.BinaryFlag
  7154. $$ = x
  7155. }
  7156. | "TIME" OptFieldLen
  7157. {
  7158. x := types.NewFieldType(mysql.TypeDuration)
  7159. x.Flen, _ = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDuration)
  7160. x.Decimal = $2.(int)
  7161. if x.Decimal > 0 {
  7162. x.Flen = x.Flen + 1 + x.Decimal
  7163. }
  7164. x.Charset = charset.CharsetBin
  7165. x.Collate = charset.CollationBin
  7166. x.Flag |= mysql.BinaryFlag
  7167. $$ = x
  7168. }
  7169. | "SIGNED" OptInteger
  7170. {
  7171. x := types.NewFieldType(mysql.TypeLonglong)
  7172. x.Charset = charset.CharsetBin
  7173. x.Collate = charset.CollationBin
  7174. x.Flag |= mysql.BinaryFlag
  7175. $$ = x
  7176. }
  7177. | "UNSIGNED" OptInteger
  7178. {
  7179. x := types.NewFieldType(mysql.TypeLonglong)
  7180. x.Flag |= mysql.UnsignedFlag | mysql.BinaryFlag
  7181. x.Charset = charset.CharsetBin
  7182. x.Collate = charset.CollationBin
  7183. $$ = x
  7184. }
  7185. | "JSON"
  7186. {
  7187. x := types.NewFieldType(mysql.TypeJSON)
  7188. x.Flag |= mysql.BinaryFlag | (mysql.ParseToJSONFlag)
  7189. x.Charset = mysql.DefaultCharset
  7190. x.Collate = mysql.DefaultCollationName
  7191. $$ = x
  7192. }
  7193. | "DOUBLE"
  7194. {
  7195. x := types.NewFieldType(mysql.TypeDouble)
  7196. x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDouble)
  7197. x.Flag |= mysql.BinaryFlag
  7198. x.Charset = charset.CharsetBin
  7199. x.Collate = charset.CollationBin
  7200. $$ = x
  7201. }
  7202. | "FLOAT" FloatOpt
  7203. {
  7204. x := types.NewFieldType(mysql.TypeFloat)
  7205. fopt := $2.(*ast.FloatOpt)
  7206. if fopt.Flen >= 54 {
  7207. yylex.AppendError(ErrTooBigPrecision.GenWithStackByArgs(fopt.Flen, "CAST", 53))
  7208. } else if fopt.Flen >= 25 {
  7209. x = types.NewFieldType(mysql.TypeDouble)
  7210. }
  7211. x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(x.Tp)
  7212. x.Flag |= mysql.BinaryFlag
  7213. x.Charset = charset.CharsetBin
  7214. x.Collate = charset.CollationBin
  7215. $$ = x
  7216. }
  7217. | "REAL"
  7218. {
  7219. var x *types.FieldType
  7220. if parser.lexer.GetSQLMode().HasRealAsFloatMode() {
  7221. x = types.NewFieldType(mysql.TypeFloat)
  7222. } else {
  7223. x = types.NewFieldType(mysql.TypeDouble)
  7224. }
  7225. x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(x.Tp)
  7226. x.Flag |= mysql.BinaryFlag
  7227. x.Charset = charset.CharsetBin
  7228. x.Collate = charset.CollationBin
  7229. $$ = x
  7230. }
  7231. Priority:
  7232. "LOW_PRIORITY"
  7233. {
  7234. $$ = mysql.LowPriority
  7235. }
  7236. | "HIGH_PRIORITY"
  7237. {
  7238. $$ = mysql.HighPriority
  7239. }
  7240. | "DELAYED"
  7241. {
  7242. $$ = mysql.DelayedPriority
  7243. }
  7244. PriorityOpt:
  7245. {
  7246. $$ = mysql.NoPriority
  7247. }
  7248. | Priority
  7249. TableName:
  7250. Identifier
  7251. {
  7252. $$ = &ast.TableName{Name: model.NewCIStr($1)}
  7253. }
  7254. | Identifier '.' Identifier
  7255. {
  7256. $$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)}
  7257. }
  7258. TableNameList:
  7259. TableName
  7260. {
  7261. tbl := []*ast.TableName{$1.(*ast.TableName)}
  7262. $$ = tbl
  7263. }
  7264. | TableNameList ',' TableName
  7265. {
  7266. $$ = append($1.([]*ast.TableName), $3.(*ast.TableName))
  7267. }
  7268. TableNameOptWild:
  7269. Identifier OptWild
  7270. {
  7271. $$ = &ast.TableName{Name: model.NewCIStr($1)}
  7272. }
  7273. | Identifier '.' Identifier OptWild
  7274. {
  7275. $$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)}
  7276. }
  7277. TableAliasRefList:
  7278. TableNameOptWild
  7279. {
  7280. tbl := []*ast.TableName{$1.(*ast.TableName)}
  7281. $$ = tbl
  7282. }
  7283. | TableAliasRefList ',' TableNameOptWild
  7284. {
  7285. $$ = append($1.([]*ast.TableName), $3.(*ast.TableName))
  7286. }
  7287. OptWild:
  7288. %prec empty
  7289. {}
  7290. | '.' '*'
  7291. {}
  7292. QuickOptional:
  7293. %prec empty
  7294. {
  7295. $$ = false
  7296. }
  7297. | "QUICK"
  7298. {
  7299. $$ = true
  7300. }
  7301. /***************************Prepared Statement Start******************************
  7302. * See https://dev.mysql.com/doc/refman/5.7/en/prepare.html
  7303. * Example:
  7304. * PREPARE stmt_name FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
  7305. * OR
  7306. * SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
  7307. * PREPARE stmt_name FROM @s;
  7308. */
  7309. PreparedStmt:
  7310. "PREPARE" Identifier "FROM" PrepareSQL
  7311. {
  7312. var sqlText string
  7313. var sqlVar *ast.VariableExpr
  7314. switch x := $4.(type) {
  7315. case string:
  7316. sqlText = x
  7317. case *ast.VariableExpr:
  7318. sqlVar = x
  7319. }
  7320. $$ = &ast.PrepareStmt{
  7321. Name: $2,
  7322. SQLText: sqlText,
  7323. SQLVar: sqlVar,
  7324. }
  7325. }
  7326. PrepareSQL:
  7327. stringLit
  7328. {
  7329. $$ = $1
  7330. }
  7331. | UserVariable
  7332. {
  7333. $$ = $1
  7334. }
  7335. /*
  7336. * See https://dev.mysql.com/doc/refman/5.7/en/execute.html
  7337. * Example:
  7338. * EXECUTE stmt1 USING @a, @b;
  7339. * OR
  7340. * EXECUTE stmt1;
  7341. */
  7342. ExecuteStmt:
  7343. "EXECUTE" Identifier
  7344. {
  7345. $$ = &ast.ExecuteStmt{Name: $2}
  7346. }
  7347. | "EXECUTE" Identifier "USING" UserVariableList
  7348. {
  7349. $$ = &ast.ExecuteStmt{
  7350. Name: $2,
  7351. UsingVars: $4.([]ast.ExprNode),
  7352. }
  7353. }
  7354. UserVariableList:
  7355. UserVariable
  7356. {
  7357. $$ = []ast.ExprNode{$1}
  7358. }
  7359. | UserVariableList ',' UserVariable
  7360. {
  7361. $$ = append($1.([]ast.ExprNode), $3)
  7362. }
  7363. DeallocateStmt:
  7364. DeallocateSym "PREPARE" Identifier
  7365. {
  7366. $$ = &ast.DeallocateStmt{Name: $3}
  7367. }
  7368. DeallocateSym:
  7369. "DEALLOCATE"
  7370. | "DROP"
  7371. RollbackStmt:
  7372. "ROLLBACK"
  7373. {
  7374. $$ = &ast.RollbackStmt{}
  7375. }
  7376. | "ROLLBACK" CompletionTypeWithinTransaction
  7377. {
  7378. $$ = &ast.RollbackStmt{CompletionType: $2.(ast.CompletionType)}
  7379. }
  7380. CompletionTypeWithinTransaction:
  7381. "AND" "CHAIN" "NO" "RELEASE"
  7382. {
  7383. $$ = ast.CompletionTypeChain
  7384. }
  7385. | "AND" "NO" "CHAIN" "RELEASE"
  7386. {
  7387. $$ = ast.CompletionTypeRelease
  7388. }
  7389. | "AND" "NO" "CHAIN" "NO" "RELEASE"
  7390. {
  7391. $$ = ast.CompletionTypeDefault
  7392. }
  7393. | "AND" "CHAIN"
  7394. {
  7395. $$ = ast.CompletionTypeChain
  7396. }
  7397. | "AND" "NO" "CHAIN"
  7398. {
  7399. $$ = ast.CompletionTypeDefault
  7400. }
  7401. | "RELEASE"
  7402. {
  7403. $$ = ast.CompletionTypeRelease
  7404. }
  7405. | "NO" "RELEASE"
  7406. {
  7407. $$ = ast.CompletionTypeDefault
  7408. }
  7409. ShutdownStmt:
  7410. "SHUTDOWN"
  7411. {
  7412. $$ = &ast.ShutdownStmt{}
  7413. }
  7414. SelectStmtBasic:
  7415. "SELECT" SelectStmtOpts SelectStmtFieldList
  7416. {
  7417. st := &ast.SelectStmt{
  7418. SelectStmtOpts: $2.(*ast.SelectStmtOpts),
  7419. Distinct: $2.(*ast.SelectStmtOpts).Distinct,
  7420. Fields: $3.(*ast.FieldList),
  7421. Kind: ast.SelectStmtKindSelect,
  7422. }
  7423. if st.SelectStmtOpts.TableHints != nil {
  7424. st.TableHints = st.SelectStmtOpts.TableHints
  7425. }
  7426. $$ = st
  7427. }
  7428. SelectStmtFromDualTable:
  7429. SelectStmtBasic FromDual WhereClauseOptional
  7430. {
  7431. st := $1.(*ast.SelectStmt)
  7432. lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
  7433. if lastField.Expr != nil && lastField.AsName.O == "" {
  7434. lastEnd := yyS[yypt-1].offset - 1
  7435. lastField.SetText(parser.src[lastField.Offset:lastEnd])
  7436. }
  7437. if $3 != nil {
  7438. st.Where = $3.(ast.ExprNode)
  7439. }
  7440. }
  7441. SelectStmtFromTable:
  7442. SelectStmtBasic "FROM" TableRefsClause WhereClauseOptional SelectStmtGroup HavingClause WindowClauseOptional
  7443. {
  7444. st := $1.(*ast.SelectStmt)
  7445. st.From = $3.(*ast.TableRefsClause)
  7446. lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
  7447. if lastField.Expr != nil && lastField.AsName.O == "" {
  7448. lastEnd := parser.endOffset(&yyS[yypt-5])
  7449. lastField.SetText(parser.src[lastField.Offset:lastEnd])
  7450. }
  7451. if $4 != nil {
  7452. st.Where = $4.(ast.ExprNode)
  7453. }
  7454. if $5 != nil {
  7455. st.GroupBy = $5.(*ast.GroupByClause)
  7456. }
  7457. if $6 != nil {
  7458. st.Having = $6.(*ast.HavingClause)
  7459. }
  7460. if $7 != nil {
  7461. st.WindowSpecs = ($7.([]ast.WindowSpec))
  7462. }
  7463. $$ = st
  7464. }
  7465. TableSampleOpt:
  7466. %prec empty
  7467. {
  7468. $$ = nil
  7469. }
  7470. | "TABLESAMPLE" TableSampleMethodOpt '(' Expression TableSampleUnitOpt ')' RepeatableOpt
  7471. {
  7472. var repSeed ast.ExprNode
  7473. if $7 != nil {
  7474. repSeed = ast.NewValueExpr($7, parser.charset, parser.collation)
  7475. }
  7476. $$ = &ast.TableSample{
  7477. SampleMethod: $2.(ast.SampleMethodType),
  7478. Expr: ast.NewValueExpr($4, parser.charset, parser.collation),
  7479. SampleClauseUnit: $5.(ast.SampleClauseUnitType),
  7480. RepeatableSeed: repSeed,
  7481. }
  7482. }
  7483. | "TABLESAMPLE" TableSampleMethodOpt '(' ')' RepeatableOpt
  7484. {
  7485. var repSeed ast.ExprNode
  7486. if $5 != nil {
  7487. repSeed = ast.NewValueExpr($5, parser.charset, parser.collation)
  7488. }
  7489. $$ = &ast.TableSample{
  7490. SampleMethod: $2.(ast.SampleMethodType),
  7491. RepeatableSeed: repSeed,
  7492. }
  7493. }
  7494. TableSampleMethodOpt:
  7495. %prec empty
  7496. {
  7497. $$ = ast.SampleMethodTypeNone
  7498. }
  7499. | "SYSTEM"
  7500. {
  7501. $$ = ast.SampleMethodTypeSystem
  7502. }
  7503. | "BERNOULLI"
  7504. {
  7505. $$ = ast.SampleMethodTypeBernoulli
  7506. }
  7507. | "REGIONS"
  7508. {
  7509. $$ = ast.SampleMethodTypeTiDBRegion
  7510. }
  7511. TableSampleUnitOpt:
  7512. %prec empty
  7513. {
  7514. $$ = ast.SampleClauseUnitTypeDefault
  7515. }
  7516. | "ROWS"
  7517. {
  7518. $$ = ast.SampleClauseUnitTypeRow
  7519. }
  7520. | "PERCENT"
  7521. {
  7522. $$ = ast.SampleClauseUnitTypePercent
  7523. }
  7524. RepeatableOpt:
  7525. %prec empty
  7526. {
  7527. $$ = nil
  7528. }
  7529. | "REPEATABLE" '(' Expression ')'
  7530. {
  7531. $$ = $3
  7532. }
  7533. SelectStmt:
  7534. SelectStmtNoWith
  7535. | WithClause SelectStmtNoWith
  7536. {
  7537. st := $2.(*ast.SelectStmt)
  7538. st.With = $1.(*ast.WithClause)
  7539. $$ = st
  7540. }
  7541. SelectStmtNoWith:
  7542. SelectStmtBasic WhereClauseOptional OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
  7543. {
  7544. st := $1.(*ast.SelectStmt)
  7545. if $5 != nil {
  7546. st.LockInfo = $5.(*ast.SelectLockInfo)
  7547. }
  7548. lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
  7549. if lastField.Expr != nil && lastField.AsName.O == "" {
  7550. src := parser.src
  7551. var lastEnd int
  7552. if $2 != nil {
  7553. lastEnd = yyS[yypt-4].offset - 1
  7554. } else if $3 != nil {
  7555. lastEnd = yyS[yypt-3].offset - 1
  7556. } else if $4 != nil {
  7557. lastEnd = yyS[yypt-2].offset - 1
  7558. } else if st.LockInfo != nil && st.LockInfo.LockType != ast.SelectLockNone {
  7559. lastEnd = yyS[yypt-1].offset - 1
  7560. } else if $6 != nil {
  7561. lastEnd = yyS[yypt].offset - 1
  7562. } else {
  7563. lastEnd = len(src)
  7564. if src[lastEnd-1] == ';' {
  7565. lastEnd--
  7566. }
  7567. }
  7568. lastField.SetText(src[lastField.Offset:lastEnd])
  7569. }
  7570. if $2 != nil {
  7571. st.Where = $2.(ast.ExprNode)
  7572. }
  7573. if $3 != nil {
  7574. st.OrderBy = $3.(*ast.OrderByClause)
  7575. }
  7576. if $4 != nil {
  7577. st.Limit = $4.(*ast.Limit)
  7578. }
  7579. if $6 != nil {
  7580. st.SelectIntoOpt = $6.(*ast.SelectIntoOption)
  7581. }
  7582. $$ = st
  7583. }
  7584. | SelectStmtFromDualTable OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
  7585. {
  7586. st := $1.(*ast.SelectStmt)
  7587. if $2 != nil {
  7588. st.OrderBy = $2.(*ast.OrderByClause)
  7589. }
  7590. if $3 != nil {
  7591. st.Limit = $3.(*ast.Limit)
  7592. }
  7593. if $4 != nil {
  7594. st.LockInfo = $4.(*ast.SelectLockInfo)
  7595. }
  7596. if $5 != nil {
  7597. st.SelectIntoOpt = $5.(*ast.SelectIntoOption)
  7598. }
  7599. $$ = st
  7600. }
  7601. | SelectStmtFromTable OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
  7602. {
  7603. st := $1.(*ast.SelectStmt)
  7604. if $4 != nil {
  7605. st.LockInfo = $4.(*ast.SelectLockInfo)
  7606. }
  7607. if $2 != nil {
  7608. st.OrderBy = $2.(*ast.OrderByClause)
  7609. }
  7610. if $3 != nil {
  7611. st.Limit = $3.(*ast.Limit)
  7612. }
  7613. if $5 != nil {
  7614. st.SelectIntoOpt = $5.(*ast.SelectIntoOption)
  7615. }
  7616. $$ = st
  7617. }
  7618. | "TABLE" TableName OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
  7619. {
  7620. st := &ast.SelectStmt{
  7621. Kind: ast.SelectStmtKindTable,
  7622. Fields: &ast.FieldList{Fields: []*ast.SelectField{{WildCard: &ast.WildCardField{}}}},
  7623. }
  7624. ts := &ast.TableSource{Source: $2.(*ast.TableName)}
  7625. st.From = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}}
  7626. if $3 != nil {
  7627. st.OrderBy = $3.(*ast.OrderByClause)
  7628. }
  7629. if $4 != nil {
  7630. st.Limit = $4.(*ast.Limit)
  7631. }
  7632. if $5 != nil {
  7633. st.LockInfo = $5.(*ast.SelectLockInfo)
  7634. }
  7635. if $6 != nil {
  7636. st.SelectIntoOpt = $6.(*ast.SelectIntoOption)
  7637. }
  7638. $$ = st
  7639. }
  7640. | "VALUES" ValuesStmtList OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
  7641. {
  7642. st := &ast.SelectStmt{
  7643. Kind: ast.SelectStmtKindValues,
  7644. Fields: &ast.FieldList{Fields: []*ast.SelectField{{WildCard: &ast.WildCardField{}}}},
  7645. Lists: $2.([]*ast.RowExpr),
  7646. }
  7647. if $3 != nil {
  7648. st.OrderBy = $3.(*ast.OrderByClause)
  7649. }
  7650. if $4 != nil {
  7651. st.Limit = $4.(*ast.Limit)
  7652. }
  7653. if $5 != nil {
  7654. st.LockInfo = $5.(*ast.SelectLockInfo)
  7655. }
  7656. if $6 != nil {
  7657. st.SelectIntoOpt = $6.(*ast.SelectIntoOption)
  7658. }
  7659. $$ = st
  7660. }
  7661. WithClause:
  7662. "WITH" WithList
  7663. {
  7664. $$ = $2
  7665. }
  7666. | "WITH" recursive WithList
  7667. {
  7668. ws := $3.(*ast.WithClause)
  7669. ws.IsRecursive = true
  7670. $$ = ws
  7671. }
  7672. WithList:
  7673. WithList ',' CommonTableExpr
  7674. {
  7675. ws := $1.(*ast.WithClause)
  7676. ws.CTEs = append(ws.CTEs, $3.(*ast.CommonTableExpression))
  7677. $$ = ws
  7678. }
  7679. | CommonTableExpr
  7680. {
  7681. ws := &ast.WithClause{}
  7682. ws.CTEs = make([]*ast.CommonTableExpression, 0, 4)
  7683. ws.CTEs = append(ws.CTEs, $1.(*ast.CommonTableExpression))
  7684. $$ = ws
  7685. }
  7686. CommonTableExpr:
  7687. Identifier IdentListWithParenOpt "AS" SubSelect
  7688. {
  7689. cte := &ast.CommonTableExpression{}
  7690. cte.Name = model.NewCIStr($1)
  7691. cte.ColNameList = $2.([]model.CIStr)
  7692. cte.Query = $4.(*ast.SubqueryExpr)
  7693. $$ = cte
  7694. }
  7695. FromDual:
  7696. "FROM" "DUAL"
  7697. WindowClauseOptional:
  7698. {
  7699. $$ = nil
  7700. }
  7701. | "WINDOW" WindowDefinitionList
  7702. {
  7703. $$ = $2.([]ast.WindowSpec)
  7704. }
  7705. WindowDefinitionList:
  7706. WindowDefinition
  7707. {
  7708. $$ = []ast.WindowSpec{$1.(ast.WindowSpec)}
  7709. }
  7710. | WindowDefinitionList ',' WindowDefinition
  7711. {
  7712. $$ = append($1.([]ast.WindowSpec), $3.(ast.WindowSpec))
  7713. }
  7714. WindowDefinition:
  7715. WindowName "AS" WindowSpec
  7716. {
  7717. var spec = $3.(ast.WindowSpec)
  7718. spec.Name = $1.(model.CIStr)
  7719. $$ = spec
  7720. }
  7721. WindowName:
  7722. Identifier
  7723. {
  7724. $$ = model.NewCIStr($1)
  7725. }
  7726. WindowSpec:
  7727. '(' WindowSpecDetails ')'
  7728. {
  7729. $$ = $2.(ast.WindowSpec)
  7730. }
  7731. WindowSpecDetails:
  7732. OptExistingWindowName OptPartitionClause OptWindowOrderByClause OptWindowFrameClause
  7733. {
  7734. spec := ast.WindowSpec{Ref: $1.(model.CIStr)}
  7735. if $2 != nil {
  7736. spec.PartitionBy = $2.(*ast.PartitionByClause)
  7737. }
  7738. if $3 != nil {
  7739. spec.OrderBy = $3.(*ast.OrderByClause)
  7740. }
  7741. if $4 != nil {
  7742. spec.Frame = $4.(*ast.FrameClause)
  7743. }
  7744. $$ = spec
  7745. }
  7746. OptExistingWindowName:
  7747. {
  7748. $$ = model.CIStr{}
  7749. }
  7750. | WindowName
  7751. OptPartitionClause:
  7752. {
  7753. $$ = nil
  7754. }
  7755. | "PARTITION" "BY" ByList
  7756. {
  7757. $$ = &ast.PartitionByClause{Items: $3.([]*ast.ByItem)}
  7758. }
  7759. OptWindowOrderByClause:
  7760. {
  7761. $$ = nil
  7762. }
  7763. | "ORDER" "BY" ByList
  7764. {
  7765. $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)}
  7766. }
  7767. OptWindowFrameClause:
  7768. {
  7769. $$ = nil
  7770. }
  7771. | WindowFrameUnits WindowFrameExtent
  7772. {
  7773. $$ = &ast.FrameClause{
  7774. Type: $1.(ast.FrameType),
  7775. Extent: $2.(ast.FrameExtent),
  7776. }
  7777. }
  7778. WindowFrameUnits:
  7779. "ROWS"
  7780. {
  7781. $$ = ast.FrameType(ast.Rows)
  7782. }
  7783. | "RANGE"
  7784. {
  7785. $$ = ast.FrameType(ast.Ranges)
  7786. }
  7787. | "GROUPS"
  7788. {
  7789. $$ = ast.FrameType(ast.Groups)
  7790. }
  7791. WindowFrameExtent:
  7792. WindowFrameStart
  7793. {
  7794. $$ = ast.FrameExtent{
  7795. Start: $1.(ast.FrameBound),
  7796. End: ast.FrameBound{Type: ast.CurrentRow},
  7797. }
  7798. }
  7799. | WindowFrameBetween
  7800. WindowFrameStart:
  7801. "UNBOUNDED" "PRECEDING"
  7802. {
  7803. $$ = ast.FrameBound{Type: ast.Preceding, UnBounded: true}
  7804. }
  7805. | NumLiteral "PRECEDING"
  7806. {
  7807. $$ = ast.FrameBound{Type: ast.Preceding, Expr: ast.NewValueExpr($1, parser.charset, parser.collation)}
  7808. }
  7809. | paramMarker "PRECEDING"
  7810. {
  7811. $$ = ast.FrameBound{Type: ast.Preceding, Expr: ast.NewParamMarkerExpr(yyS[yypt].offset)}
  7812. }
  7813. | "INTERVAL" Expression TimeUnit "PRECEDING"
  7814. {
  7815. $$ = ast.FrameBound{Type: ast.Preceding, Expr: $2, Unit: $3.(ast.TimeUnitType)}
  7816. }
  7817. | "CURRENT" "ROW"
  7818. {
  7819. $$ = ast.FrameBound{Type: ast.CurrentRow}
  7820. }
  7821. WindowFrameBetween:
  7822. "BETWEEN" WindowFrameBound "AND" WindowFrameBound
  7823. {
  7824. $$ = ast.FrameExtent{Start: $2.(ast.FrameBound), End: $4.(ast.FrameBound)}
  7825. }
  7826. WindowFrameBound:
  7827. WindowFrameStart
  7828. | "UNBOUNDED" "FOLLOWING"
  7829. {
  7830. $$ = ast.FrameBound{Type: ast.Following, UnBounded: true}
  7831. }
  7832. | NumLiteral "FOLLOWING"
  7833. {
  7834. $$ = ast.FrameBound{Type: ast.Following, Expr: ast.NewValueExpr($1, parser.charset, parser.collation)}
  7835. }
  7836. | paramMarker "FOLLOWING"
  7837. {
  7838. $$ = ast.FrameBound{Type: ast.Following, Expr: ast.NewParamMarkerExpr(yyS[yypt].offset)}
  7839. }
  7840. | "INTERVAL" Expression TimeUnit "FOLLOWING"
  7841. {
  7842. $$ = ast.FrameBound{Type: ast.Following, Expr: $2, Unit: $3.(ast.TimeUnitType)}
  7843. }
  7844. OptWindowingClause:
  7845. {
  7846. $$ = nil
  7847. }
  7848. | WindowingClause
  7849. {
  7850. spec := $1.(ast.WindowSpec)
  7851. $$ = &spec
  7852. }
  7853. WindowingClause:
  7854. "OVER" WindowNameOrSpec
  7855. {
  7856. $$ = $2.(ast.WindowSpec)
  7857. }
  7858. WindowNameOrSpec:
  7859. WindowName
  7860. {
  7861. $$ = ast.WindowSpec{Name: $1.(model.CIStr), OnlyAlias: true}
  7862. }
  7863. | WindowSpec
  7864. WindowFuncCall:
  7865. "ROW_NUMBER" '(' ')' WindowingClause
  7866. {
  7867. $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
  7868. }
  7869. | "RANK" '(' ')' WindowingClause
  7870. {
  7871. $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
  7872. }
  7873. | "DENSE_RANK" '(' ')' WindowingClause
  7874. {
  7875. $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
  7876. }
  7877. | "CUME_DIST" '(' ')' WindowingClause
  7878. {
  7879. $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
  7880. }
  7881. | "PERCENT_RANK" '(' ')' WindowingClause
  7882. {
  7883. $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
  7884. }
  7885. | "NTILE" '(' SimpleExpr ')' WindowingClause
  7886. {
  7887. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: $5.(ast.WindowSpec)}
  7888. }
  7889. | "LEAD" '(' Expression OptLeadLagInfo ')' OptNullTreatment WindowingClause
  7890. {
  7891. args := []ast.ExprNode{$3}
  7892. if $4 != nil {
  7893. args = append(args, $4.([]ast.ExprNode)...)
  7894. }
  7895. $$ = &ast.WindowFuncExpr{F: $1, Args: args, IgnoreNull: $6.(bool), Spec: $7.(ast.WindowSpec)}
  7896. }
  7897. | "LAG" '(' Expression OptLeadLagInfo ')' OptNullTreatment WindowingClause
  7898. {
  7899. args := []ast.ExprNode{$3}
  7900. if $4 != nil {
  7901. args = append(args, $4.([]ast.ExprNode)...)
  7902. }
  7903. $$ = &ast.WindowFuncExpr{F: $1, Args: args, IgnoreNull: $6.(bool), Spec: $7.(ast.WindowSpec)}
  7904. }
  7905. | "FIRST_VALUE" '(' Expression ')' OptNullTreatment WindowingClause
  7906. {
  7907. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, IgnoreNull: $5.(bool), Spec: $6.(ast.WindowSpec)}
  7908. }
  7909. | "LAST_VALUE" '(' Expression ')' OptNullTreatment WindowingClause
  7910. {
  7911. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, IgnoreNull: $5.(bool), Spec: $6.(ast.WindowSpec)}
  7912. }
  7913. | "NTH_VALUE" '(' Expression ',' SimpleExpr ')' OptFromFirstLast OptNullTreatment WindowingClause
  7914. {
  7915. $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}, FromLast: $7.(bool), IgnoreNull: $8.(bool), Spec: $9.(ast.WindowSpec)}
  7916. }
  7917. OptLeadLagInfo:
  7918. {
  7919. $$ = nil
  7920. }
  7921. | ',' NumLiteral OptLLDefault
  7922. {
  7923. args := []ast.ExprNode{ast.NewValueExpr($2, parser.charset, parser.collation)}
  7924. if $3 != nil {
  7925. args = append(args, $3.(ast.ExprNode))
  7926. }
  7927. $$ = args
  7928. }
  7929. | ',' paramMarker OptLLDefault
  7930. {
  7931. args := []ast.ExprNode{ast.NewValueExpr($2, parser.charset, parser.collation)}
  7932. if $3 != nil {
  7933. args = append(args, $3.(ast.ExprNode))
  7934. }
  7935. $$ = args
  7936. }
  7937. OptLLDefault:
  7938. {
  7939. $$ = nil
  7940. }
  7941. | ',' Expression
  7942. {
  7943. $$ = $2
  7944. }
  7945. OptNullTreatment:
  7946. {
  7947. $$ = false
  7948. }
  7949. | "RESPECT" "NULLS"
  7950. {
  7951. $$ = false
  7952. }
  7953. | "IGNORE" "NULLS"
  7954. {
  7955. $$ = true
  7956. }
  7957. OptFromFirstLast:
  7958. {
  7959. $$ = false
  7960. }
  7961. | "FROM" "FIRST"
  7962. {
  7963. $$ = false
  7964. }
  7965. | "FROM" "LAST"
  7966. {
  7967. $$ = true
  7968. }
  7969. TableRefsClause:
  7970. TableRefs
  7971. {
  7972. $$ = &ast.TableRefsClause{TableRefs: $1.(*ast.Join)}
  7973. }
  7974. TableRefs:
  7975. EscapedTableRef
  7976. {
  7977. if j, ok := $1.(*ast.Join); ok {
  7978. // if $1 is Join, use it directly
  7979. $$ = j
  7980. } else {
  7981. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: nil}
  7982. }
  7983. }
  7984. | TableRefs ',' EscapedTableRef
  7985. {
  7986. /* from a, b is default cross join */
  7987. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin}
  7988. }
  7989. EscapedTableRef:
  7990. TableRef %prec lowerThanSetKeyword
  7991. | '{' Identifier TableRef '}'
  7992. {
  7993. /*
  7994. * ODBC escape syntax for outer join is { OJ join_table }
  7995. * Use an Identifier for OJ
  7996. */
  7997. $$ = $3
  7998. }
  7999. TableRef:
  8000. TableFactor
  8001. | JoinTable
  8002. TableFactor:
  8003. TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt TableSampleOpt
  8004. {
  8005. tn := $1.(*ast.TableName)
  8006. tn.PartitionNames = $2.([]model.CIStr)
  8007. tn.IndexHints = $4.([]*ast.IndexHint)
  8008. if $5 != nil {
  8009. tn.TableSample = $5.(*ast.TableSample)
  8010. }
  8011. $$ = &ast.TableSource{Source: tn, AsName: $3.(model.CIStr)}
  8012. }
  8013. | '(' SetOprStmt1 ')' TableAsNameOpt
  8014. {
  8015. if st, isSel := $2.(*ast.SelectStmt); isSel {
  8016. endOffset := parser.endOffset(&yyS[yypt-1])
  8017. parser.setLastSelectFieldText(st, endOffset)
  8018. }
  8019. $$ = &ast.TableSource{Source: $2.(ast.ResultSetNode), AsName: $4.(model.CIStr)}
  8020. }
  8021. | '(' TableRefs ')'
  8022. {
  8023. j := $2.(*ast.Join)
  8024. j.ExplicitParens = true
  8025. $$ = $2
  8026. }
  8027. PartitionNameListOpt:
  8028. /* empty */
  8029. {
  8030. $$ = []model.CIStr{}
  8031. }
  8032. | "PARTITION" '(' PartitionNameList ')'
  8033. {
  8034. $$ = $3
  8035. }
  8036. TableAsNameOpt:
  8037. {
  8038. $$ = model.CIStr{}
  8039. }
  8040. | TableAsName
  8041. TableAsName:
  8042. Identifier
  8043. {
  8044. $$ = model.NewCIStr($1)
  8045. }
  8046. | "AS" Identifier
  8047. {
  8048. $$ = model.NewCIStr($2)
  8049. }
  8050. IndexHintType:
  8051. "USE" KeyOrIndex
  8052. {
  8053. $$ = ast.HintUse
  8054. }
  8055. | "IGNORE" KeyOrIndex
  8056. {
  8057. $$ = ast.HintIgnore
  8058. }
  8059. | "FORCE" KeyOrIndex
  8060. {
  8061. $$ = ast.HintForce
  8062. }
  8063. IndexHintScope:
  8064. {
  8065. $$ = ast.HintForScan
  8066. }
  8067. | "FOR" "JOIN"
  8068. {
  8069. $$ = ast.HintForJoin
  8070. }
  8071. | "FOR" "ORDER" "BY"
  8072. {
  8073. $$ = ast.HintForOrderBy
  8074. }
  8075. | "FOR" "GROUP" "BY"
  8076. {
  8077. $$ = ast.HintForGroupBy
  8078. }
  8079. IndexHint:
  8080. IndexHintType IndexHintScope '(' IndexNameList ')'
  8081. {
  8082. $$ = &ast.IndexHint{
  8083. IndexNames: $4.([]model.CIStr),
  8084. HintType: $1.(ast.IndexHintType),
  8085. HintScope: $2.(ast.IndexHintScope),
  8086. }
  8087. }
  8088. IndexNameList:
  8089. {
  8090. var nameList []model.CIStr
  8091. $$ = nameList
  8092. }
  8093. | Identifier
  8094. {
  8095. $$ = []model.CIStr{model.NewCIStr($1)}
  8096. }
  8097. | IndexNameList ',' Identifier
  8098. {
  8099. $$ = append($1.([]model.CIStr), model.NewCIStr($3))
  8100. }
  8101. | "PRIMARY"
  8102. {
  8103. $$ = []model.CIStr{model.NewCIStr($1)}
  8104. }
  8105. | IndexNameList ',' "PRIMARY"
  8106. {
  8107. $$ = append($1.([]model.CIStr), model.NewCIStr($3))
  8108. }
  8109. IndexHintList:
  8110. IndexHint
  8111. {
  8112. $$ = []*ast.IndexHint{$1.(*ast.IndexHint)}
  8113. }
  8114. | IndexHintList IndexHint
  8115. {
  8116. $$ = append($1.([]*ast.IndexHint), $2.(*ast.IndexHint))
  8117. }
  8118. IndexHintListOpt:
  8119. {
  8120. $$ = []*ast.IndexHint{}
  8121. }
  8122. | IndexHintList
  8123. JoinTable:
  8124. /* Use %prec to evaluate production TableRef before cross join */
  8125. TableRef CrossOpt TableRef %prec tableRefPriority
  8126. {
  8127. $$ = ast.NewCrossJoin($1.(ast.ResultSetNode), $3.(ast.ResultSetNode))
  8128. }
  8129. | TableRef CrossOpt TableRef "ON" Expression
  8130. {
  8131. on := &ast.OnCondition{Expr: $5}
  8132. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, On: on}
  8133. }
  8134. | TableRef CrossOpt TableRef "USING" '(' ColumnNameList ')'
  8135. {
  8136. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, Using: $6.([]*ast.ColumnName)}
  8137. }
  8138. | TableRef JoinType OuterOpt "JOIN" TableRef "ON" Expression
  8139. {
  8140. on := &ast.OnCondition{Expr: $7}
  8141. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), On: on}
  8142. }
  8143. | TableRef JoinType OuterOpt "JOIN" TableRef "USING" '(' ColumnNameList ')'
  8144. {
  8145. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), Using: $8.([]*ast.ColumnName)}
  8146. }
  8147. | TableRef "NATURAL" "JOIN" TableRef
  8148. {
  8149. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $4.(ast.ResultSetNode), NaturalJoin: true}
  8150. }
  8151. | TableRef "NATURAL" JoinType OuterOpt "JOIN" TableRef
  8152. {
  8153. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $6.(ast.ResultSetNode), Tp: $3.(ast.JoinType), NaturalJoin: true}
  8154. }
  8155. | TableRef "STRAIGHT_JOIN" TableRef
  8156. {
  8157. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true}
  8158. }
  8159. | TableRef "STRAIGHT_JOIN" TableRef "ON" Expression
  8160. {
  8161. on := &ast.OnCondition{Expr: $5}
  8162. $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true, On: on}
  8163. }
  8164. JoinType:
  8165. "LEFT"
  8166. {
  8167. $$ = ast.LeftJoin
  8168. }
  8169. | "RIGHT"
  8170. {
  8171. $$ = ast.RightJoin
  8172. }
  8173. OuterOpt:
  8174. {}
  8175. | "OUTER"
  8176. CrossOpt:
  8177. "JOIN"
  8178. | "CROSS" "JOIN"
  8179. | "INNER" "JOIN"
  8180. LimitClause:
  8181. {
  8182. $$ = nil
  8183. }
  8184. | "LIMIT" LimitOption
  8185. {
  8186. $$ = &ast.Limit{Count: $2.(ast.ValueExpr)}
  8187. }
  8188. LimitOption:
  8189. LengthNum
  8190. {
  8191. $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
  8192. }
  8193. | paramMarker
  8194. {
  8195. $$ = ast.NewParamMarkerExpr(yyS[yypt].offset)
  8196. }
  8197. RowOrRows:
  8198. "ROW"
  8199. | "ROWS"
  8200. FirstOrNext:
  8201. "FIRST"
  8202. | "NEXT"
  8203. FetchFirstOpt:
  8204. {
  8205. $$ = ast.NewValueExpr(uint64(1), parser.charset, parser.collation)
  8206. }
  8207. | LimitOption
  8208. SelectStmtLimit:
  8209. "LIMIT" LimitOption
  8210. {
  8211. $$ = &ast.Limit{Count: $2.(ast.ExprNode)}
  8212. }
  8213. | "LIMIT" LimitOption ',' LimitOption
  8214. {
  8215. $$ = &ast.Limit{Offset: $2.(ast.ExprNode), Count: $4.(ast.ExprNode)}
  8216. }
  8217. | "LIMIT" LimitOption "OFFSET" LimitOption
  8218. {
  8219. $$ = &ast.Limit{Offset: $4.(ast.ExprNode), Count: $2.(ast.ExprNode)}
  8220. }
  8221. | "FETCH" FirstOrNext FetchFirstOpt RowOrRows "ONLY"
  8222. {
  8223. $$ = &ast.Limit{Count: $3.(ast.ExprNode)}
  8224. }
  8225. SelectStmtLimitOpt:
  8226. {
  8227. $$ = nil
  8228. }
  8229. | SelectStmtLimit
  8230. SelectStmtOpt:
  8231. TableOptimizerHints
  8232. {
  8233. opt := &ast.SelectStmtOpts{}
  8234. opt.SQLCache = true
  8235. opt.TableHints = $1.([]*ast.TableOptimizerHint)
  8236. $$ = opt
  8237. }
  8238. | DistinctOpt
  8239. {
  8240. opt := &ast.SelectStmtOpts{}
  8241. opt.SQLCache = true
  8242. if $1.(bool) {
  8243. opt.Distinct = true
  8244. } else {
  8245. opt.Distinct = false
  8246. opt.ExplicitAll = true
  8247. }
  8248. $$ = opt
  8249. }
  8250. | Priority
  8251. {
  8252. opt := &ast.SelectStmtOpts{}
  8253. opt.SQLCache = true
  8254. opt.Priority = $1.(mysql.PriorityEnum)
  8255. $$ = opt
  8256. }
  8257. | "SQL_SMALL_RESULT"
  8258. {
  8259. opt := &ast.SelectStmtOpts{}
  8260. opt.SQLCache = true
  8261. opt.SQLSmallResult = true
  8262. $$ = opt
  8263. }
  8264. | "SQL_BIG_RESULT"
  8265. {
  8266. opt := &ast.SelectStmtOpts{}
  8267. opt.SQLCache = true
  8268. opt.SQLBigResult = true
  8269. $$ = opt
  8270. }
  8271. | "SQL_BUFFER_RESULT"
  8272. {
  8273. opt := &ast.SelectStmtOpts{}
  8274. opt.SQLCache = true
  8275. opt.SQLBufferResult = true
  8276. $$ = opt
  8277. }
  8278. | SelectStmtSQLCache
  8279. {
  8280. opt := &ast.SelectStmtOpts{}
  8281. opt.SQLCache = $1.(bool)
  8282. $$ = opt
  8283. }
  8284. | "SQL_CALC_FOUND_ROWS"
  8285. {
  8286. opt := &ast.SelectStmtOpts{}
  8287. opt.SQLCache = true
  8288. opt.CalcFoundRows = true
  8289. $$ = opt
  8290. }
  8291. | "STRAIGHT_JOIN"
  8292. {
  8293. opt := &ast.SelectStmtOpts{}
  8294. opt.SQLCache = true
  8295. opt.StraightJoin = true
  8296. $$ = opt
  8297. }
  8298. SelectStmtOpts:
  8299. %prec empty
  8300. {
  8301. opt := &ast.SelectStmtOpts{}
  8302. opt.SQLCache = true
  8303. $$ = opt
  8304. }
  8305. | SelectStmtOptsList %prec lowerThanSelectOpt
  8306. SelectStmtOptsList:
  8307. SelectStmtOptsList SelectStmtOpt
  8308. {
  8309. opts := $1.(*ast.SelectStmtOpts)
  8310. opt := $2.(*ast.SelectStmtOpts)
  8311. // Merge options.
  8312. // Always use the first hint.
  8313. if opt.TableHints != nil && opts.TableHints == nil {
  8314. opts.TableHints = opt.TableHints
  8315. }
  8316. if opt.Distinct {
  8317. opts.Distinct = true
  8318. }
  8319. if opt.Priority != mysql.NoPriority {
  8320. opts.Priority = opt.Priority
  8321. }
  8322. if opt.SQLSmallResult {
  8323. opts.SQLSmallResult = true
  8324. }
  8325. if opt.SQLBigResult {
  8326. opts.SQLBigResult = true
  8327. }
  8328. if opt.SQLBufferResult {
  8329. opts.SQLBufferResult = true
  8330. }
  8331. if !opt.SQLCache {
  8332. opts.SQLCache = false
  8333. }
  8334. if opt.CalcFoundRows {
  8335. opts.CalcFoundRows = true
  8336. }
  8337. if opt.StraightJoin {
  8338. opts.StraightJoin = true
  8339. }
  8340. if opt.ExplicitAll {
  8341. opts.ExplicitAll = true
  8342. }
  8343. if opts.Distinct && opts.ExplicitAll {
  8344. yylex.AppendError(ErrWrongUsage.GenWithStackByArgs("ALL", "DISTINCT"))
  8345. return 1
  8346. }
  8347. $$ = opts
  8348. }
  8349. | SelectStmtOpt
  8350. TableOptimizerHints:
  8351. hintComment
  8352. {
  8353. hints, warns := parser.parseHint($1)
  8354. for _, w := range warns {
  8355. yylex.AppendError(w)
  8356. parser.lastErrorAsWarn()
  8357. }
  8358. $$ = hints
  8359. }
  8360. TableOptimizerHintsOpt:
  8361. /* empty */
  8362. {
  8363. $$ = nil
  8364. }
  8365. | TableOptimizerHints
  8366. SelectStmtSQLCache:
  8367. "SQL_CACHE"
  8368. {
  8369. $$ = true
  8370. }
  8371. | "SQL_NO_CACHE"
  8372. {
  8373. $$ = false
  8374. }
  8375. SelectStmtFieldList:
  8376. FieldList
  8377. {
  8378. $$ = &ast.FieldList{Fields: $1.([]*ast.SelectField)}
  8379. }
  8380. SelectStmtGroup:
  8381. /* EMPTY */
  8382. {
  8383. $$ = nil
  8384. }
  8385. | GroupByClause
  8386. SelectStmtIntoOption:
  8387. {
  8388. $$ = nil
  8389. }
  8390. | "INTO" "OUTFILE" stringLit Fields Lines
  8391. {
  8392. x := &ast.SelectIntoOption{
  8393. Tp: ast.SelectIntoOutfile,
  8394. FileName: $3,
  8395. }
  8396. if $4 != nil {
  8397. x.FieldsInfo = $4.(*ast.FieldsClause)
  8398. }
  8399. if $5 != nil {
  8400. x.LinesInfo = $5.(*ast.LinesClause)
  8401. }
  8402. $$ = x
  8403. }
  8404. // See https://dev.mysql.com/doc/refman/5.7/en/subqueries.html
  8405. SubSelect:
  8406. '(' SetOprStmt1 ')'
  8407. {
  8408. if s, isSel := $2.(*ast.SelectStmt); isSel {
  8409. endOffset := parser.endOffset(&yyS[yypt])
  8410. parser.setLastSelectFieldText(s, endOffset)
  8411. }
  8412. rs := $2.(ast.ResultSetNode)
  8413. src := parser.src
  8414. // See the implementation of yyParse function
  8415. rs.SetText(src[yyS[yypt-1].offset:yyS[yypt].offset])
  8416. $$ = &ast.SubqueryExpr{Query: rs}
  8417. }
  8418. SubSelect2:
  8419. '(' SetOprStmt2 ')'
  8420. {
  8421. if s, isSel := $2.(*ast.SelectStmt); isSel {
  8422. endOffset := parser.endOffset(&yyS[yypt])
  8423. parser.setLastSelectFieldText(s, endOffset)
  8424. }
  8425. rs := $2.(ast.ResultSetNode)
  8426. src := parser.src
  8427. // See the implementation of yyParse function
  8428. rs.SetText(src[yyS[yypt-1].offset:yyS[yypt].offset])
  8429. $$ = &ast.SubqueryExpr{Query: rs}
  8430. }
  8431. // See https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html
  8432. SelectLockOpt:
  8433. /* empty */
  8434. {
  8435. $$ = nil
  8436. }
  8437. | "FOR" "UPDATE"
  8438. {
  8439. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForUpdate}
  8440. }
  8441. | "FOR" "SHARE"
  8442. {
  8443. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShare}
  8444. }
  8445. | "FOR" "UPDATE" "NOWAIT"
  8446. {
  8447. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForUpdateNoWait}
  8448. }
  8449. | "FOR" "UPDATE" "WAIT" NUM
  8450. {
  8451. $$ = &ast.SelectLockInfo{
  8452. LockType: ast.SelectLockForUpdateWaitN,
  8453. WaitSec: getUint64FromNUM($4),
  8454. }
  8455. }
  8456. | "FOR" "SHARE" "NOWAIT"
  8457. {
  8458. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShareNoWait}
  8459. }
  8460. | "FOR" "UPDATE" "SKIP" "LOCKED"
  8461. {
  8462. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForUpdateSkipLocked}
  8463. }
  8464. | "FOR" "SHARE" "SKIP" "LOCKED"
  8465. {
  8466. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShareSkipLocked}
  8467. }
  8468. | "LOCK" "IN" "SHARE" "MODE"
  8469. {
  8470. $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShare}
  8471. }
  8472. SetOprStmt1:
  8473. SetOprClauseList %prec lowerThanParenthese
  8474. {
  8475. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: $1.([]ast.Node)}}
  8476. lastSelect := setOpr.SelectList.Selects[len(setOpr.SelectList.Selects)-1]
  8477. if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && len(setOpr.SelectList.Selects) == 1 {
  8478. $$ = sel
  8479. } else {
  8480. if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && !sel.IsInBraces {
  8481. setOpr.OrderBy = sel.OrderBy
  8482. setOpr.Limit = sel.Limit
  8483. sel.OrderBy = nil
  8484. sel.Limit = nil
  8485. }
  8486. $$ = setOpr
  8487. }
  8488. }
  8489. | SetOprStmt
  8490. SetOprStmt2:
  8491. SetOprClauseList %prec higherThanParenthese
  8492. {
  8493. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: $1.([]ast.Node)}}
  8494. lastSelect := setOpr.SelectList.Selects[len(setOpr.SelectList.Selects)-1]
  8495. if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && len(setOpr.SelectList.Selects) == 1 {
  8496. $$ = sel
  8497. } else {
  8498. if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && !sel.IsInBraces {
  8499. setOpr.OrderBy = sel.OrderBy
  8500. setOpr.Limit = sel.Limit
  8501. sel.OrderBy = nil
  8502. sel.Limit = nil
  8503. }
  8504. $$ = setOpr
  8505. }
  8506. }
  8507. | SetOprStmt
  8508. // See https://dev.mysql.com/doc/refman/5.7/en/union.html
  8509. // See https://mariadb.com/kb/en/intersect/
  8510. // See https://mariadb.com/kb/en/except/
  8511. SetOprStmt:
  8512. SetOprClauseList SetOpr '(' SetOprClauseList ')' OrderBy
  8513. {
  8514. setOprList1 := $1.([]ast.Node)
  8515. setOprList2 := $4.([]ast.Node)
  8516. if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
  8517. endOffset := parser.endOffset(&yyS[yypt-4])
  8518. parser.setLastSelectFieldText(sel, endOffset)
  8519. }
  8520. nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2}
  8521. nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType)
  8522. setOprList := append(setOprList1, nextSetOprList)
  8523. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}}
  8524. setOpr.OrderBy = $6.(*ast.OrderByClause)
  8525. $$ = setOpr
  8526. }
  8527. | SetOprClauseList SetOpr '(' SetOprClauseList ')' SelectStmtLimit
  8528. {
  8529. setOprList1 := $1.([]ast.Node)
  8530. setOprList2 := $4.([]ast.Node)
  8531. if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
  8532. endOffset := parser.endOffset(&yyS[yypt-4])
  8533. parser.setLastSelectFieldText(sel, endOffset)
  8534. }
  8535. nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2}
  8536. nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType)
  8537. setOprList := append(setOprList1, nextSetOprList)
  8538. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}}
  8539. setOpr.Limit = $6.(*ast.Limit)
  8540. $$ = setOpr
  8541. }
  8542. | SetOprClauseList SetOpr '(' SetOprClauseList ')' OrderBy SelectStmtLimit
  8543. {
  8544. setOprList1 := $1.([]ast.Node)
  8545. setOprList2 := $4.([]ast.Node)
  8546. if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
  8547. endOffset := parser.endOffset(&yyS[yypt-5])
  8548. parser.setLastSelectFieldText(sel, endOffset)
  8549. }
  8550. nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2}
  8551. nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType)
  8552. setOprList := append(setOprList1, nextSetOprList)
  8553. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}}
  8554. setOpr.OrderBy = $6.(*ast.OrderByClause)
  8555. setOpr.Limit = $7.(*ast.Limit)
  8556. $$ = setOpr
  8557. }
  8558. | '(' SetOprClauseList ')' OrderBy
  8559. {
  8560. setOprList := $2.([]ast.Node)
  8561. if sel, isSelect := setOprList[0].(*ast.SelectStmt); isSelect && !sel.IsInBraces && len(setOprList) == 1 {
  8562. endOffset := parser.endOffset(&yyS[yypt-1])
  8563. parser.setLastSelectFieldText(sel, endOffset)
  8564. }
  8565. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: []ast.Node{&ast.SetOprSelectList{Selects: $2.([]ast.Node)}}}}
  8566. setOpr.OrderBy = $4.(*ast.OrderByClause)
  8567. $$ = setOpr
  8568. }
  8569. | '(' SetOprClauseList ')' SelectStmtLimit
  8570. {
  8571. setOprList := $2.([]ast.Node)
  8572. if sel, isSelect := setOprList[0].(*ast.SelectStmt); isSelect && !sel.IsInBraces && len(setOprList) == 1 {
  8573. endOffset := parser.endOffset(&yyS[yypt-1])
  8574. parser.setLastSelectFieldText(sel, endOffset)
  8575. }
  8576. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: []ast.Node{&ast.SetOprSelectList{Selects: setOprList}}}}
  8577. setOpr.Limit = $4.(*ast.Limit)
  8578. $$ = setOpr
  8579. }
  8580. | '(' SetOprClauseList ')' OrderBy SelectStmtLimit
  8581. {
  8582. setOprList := $2.([]ast.Node)
  8583. if sel, isSelect := setOprList[0].(*ast.SelectStmt); isSelect && !sel.IsInBraces && len(setOprList) == 1 {
  8584. endOffset := parser.endOffset(&yyS[yypt-2])
  8585. parser.setLastSelectFieldText(sel, endOffset)
  8586. }
  8587. setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: []ast.Node{&ast.SetOprSelectList{Selects: setOprList}}}}
  8588. setOpr.OrderBy = $4.(*ast.OrderByClause)
  8589. setOpr.Limit = $5.(*ast.Limit)
  8590. $$ = setOpr
  8591. }
  8592. SetOprClauseList:
  8593. SetOprClause
  8594. | SetOprClauseList SetOpr SetOprClause
  8595. {
  8596. setOprList1 := $1.([]ast.Node)
  8597. setOprList2 := $3.([]ast.Node)
  8598. if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
  8599. endOffset := parser.endOffset(&yyS[yypt-1])
  8600. parser.setLastSelectFieldText(sel, endOffset)
  8601. }
  8602. switch x := setOprList2[0].(type) {
  8603. case *ast.SelectStmt:
  8604. x.AfterSetOperator = $2.(*ast.SetOprType)
  8605. case *ast.SetOprSelectList:
  8606. x.AfterSetOperator = $2.(*ast.SetOprType)
  8607. }
  8608. $$ = append(setOprList1, setOprList2...)
  8609. }
  8610. SetOprClause:
  8611. SelectStmt
  8612. {
  8613. $$ = []ast.Node{$1.(*ast.SelectStmt)}
  8614. }
  8615. | '(' SetOprClauseList ')'
  8616. {
  8617. setList := $2.([]ast.Node)
  8618. if sel, isSelect := setList[0].(*ast.SelectStmt); isSelect && len(setList) == 1 {
  8619. endOffset := parser.endOffset(&yyS[yypt])
  8620. parser.setLastSelectFieldText(sel, endOffset)
  8621. sel.IsInBraces = true
  8622. } else {
  8623. setList = []ast.Node{&ast.SetOprSelectList{Selects: $2.([]ast.Node)}}
  8624. }
  8625. $$ = setList
  8626. }
  8627. SetOpr:
  8628. "UNION" SetOprOpt
  8629. {
  8630. var tp ast.SetOprType
  8631. tp = ast.Union
  8632. if $2 == false {
  8633. tp = ast.UnionAll
  8634. }
  8635. $$ = &tp
  8636. }
  8637. | "EXCEPT" SetOprOpt
  8638. {
  8639. var tp ast.SetOprType
  8640. tp = ast.Except
  8641. if $2 == false {
  8642. tp = ast.ExceptAll
  8643. }
  8644. $$ = &tp
  8645. }
  8646. | "INTERSECT" SetOprOpt
  8647. {
  8648. var tp ast.SetOprType
  8649. tp = ast.Intersect
  8650. if $2 == false {
  8651. tp = ast.IntersectAll
  8652. }
  8653. $$ = &tp
  8654. }
  8655. SetOprOpt:
  8656. DefaultTrueDistinctOpt
  8657. /********************Change Statement*******************************/
  8658. ChangeStmt:
  8659. "CHANGE" "PUMP" "TO" "NODE_STATE" eq stringLit forKwd "NODE_ID" stringLit
  8660. {
  8661. $$ = &ast.ChangeStmt{
  8662. NodeType: ast.PumpType,
  8663. State: $6,
  8664. NodeID: $9,
  8665. }
  8666. }
  8667. | "CHANGE" "DRAINER" "TO" "NODE_STATE" eq stringLit forKwd "NODE_ID" stringLit
  8668. {
  8669. $$ = &ast.ChangeStmt{
  8670. NodeType: ast.DrainerType,
  8671. State: $6,
  8672. NodeID: $9,
  8673. }
  8674. }
  8675. /********************Set Statement*******************************/
  8676. SetStmt:
  8677. "SET" VariableAssignmentList
  8678. {
  8679. $$ = &ast.SetStmt{Variables: $2.([]*ast.VariableAssignment)}
  8680. }
  8681. | "SET" "PASSWORD" eq PasswordOpt
  8682. {
  8683. $$ = &ast.SetPwdStmt{Password: $4}
  8684. }
  8685. | "SET" "PASSWORD" "FOR" Username eq PasswordOpt
  8686. {
  8687. $$ = &ast.SetPwdStmt{User: $4.(*auth.UserIdentity), Password: $6}
  8688. }
  8689. | "SET" "GLOBAL" "TRANSACTION" TransactionChars
  8690. {
  8691. vars := $4.([]*ast.VariableAssignment)
  8692. for _, v := range vars {
  8693. v.IsGlobal = true
  8694. }
  8695. $$ = &ast.SetStmt{Variables: vars}
  8696. }
  8697. | "SET" "SESSION" "TRANSACTION" TransactionChars
  8698. {
  8699. $$ = &ast.SetStmt{Variables: $4.([]*ast.VariableAssignment)}
  8700. }
  8701. | "SET" "TRANSACTION" TransactionChars
  8702. {
  8703. assigns := $3.([]*ast.VariableAssignment)
  8704. for i := 0; i < len(assigns); i++ {
  8705. if assigns[i].Name == "tx_isolation" {
  8706. // A special session variable that make setting tx_isolation take effect one time.
  8707. assigns[i].Name = "tx_isolation_one_shot"
  8708. }
  8709. }
  8710. $$ = &ast.SetStmt{Variables: assigns}
  8711. }
  8712. | "SET" "CONFIG" Identifier ConfigItemName EqOrAssignmentEq SetExpr
  8713. {
  8714. $$ = &ast.SetConfigStmt{Type: strings.ToLower($3), Name: $4, Value: $6}
  8715. }
  8716. | "SET" "CONFIG" stringLit ConfigItemName EqOrAssignmentEq SetExpr
  8717. {
  8718. $$ = &ast.SetConfigStmt{Instance: $3, Name: $4, Value: $6}
  8719. }
  8720. SetRoleStmt:
  8721. "SET" "ROLE" SetRoleOpt
  8722. {
  8723. $$ = $3.(*ast.SetRoleStmt)
  8724. }
  8725. SetDefaultRoleStmt:
  8726. "SET" "DEFAULT" "ROLE" SetDefaultRoleOpt "TO" UsernameList
  8727. {
  8728. tmp := $4.(*ast.SetRoleStmt)
  8729. $$ = &ast.SetDefaultRoleStmt{
  8730. SetRoleOpt: tmp.SetRoleOpt,
  8731. RoleList: tmp.RoleList,
  8732. UserList: $6.([]*auth.UserIdentity),
  8733. }
  8734. }
  8735. SetDefaultRoleOpt:
  8736. "NONE"
  8737. {
  8738. $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleNone, RoleList: nil}
  8739. }
  8740. | "ALL"
  8741. {
  8742. $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleAll, RoleList: nil}
  8743. }
  8744. | RolenameList
  8745. {
  8746. $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleRegular, RoleList: $1.([]*auth.RoleIdentity)}
  8747. }
  8748. SetRoleOpt:
  8749. "ALL" "EXCEPT" RolenameList
  8750. {
  8751. $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleAllExcept, RoleList: $3.([]*auth.RoleIdentity)}
  8752. }
  8753. | SetDefaultRoleOpt
  8754. | "DEFAULT"
  8755. {
  8756. $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleDefault, RoleList: nil}
  8757. }
  8758. TransactionChars:
  8759. TransactionChar
  8760. {
  8761. if $1 != nil {
  8762. $$ = $1
  8763. } else {
  8764. $$ = []*ast.VariableAssignment{}
  8765. }
  8766. }
  8767. | TransactionChars ',' TransactionChar
  8768. {
  8769. if $3 != nil {
  8770. varAssigns := $3.([]*ast.VariableAssignment)
  8771. $$ = append($1.([]*ast.VariableAssignment), varAssigns...)
  8772. } else {
  8773. $$ = $1
  8774. }
  8775. }
  8776. TransactionChar:
  8777. "ISOLATION" "LEVEL" IsolationLevel
  8778. {
  8779. varAssigns := []*ast.VariableAssignment{}
  8780. expr := ast.NewValueExpr($3, parser.charset, parser.collation)
  8781. varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_isolation", Value: expr, IsSystem: true})
  8782. $$ = varAssigns
  8783. }
  8784. | "READ" "WRITE"
  8785. {
  8786. varAssigns := []*ast.VariableAssignment{}
  8787. expr := ast.NewValueExpr("0", parser.charset, parser.collation)
  8788. varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_only", Value: expr, IsSystem: true})
  8789. $$ = varAssigns
  8790. }
  8791. | "READ" "ONLY"
  8792. {
  8793. varAssigns := []*ast.VariableAssignment{}
  8794. expr := ast.NewValueExpr("1", parser.charset, parser.collation)
  8795. varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_only", Value: expr, IsSystem: true})
  8796. $$ = varAssigns
  8797. }
  8798. IsolationLevel:
  8799. "REPEATABLE" "READ"
  8800. {
  8801. $$ = ast.RepeatableRead
  8802. }
  8803. | "READ" "COMMITTED"
  8804. {
  8805. $$ = ast.ReadCommitted
  8806. }
  8807. | "READ" "UNCOMMITTED"
  8808. {
  8809. $$ = ast.ReadUncommitted
  8810. }
  8811. | "SERIALIZABLE"
  8812. {
  8813. $$ = ast.Serializable
  8814. }
  8815. SetExpr:
  8816. "ON"
  8817. {
  8818. $$ = ast.NewValueExpr("ON", parser.charset, parser.collation)
  8819. }
  8820. | ExprOrDefault
  8821. EqOrAssignmentEq:
  8822. eq
  8823. | assignmentEq
  8824. VariableName:
  8825. Identifier
  8826. | Identifier '.' Identifier
  8827. {
  8828. $$ = $1 + "." + $3
  8829. }
  8830. ConfigItemName:
  8831. Identifier
  8832. | Identifier '.' ConfigItemName
  8833. {
  8834. $$ = $1 + "." + $3
  8835. }
  8836. | Identifier '-' ConfigItemName
  8837. {
  8838. $$ = $1 + "-" + $3
  8839. }
  8840. VariableAssignment:
  8841. VariableName EqOrAssignmentEq SetExpr
  8842. {
  8843. $$ = &ast.VariableAssignment{Name: $1, Value: $3, IsSystem: true}
  8844. }
  8845. | "GLOBAL" VariableName EqOrAssignmentEq SetExpr
  8846. {
  8847. $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsGlobal: true, IsSystem: true}
  8848. }
  8849. | "SESSION" VariableName EqOrAssignmentEq SetExpr
  8850. {
  8851. $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsSystem: true}
  8852. }
  8853. | "LOCAL" VariableName EqOrAssignmentEq Expression
  8854. {
  8855. $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsSystem: true}
  8856. }
  8857. | doubleAtIdentifier EqOrAssignmentEq SetExpr
  8858. {
  8859. v := strings.ToLower($1)
  8860. var isGlobal bool
  8861. if strings.HasPrefix(v, "@@global.") {
  8862. isGlobal = true
  8863. v = strings.TrimPrefix(v, "@@global.")
  8864. } else if strings.HasPrefix(v, "@@session.") {
  8865. v = strings.TrimPrefix(v, "@@session.")
  8866. } else if strings.HasPrefix(v, "@@local.") {
  8867. v = strings.TrimPrefix(v, "@@local.")
  8868. } else if strings.HasPrefix(v, "@@") {
  8869. v = strings.TrimPrefix(v, "@@")
  8870. }
  8871. $$ = &ast.VariableAssignment{Name: v, Value: $3, IsGlobal: isGlobal, IsSystem: true}
  8872. }
  8873. | singleAtIdentifier EqOrAssignmentEq Expression
  8874. {
  8875. v := $1
  8876. v = strings.TrimPrefix(v, "@")
  8877. $$ = &ast.VariableAssignment{Name: v, Value: $3}
  8878. }
  8879. | "NAMES" CharsetName
  8880. {
  8881. $$ = &ast.VariableAssignment{
  8882. Name: ast.SetNames,
  8883. Value: ast.NewValueExpr($2, "", ""),
  8884. }
  8885. }
  8886. | "NAMES" CharsetName "COLLATE" "DEFAULT"
  8887. {
  8888. $$ = &ast.VariableAssignment{
  8889. Name: ast.SetNames,
  8890. Value: ast.NewValueExpr($2, "", ""),
  8891. }
  8892. }
  8893. | "NAMES" CharsetName "COLLATE" StringName
  8894. {
  8895. $$ = &ast.VariableAssignment{
  8896. Name: ast.SetNames,
  8897. Value: ast.NewValueExpr($2, "", ""),
  8898. ExtendValue: ast.NewValueExpr($4, "", ""),
  8899. }
  8900. }
  8901. | "NAMES" "DEFAULT"
  8902. {
  8903. v := &ast.DefaultExpr{}
  8904. $$ = &ast.VariableAssignment{Name: ast.SetNames, Value: v}
  8905. }
  8906. | CharsetKw CharsetNameOrDefault
  8907. {
  8908. $$ = &ast.VariableAssignment{Name: ast.SetCharset, Value: $2}
  8909. }
  8910. CharsetNameOrDefault:
  8911. CharsetName
  8912. {
  8913. $$ = ast.NewValueExpr($1, "", "")
  8914. }
  8915. | "DEFAULT"
  8916. {
  8917. $$ = &ast.DefaultExpr{}
  8918. }
  8919. CharsetName:
  8920. StringName
  8921. {
  8922. // Validate input charset name to keep the same behavior as parser of MySQL.
  8923. name, _, err := charset.GetCharsetInfo($1)
  8924. if err != nil {
  8925. yylex.AppendError(ErrUnknownCharacterSet.GenWithStackByArgs($1))
  8926. return 1
  8927. }
  8928. // Use charset name returned from charset.GetCharsetInfo(),
  8929. // to keep lower case of input for generated column restore.
  8930. $$ = name
  8931. }
  8932. | binaryType
  8933. {
  8934. $$ = charset.CharsetBin
  8935. }
  8936. CollationName:
  8937. StringName
  8938. {
  8939. info, err := charset.GetCollationByName($1)
  8940. if err != nil {
  8941. yylex.AppendError(err)
  8942. return 1
  8943. }
  8944. $$ = info.Name
  8945. }
  8946. | binaryType
  8947. {
  8948. $$ = charset.CollationBin
  8949. }
  8950. VariableAssignmentList:
  8951. VariableAssignment
  8952. {
  8953. $$ = []*ast.VariableAssignment{$1.(*ast.VariableAssignment)}
  8954. }
  8955. | VariableAssignmentList ',' VariableAssignment
  8956. {
  8957. $$ = append($1.([]*ast.VariableAssignment), $3.(*ast.VariableAssignment))
  8958. }
  8959. Variable:
  8960. SystemVariable
  8961. | UserVariable
  8962. SystemVariable:
  8963. doubleAtIdentifier
  8964. {
  8965. v := strings.ToLower($1)
  8966. var isGlobal bool
  8967. explicitScope := true
  8968. if strings.HasPrefix(v, "@@global.") {
  8969. isGlobal = true
  8970. v = strings.TrimPrefix(v, "@@global.")
  8971. } else if strings.HasPrefix(v, "@@session.") {
  8972. v = strings.TrimPrefix(v, "@@session.")
  8973. } else if strings.HasPrefix(v, "@@local.") {
  8974. v = strings.TrimPrefix(v, "@@local.")
  8975. } else if strings.HasPrefix(v, "@@") {
  8976. v, explicitScope = strings.TrimPrefix(v, "@@"), false
  8977. }
  8978. $$ = &ast.VariableExpr{Name: v, IsGlobal: isGlobal, IsSystem: true, ExplicitScope: explicitScope}
  8979. }
  8980. UserVariable:
  8981. singleAtIdentifier
  8982. {
  8983. v := $1
  8984. v = strings.TrimPrefix(v, "@")
  8985. $$ = &ast.VariableExpr{Name: v, IsGlobal: false, IsSystem: false}
  8986. }
  8987. Username:
  8988. StringName
  8989. {
  8990. $$ = &auth.UserIdentity{Username: $1, Hostname: "%"}
  8991. }
  8992. | StringName '@' StringName
  8993. {
  8994. $$ = &auth.UserIdentity{Username: $1, Hostname: $3}
  8995. }
  8996. | StringName singleAtIdentifier
  8997. {
  8998. $$ = &auth.UserIdentity{Username: $1, Hostname: strings.TrimPrefix($2, "@")}
  8999. }
  9000. | "CURRENT_USER" OptionalBraces
  9001. {
  9002. $$ = &auth.UserIdentity{CurrentUser: true}
  9003. }
  9004. UsernameList:
  9005. Username
  9006. {
  9007. $$ = []*auth.UserIdentity{$1.(*auth.UserIdentity)}
  9008. }
  9009. | UsernameList ',' Username
  9010. {
  9011. $$ = append($1.([]*auth.UserIdentity), $3.(*auth.UserIdentity))
  9012. }
  9013. PasswordOpt:
  9014. stringLit
  9015. | "PASSWORD" '(' AuthString ')'
  9016. {
  9017. $$ = $3
  9018. }
  9019. AuthString:
  9020. stringLit
  9021. RoleNameString:
  9022. stringLit
  9023. | identifier
  9024. RolenameComposed:
  9025. StringName '@' StringName
  9026. {
  9027. $$ = &auth.RoleIdentity{Username: $1, Hostname: $3}
  9028. }
  9029. | StringName singleAtIdentifier
  9030. {
  9031. $$ = &auth.RoleIdentity{Username: $1, Hostname: strings.TrimPrefix($2, "@")}
  9032. }
  9033. RolenameWithoutIdent:
  9034. stringLit
  9035. {
  9036. $$ = &auth.RoleIdentity{Username: $1, Hostname: "%"}
  9037. }
  9038. | RolenameComposed
  9039. {
  9040. $$ = $1
  9041. }
  9042. Rolename:
  9043. RoleNameString
  9044. {
  9045. $$ = &auth.RoleIdentity{Username: $1, Hostname: "%"}
  9046. }
  9047. | RolenameComposed
  9048. {
  9049. $$ = $1
  9050. }
  9051. RolenameList:
  9052. Rolename
  9053. {
  9054. $$ = []*auth.RoleIdentity{$1.(*auth.RoleIdentity)}
  9055. }
  9056. | RolenameList ',' Rolename
  9057. {
  9058. $$ = append($1.([]*auth.RoleIdentity), $3.(*auth.RoleIdentity))
  9059. }
  9060. /****************************Admin Statement*******************************/
  9061. AdminStmt:
  9062. "ADMIN" "SHOW" "DDL"
  9063. {
  9064. $$ = &ast.AdminStmt{Tp: ast.AdminShowDDL}
  9065. }
  9066. | "ADMIN" "SHOW" "DDL" "JOBS" WhereClauseOptional
  9067. {
  9068. stmt := &ast.AdminStmt{Tp: ast.AdminShowDDLJobs}
  9069. if $5 != nil {
  9070. stmt.Where = $5.(ast.ExprNode)
  9071. }
  9072. $$ = stmt
  9073. }
  9074. | "ADMIN" "SHOW" "DDL" "JOBS" Int64Num WhereClauseOptional
  9075. {
  9076. stmt := &ast.AdminStmt{
  9077. Tp: ast.AdminShowDDLJobs,
  9078. JobNumber: $5.(int64),
  9079. }
  9080. if $6 != nil {
  9081. stmt.Where = $6.(ast.ExprNode)
  9082. }
  9083. $$ = stmt
  9084. }
  9085. | "ADMIN" "SHOW" TableName "NEXT_ROW_ID"
  9086. {
  9087. $$ = &ast.AdminStmt{
  9088. Tp: ast.AdminShowNextRowID,
  9089. Tables: []*ast.TableName{$3.(*ast.TableName)},
  9090. }
  9091. }
  9092. | "ADMIN" "CHECK" "TABLE" TableNameList
  9093. {
  9094. $$ = &ast.AdminStmt{
  9095. Tp: ast.AdminCheckTable,
  9096. Tables: $4.([]*ast.TableName),
  9097. }
  9098. }
  9099. | "ADMIN" "CHECK" "INDEX" TableName Identifier
  9100. {
  9101. $$ = &ast.AdminStmt{
  9102. Tp: ast.AdminCheckIndex,
  9103. Tables: []*ast.TableName{$4.(*ast.TableName)},
  9104. Index: string($5),
  9105. }
  9106. }
  9107. | "ADMIN" "RECOVER" "INDEX" TableName Identifier
  9108. {
  9109. $$ = &ast.AdminStmt{
  9110. Tp: ast.AdminRecoverIndex,
  9111. Tables: []*ast.TableName{$4.(*ast.TableName)},
  9112. Index: string($5),
  9113. }
  9114. }
  9115. | "ADMIN" "CLEANUP" "INDEX" TableName Identifier
  9116. {
  9117. $$ = &ast.AdminStmt{
  9118. Tp: ast.AdminCleanupIndex,
  9119. Tables: []*ast.TableName{$4.(*ast.TableName)},
  9120. Index: string($5),
  9121. }
  9122. }
  9123. | "ADMIN" "CHECK" "INDEX" TableName Identifier HandleRangeList
  9124. {
  9125. $$ = &ast.AdminStmt{
  9126. Tp: ast.AdminCheckIndexRange,
  9127. Tables: []*ast.TableName{$4.(*ast.TableName)},
  9128. Index: string($5),
  9129. HandleRanges: $6.([]ast.HandleRange),
  9130. }
  9131. }
  9132. | "ADMIN" "CHECKSUM" "TABLE" TableNameList
  9133. {
  9134. $$ = &ast.AdminStmt{
  9135. Tp: ast.AdminChecksumTable,
  9136. Tables: $4.([]*ast.TableName),
  9137. }
  9138. }
  9139. | "ADMIN" "CANCEL" "DDL" "JOBS" NumList
  9140. {
  9141. $$ = &ast.AdminStmt{
  9142. Tp: ast.AdminCancelDDLJobs,
  9143. JobIDs: $5.([]int64),
  9144. }
  9145. }
  9146. | "ADMIN" "SHOW" "DDL" "JOB" "QUERIES" NumList
  9147. {
  9148. $$ = &ast.AdminStmt{
  9149. Tp: ast.AdminShowDDLJobQueries,
  9150. JobIDs: $6.([]int64),
  9151. }
  9152. }
  9153. | "ADMIN" "SHOW" "SLOW" AdminShowSlow
  9154. {
  9155. $$ = &ast.AdminStmt{
  9156. Tp: ast.AdminShowSlow,
  9157. ShowSlow: $4.(*ast.ShowSlow),
  9158. }
  9159. }
  9160. | "ADMIN" "RELOAD" "EXPR_PUSHDOWN_BLACKLIST"
  9161. {
  9162. $$ = &ast.AdminStmt{
  9163. Tp: ast.AdminReloadExprPushdownBlacklist,
  9164. }
  9165. }
  9166. | "ADMIN" "RELOAD" "OPT_RULE_BLACKLIST"
  9167. {
  9168. $$ = &ast.AdminStmt{
  9169. Tp: ast.AdminReloadOptRuleBlacklist,
  9170. }
  9171. }
  9172. | "ADMIN" "PLUGINS" "ENABLE" PluginNameList
  9173. {
  9174. $$ = &ast.AdminStmt{
  9175. Tp: ast.AdminPluginEnable,
  9176. Plugins: $4.([]string),
  9177. }
  9178. }
  9179. | "ADMIN" "PLUGINS" "DISABLE" PluginNameList
  9180. {
  9181. $$ = &ast.AdminStmt{
  9182. Tp: ast.AdminPluginDisable,
  9183. Plugins: $4.([]string),
  9184. }
  9185. }
  9186. | "ADMIN" "CLEANUP" "TABLE" "LOCK" TableNameList
  9187. {
  9188. $$ = &ast.CleanupTableLockStmt{
  9189. Tables: $5.([]*ast.TableName),
  9190. }
  9191. }
  9192. | "ADMIN" "REPAIR" "TABLE" TableName CreateTableStmt
  9193. {
  9194. $$ = &ast.RepairTableStmt{
  9195. Table: $4.(*ast.TableName),
  9196. CreateStmt: $5.(*ast.CreateTableStmt),
  9197. }
  9198. }
  9199. | "ADMIN" "FLUSH" "BINDINGS"
  9200. {
  9201. $$ = &ast.AdminStmt{
  9202. Tp: ast.AdminFlushBindings,
  9203. }
  9204. }
  9205. | "ADMIN" "CAPTURE" "BINDINGS"
  9206. {
  9207. $$ = &ast.AdminStmt{
  9208. Tp: ast.AdminCaptureBindings,
  9209. }
  9210. }
  9211. | "ADMIN" "EVOLVE" "BINDINGS"
  9212. {
  9213. $$ = &ast.AdminStmt{
  9214. Tp: ast.AdminEvolveBindings,
  9215. }
  9216. }
  9217. | "ADMIN" "RELOAD" "BINDINGS"
  9218. {
  9219. $$ = &ast.AdminStmt{
  9220. Tp: ast.AdminReloadBindings,
  9221. }
  9222. }
  9223. | "ADMIN" "RELOAD" "STATS_EXTENDED"
  9224. {
  9225. $$ = &ast.AdminStmt{
  9226. Tp: ast.AdminReloadStatistics,
  9227. }
  9228. }
  9229. | "ADMIN" "RELOAD" "STATISTICS"
  9230. {
  9231. $$ = &ast.AdminStmt{
  9232. Tp: ast.AdminReloadStatistics,
  9233. }
  9234. }
  9235. | "ADMIN" "SHOW" "TELEMETRY"
  9236. {
  9237. $$ = &ast.AdminStmt{
  9238. Tp: ast.AdminShowTelemetry,
  9239. }
  9240. }
  9241. | "ADMIN" "RESET" "TELEMETRY_ID"
  9242. {
  9243. $$ = &ast.AdminStmt{
  9244. Tp: ast.AdminResetTelemetryID,
  9245. }
  9246. }
  9247. AdminShowSlow:
  9248. "RECENT" NUM
  9249. {
  9250. $$ = &ast.ShowSlow{
  9251. Tp: ast.ShowSlowRecent,
  9252. Count: getUint64FromNUM($2),
  9253. }
  9254. }
  9255. | "TOP" NUM
  9256. {
  9257. $$ = &ast.ShowSlow{
  9258. Tp: ast.ShowSlowTop,
  9259. Kind: ast.ShowSlowKindDefault,
  9260. Count: getUint64FromNUM($2),
  9261. }
  9262. }
  9263. | "TOP" "INTERNAL" NUM
  9264. {
  9265. $$ = &ast.ShowSlow{
  9266. Tp: ast.ShowSlowTop,
  9267. Kind: ast.ShowSlowKindInternal,
  9268. Count: getUint64FromNUM($3),
  9269. }
  9270. }
  9271. | "TOP" "ALL" NUM
  9272. {
  9273. $$ = &ast.ShowSlow{
  9274. Tp: ast.ShowSlowTop,
  9275. Kind: ast.ShowSlowKindAll,
  9276. Count: getUint64FromNUM($3),
  9277. }
  9278. }
  9279. HandleRangeList:
  9280. HandleRange
  9281. {
  9282. $$ = []ast.HandleRange{$1.(ast.HandleRange)}
  9283. }
  9284. | HandleRangeList ',' HandleRange
  9285. {
  9286. $$ = append($1.([]ast.HandleRange), $3.(ast.HandleRange))
  9287. }
  9288. HandleRange:
  9289. '(' Int64Num ',' Int64Num ')'
  9290. {
  9291. $$ = ast.HandleRange{Begin: $2.(int64), End: $4.(int64)}
  9292. }
  9293. NumList:
  9294. Int64Num
  9295. {
  9296. $$ = []int64{$1.(int64)}
  9297. }
  9298. | NumList ',' Int64Num
  9299. {
  9300. $$ = append($1.([]int64), $3.(int64))
  9301. }
  9302. /****************************Show Statement*******************************/
  9303. ShowStmt:
  9304. "SHOW" ShowTargetFilterable ShowLikeOrWhereOpt
  9305. {
  9306. stmt := $2.(*ast.ShowStmt)
  9307. if $3 != nil {
  9308. if x, ok := $3.(*ast.PatternLikeExpr); ok && x.Expr == nil {
  9309. stmt.Pattern = x
  9310. } else {
  9311. stmt.Where = $3.(ast.ExprNode)
  9312. }
  9313. }
  9314. $$ = stmt
  9315. }
  9316. | "SHOW" "CREATE" "TABLE" TableName
  9317. {
  9318. $$ = &ast.ShowStmt{
  9319. Tp: ast.ShowCreateTable,
  9320. Table: $4.(*ast.TableName),
  9321. }
  9322. }
  9323. | "SHOW" "CREATE" "VIEW" TableName
  9324. {
  9325. $$ = &ast.ShowStmt{
  9326. Tp: ast.ShowCreateView,
  9327. Table: $4.(*ast.TableName),
  9328. }
  9329. }
  9330. | "SHOW" "CREATE" "DATABASE" IfNotExists DBName
  9331. {
  9332. $$ = &ast.ShowStmt{
  9333. Tp: ast.ShowCreateDatabase,
  9334. IfNotExists: $4.(bool),
  9335. DBName: $5,
  9336. }
  9337. }
  9338. | "SHOW" "CREATE" "SEQUENCE" TableName
  9339. {
  9340. $$ = &ast.ShowStmt{
  9341. Tp: ast.ShowCreateSequence,
  9342. Table: $4.(*ast.TableName),
  9343. }
  9344. }
  9345. | "SHOW" "CREATE" "USER" Username
  9346. {
  9347. // See https://dev.mysql.com/doc/refman/5.7/en/show-create-user.html
  9348. $$ = &ast.ShowStmt{
  9349. Tp: ast.ShowCreateUser,
  9350. User: $4.(*auth.UserIdentity),
  9351. }
  9352. }
  9353. | "SHOW" "CREATE" "IMPORT" Identifier
  9354. {
  9355. $$ = &ast.ShowStmt{
  9356. Tp: ast.ShowCreateImport,
  9357. DBName: $4, // we reuse DBName of ShowStmt
  9358. }
  9359. }
  9360. | "SHOW" "TABLE" TableName PartitionNameListOpt "REGIONS" WhereClauseOptional
  9361. {
  9362. stmt := &ast.ShowStmt{
  9363. Tp: ast.ShowRegions,
  9364. Table: $3.(*ast.TableName),
  9365. }
  9366. stmt.Table.PartitionNames = $4.([]model.CIStr)
  9367. if $6 != nil {
  9368. stmt.Where = $6.(ast.ExprNode)
  9369. }
  9370. $$ = stmt
  9371. }
  9372. | "SHOW" "TABLE" TableName "NEXT_ROW_ID"
  9373. {
  9374. $$ = &ast.ShowStmt{
  9375. Tp: ast.ShowTableNextRowId,
  9376. Table: $3.(*ast.TableName),
  9377. }
  9378. }
  9379. | "SHOW" "TABLE" TableName PartitionNameListOpt "INDEX" Identifier "REGIONS" WhereClauseOptional
  9380. {
  9381. stmt := &ast.ShowStmt{
  9382. Tp: ast.ShowRegions,
  9383. Table: $3.(*ast.TableName),
  9384. IndexName: model.NewCIStr($6),
  9385. }
  9386. stmt.Table.PartitionNames = $4.([]model.CIStr)
  9387. if $8 != nil {
  9388. stmt.Where = $8.(ast.ExprNode)
  9389. }
  9390. $$ = stmt
  9391. }
  9392. | "SHOW" "GRANTS"
  9393. {
  9394. // See https://dev.mysql.com/doc/refman/5.7/en/show-grants.html
  9395. $$ = &ast.ShowStmt{Tp: ast.ShowGrants}
  9396. }
  9397. | "SHOW" "GRANTS" "FOR" Username UsingRoles
  9398. {
  9399. // See https://dev.mysql.com/doc/refman/5.7/en/show-grants.html
  9400. if $5 != nil {
  9401. $$ = &ast.ShowStmt{
  9402. Tp: ast.ShowGrants,
  9403. User: $4.(*auth.UserIdentity),
  9404. Roles: $5.([]*auth.RoleIdentity),
  9405. }
  9406. } else {
  9407. $$ = &ast.ShowStmt{
  9408. Tp: ast.ShowGrants,
  9409. User: $4.(*auth.UserIdentity),
  9410. Roles: nil,
  9411. }
  9412. }
  9413. }
  9414. | "SHOW" "MASTER" "STATUS"
  9415. {
  9416. $$ = &ast.ShowStmt{
  9417. Tp: ast.ShowMasterStatus,
  9418. }
  9419. }
  9420. | "SHOW" OptFull "PROCESSLIST"
  9421. {
  9422. $$ = &ast.ShowStmt{
  9423. Tp: ast.ShowProcessList,
  9424. Full: $2.(bool),
  9425. }
  9426. }
  9427. | "SHOW" "PROFILES"
  9428. {
  9429. $$ = &ast.ShowStmt{
  9430. Tp: ast.ShowProfiles,
  9431. }
  9432. }
  9433. | "SHOW" "PROFILE" ShowProfileTypesOpt ShowProfileArgsOpt SelectStmtLimitOpt
  9434. {
  9435. v := &ast.ShowStmt{
  9436. Tp: ast.ShowProfile,
  9437. }
  9438. if $3 != nil {
  9439. v.ShowProfileTypes = $3.([]int)
  9440. }
  9441. if $4 != nil {
  9442. v.ShowProfileArgs = $4.(*int64)
  9443. }
  9444. if $5 != nil {
  9445. v.ShowProfileLimit = $5.(*ast.Limit)
  9446. }
  9447. $$ = v
  9448. }
  9449. | "SHOW" "PRIVILEGES"
  9450. {
  9451. $$ = &ast.ShowStmt{
  9452. Tp: ast.ShowPrivileges,
  9453. }
  9454. }
  9455. | "SHOW" "BUILTINS"
  9456. {
  9457. $$ = &ast.ShowStmt{
  9458. Tp: ast.ShowBuiltins,
  9459. }
  9460. }
  9461. ShowProfileTypesOpt:
  9462. {
  9463. $$ = nil
  9464. }
  9465. | ShowProfileTypes
  9466. ShowProfileTypes:
  9467. ShowProfileType
  9468. {
  9469. $$ = []int{$1.(int)}
  9470. }
  9471. | ShowProfileTypes ',' ShowProfileType
  9472. {
  9473. l := $1.([]int)
  9474. l = append(l, $3.(int))
  9475. $$ = l
  9476. }
  9477. ShowProfileType:
  9478. "CPU"
  9479. {
  9480. $$ = ast.ProfileTypeCPU
  9481. }
  9482. | "MEMORY"
  9483. {
  9484. $$ = ast.ProfileTypeMemory
  9485. }
  9486. | "BLOCK" "IO"
  9487. {
  9488. $$ = ast.ProfileTypeBlockIo
  9489. }
  9490. | "CONTEXT" "SWITCHES"
  9491. {
  9492. $$ = ast.ProfileTypeContextSwitch
  9493. }
  9494. | "PAGE" "FAULTS"
  9495. {
  9496. $$ = ast.ProfileTypePageFaults
  9497. }
  9498. | "IPC"
  9499. {
  9500. $$ = ast.ProfileTypeIpc
  9501. }
  9502. | "SWAPS"
  9503. {
  9504. $$ = ast.ProfileTypeSwaps
  9505. }
  9506. | "SOURCE"
  9507. {
  9508. $$ = ast.ProfileTypeSource
  9509. }
  9510. | "ALL"
  9511. {
  9512. $$ = ast.ProfileTypeAll
  9513. }
  9514. ShowProfileArgsOpt:
  9515. {
  9516. $$ = nil
  9517. }
  9518. | "FOR" "QUERY" Int64Num
  9519. {
  9520. v := $3.(int64)
  9521. $$ = &v
  9522. }
  9523. UsingRoles:
  9524. {
  9525. $$ = nil
  9526. }
  9527. | "USING" RolenameList
  9528. {
  9529. $$ = $2.([]*auth.RoleIdentity)
  9530. }
  9531. ShowIndexKwd:
  9532. "INDEX"
  9533. | "INDEXES"
  9534. | "KEYS"
  9535. FromOrIn:
  9536. "FROM"
  9537. | "IN"
  9538. ShowTargetFilterable:
  9539. "ENGINES"
  9540. {
  9541. $$ = &ast.ShowStmt{Tp: ast.ShowEngines}
  9542. }
  9543. | "DATABASES"
  9544. {
  9545. $$ = &ast.ShowStmt{Tp: ast.ShowDatabases}
  9546. }
  9547. | "CONFIG"
  9548. {
  9549. $$ = &ast.ShowStmt{Tp: ast.ShowConfig}
  9550. }
  9551. | CharsetKw
  9552. {
  9553. $$ = &ast.ShowStmt{Tp: ast.ShowCharset}
  9554. }
  9555. | OptFull "TABLES" ShowDatabaseNameOpt
  9556. {
  9557. $$ = &ast.ShowStmt{
  9558. Tp: ast.ShowTables,
  9559. DBName: $3,
  9560. Full: $1.(bool),
  9561. }
  9562. }
  9563. | "OPEN" "TABLES" ShowDatabaseNameOpt
  9564. {
  9565. $$ = &ast.ShowStmt{
  9566. Tp: ast.ShowOpenTables,
  9567. DBName: $3,
  9568. }
  9569. }
  9570. | "TABLE" "STATUS" ShowDatabaseNameOpt
  9571. {
  9572. $$ = &ast.ShowStmt{
  9573. Tp: ast.ShowTableStatus,
  9574. DBName: $3,
  9575. }
  9576. }
  9577. | ShowIndexKwd FromOrIn TableName
  9578. {
  9579. $$ = &ast.ShowStmt{
  9580. Tp: ast.ShowIndex,
  9581. Table: $3.(*ast.TableName),
  9582. }
  9583. }
  9584. | ShowIndexKwd FromOrIn Identifier FromOrIn Identifier
  9585. {
  9586. show := &ast.ShowStmt{
  9587. Tp: ast.ShowIndex,
  9588. Table: &ast.TableName{Name: model.NewCIStr($3), Schema: model.NewCIStr($5)},
  9589. }
  9590. $$ = show
  9591. }
  9592. | OptFull FieldsOrColumns ShowTableAliasOpt ShowDatabaseNameOpt
  9593. {
  9594. $$ = &ast.ShowStmt{
  9595. Tp: ast.ShowColumns,
  9596. Table: $3.(*ast.TableName),
  9597. DBName: $4,
  9598. Full: $1.(bool),
  9599. }
  9600. }
  9601. | "EXTENDED" OptFull FieldsOrColumns ShowTableAliasOpt ShowDatabaseNameOpt
  9602. {
  9603. $$ = &ast.ShowStmt{
  9604. Tp: ast.ShowColumns,
  9605. Table: $4.(*ast.TableName),
  9606. DBName: $5,
  9607. Full: $2.(bool),
  9608. Extended: true,
  9609. }
  9610. }
  9611. | "WARNINGS"
  9612. {
  9613. $$ = &ast.ShowStmt{Tp: ast.ShowWarnings}
  9614. }
  9615. | "ERRORS"
  9616. {
  9617. $$ = &ast.ShowStmt{Tp: ast.ShowErrors}
  9618. }
  9619. | GlobalScope "VARIABLES"
  9620. {
  9621. $$ = &ast.ShowStmt{
  9622. Tp: ast.ShowVariables,
  9623. GlobalScope: $1.(bool),
  9624. }
  9625. }
  9626. | GlobalScope "STATUS"
  9627. {
  9628. $$ = &ast.ShowStmt{
  9629. Tp: ast.ShowStatus,
  9630. GlobalScope: $1.(bool),
  9631. }
  9632. }
  9633. | GlobalScope "BINDINGS"
  9634. {
  9635. $$ = &ast.ShowStmt{
  9636. Tp: ast.ShowBindings,
  9637. GlobalScope: $1.(bool),
  9638. }
  9639. }
  9640. | "COLLATION"
  9641. {
  9642. $$ = &ast.ShowStmt{
  9643. Tp: ast.ShowCollation,
  9644. }
  9645. }
  9646. | "TRIGGERS" ShowDatabaseNameOpt
  9647. {
  9648. $$ = &ast.ShowStmt{
  9649. Tp: ast.ShowTriggers,
  9650. DBName: $2,
  9651. }
  9652. }
  9653. | "PROCEDURE" "STATUS"
  9654. {
  9655. $$ = &ast.ShowStmt{
  9656. Tp: ast.ShowProcedureStatus,
  9657. }
  9658. }
  9659. | "PUMP" "STATUS"
  9660. {
  9661. $$ = &ast.ShowStmt{
  9662. Tp: ast.ShowPumpStatus,
  9663. }
  9664. }
  9665. | "DRAINER" "STATUS"
  9666. {
  9667. $$ = &ast.ShowStmt{
  9668. Tp: ast.ShowDrainerStatus,
  9669. }
  9670. }
  9671. | "FUNCTION" "STATUS"
  9672. {
  9673. // This statement is similar to SHOW PROCEDURE STATUS but for stored functions.
  9674. // See http://dev.mysql.com/doc/refman/5.7/en/show-function-status.html
  9675. // We do not support neither stored functions nor stored procedures.
  9676. // So we reuse show procedure status process logic.
  9677. $$ = &ast.ShowStmt{
  9678. Tp: ast.ShowProcedureStatus,
  9679. }
  9680. }
  9681. | "EVENTS" ShowDatabaseNameOpt
  9682. {
  9683. $$ = &ast.ShowStmt{
  9684. Tp: ast.ShowEvents,
  9685. DBName: $2,
  9686. }
  9687. }
  9688. | "PLUGINS"
  9689. {
  9690. $$ = &ast.ShowStmt{
  9691. Tp: ast.ShowPlugins,
  9692. }
  9693. }
  9694. | "STATS_EXTENDED"
  9695. {
  9696. $$ = &ast.ShowStmt{Tp: ast.ShowStatsExtended}
  9697. }
  9698. | "STATS_META"
  9699. {
  9700. $$ = &ast.ShowStmt{Tp: ast.ShowStatsMeta}
  9701. }
  9702. | "STATS_HISTOGRAMS"
  9703. {
  9704. $$ = &ast.ShowStmt{Tp: ast.ShowStatsHistograms}
  9705. }
  9706. | "STATS_TOPN"
  9707. {
  9708. $$ = &ast.ShowStmt{Tp: ast.ShowStatsTopN}
  9709. }
  9710. | "STATS_BUCKETS"
  9711. {
  9712. $$ = &ast.ShowStmt{Tp: ast.ShowStatsBuckets}
  9713. }
  9714. | "STATS_HEALTHY"
  9715. {
  9716. $$ = &ast.ShowStmt{Tp: ast.ShowStatsHealthy}
  9717. }
  9718. | "ANALYZE" "STATUS"
  9719. {
  9720. $$ = &ast.ShowStmt{Tp: ast.ShowAnalyzeStatus}
  9721. }
  9722. | "BACKUPS"
  9723. {
  9724. $$ = &ast.ShowStmt{Tp: ast.ShowBackups}
  9725. }
  9726. | "RESTORES"
  9727. {
  9728. $$ = &ast.ShowStmt{Tp: ast.ShowRestores}
  9729. }
  9730. | "IMPORTS"
  9731. {
  9732. $$ = &ast.ShowStmt{Tp: ast.ShowImports}
  9733. }
  9734. ShowLikeOrWhereOpt:
  9735. {
  9736. $$ = nil
  9737. }
  9738. | "LIKE" SimpleExpr
  9739. {
  9740. $$ = &ast.PatternLikeExpr{
  9741. Pattern: $2,
  9742. Escape: '\\',
  9743. }
  9744. }
  9745. | "WHERE" Expression
  9746. {
  9747. $$ = $2
  9748. }
  9749. GlobalScope:
  9750. {
  9751. $$ = false
  9752. }
  9753. | "GLOBAL"
  9754. {
  9755. $$ = true
  9756. }
  9757. | "SESSION"
  9758. {
  9759. $$ = false
  9760. }
  9761. OptFull:
  9762. {
  9763. $$ = false
  9764. }
  9765. | "FULL"
  9766. {
  9767. $$ = true
  9768. }
  9769. ShowDatabaseNameOpt:
  9770. {
  9771. $$ = ""
  9772. }
  9773. | FromOrIn DBName
  9774. {
  9775. $$ = $2
  9776. }
  9777. ShowTableAliasOpt:
  9778. FromOrIn TableName
  9779. {
  9780. $$ = $2.(*ast.TableName)
  9781. }
  9782. FlushStmt:
  9783. "FLUSH" NoWriteToBinLogAliasOpt FlushOption
  9784. {
  9785. tmp := $3.(*ast.FlushStmt)
  9786. tmp.NoWriteToBinLog = $2.(bool)
  9787. $$ = tmp
  9788. }
  9789. PluginNameList:
  9790. Identifier
  9791. {
  9792. $$ = []string{$1}
  9793. }
  9794. | PluginNameList ',' Identifier
  9795. {
  9796. $$ = append($1.([]string), $3)
  9797. }
  9798. FlushOption:
  9799. "PRIVILEGES"
  9800. {
  9801. $$ = &ast.FlushStmt{
  9802. Tp: ast.FlushPrivileges,
  9803. }
  9804. }
  9805. | "STATUS"
  9806. {
  9807. $$ = &ast.FlushStmt{
  9808. Tp: ast.FlushStatus,
  9809. }
  9810. }
  9811. | "TIDB" "PLUGINS" PluginNameList
  9812. {
  9813. $$ = &ast.FlushStmt{
  9814. Tp: ast.FlushTiDBPlugin,
  9815. Plugins: $3.([]string),
  9816. }
  9817. }
  9818. | "HOSTS"
  9819. {
  9820. $$ = &ast.FlushStmt{
  9821. Tp: ast.FlushHosts,
  9822. }
  9823. }
  9824. | LogTypeOpt "LOGS"
  9825. {
  9826. $$ = &ast.FlushStmt{
  9827. Tp: ast.FlushLogs,
  9828. LogType: $1.(ast.LogType),
  9829. }
  9830. }
  9831. | TableOrTables TableNameListOpt WithReadLockOpt
  9832. {
  9833. $$ = &ast.FlushStmt{
  9834. Tp: ast.FlushTables,
  9835. Tables: $2.([]*ast.TableName),
  9836. ReadLock: $3.(bool),
  9837. }
  9838. }
  9839. | "CLIENT_ERRORS_SUMMARY"
  9840. {
  9841. $$ = &ast.FlushStmt{
  9842. Tp: ast.FlushClientErrorsSummary,
  9843. }
  9844. }
  9845. LogTypeOpt:
  9846. /* empty */
  9847. {
  9848. $$ = ast.LogTypeDefault
  9849. }
  9850. | "BINARY"
  9851. {
  9852. $$ = ast.LogTypeBinary
  9853. }
  9854. | "ENGINE"
  9855. {
  9856. $$ = ast.LogTypeEngine
  9857. }
  9858. | "ERROR"
  9859. {
  9860. $$ = ast.LogTypeError
  9861. }
  9862. | "GENERAL"
  9863. {
  9864. $$ = ast.LogTypeGeneral
  9865. }
  9866. | "SLOW"
  9867. {
  9868. $$ = ast.LogTypeSlow
  9869. }
  9870. NoWriteToBinLogAliasOpt:
  9871. %prec lowerThanLocal
  9872. {
  9873. $$ = false
  9874. }
  9875. | "NO_WRITE_TO_BINLOG"
  9876. {
  9877. $$ = true
  9878. }
  9879. | "LOCAL"
  9880. {
  9881. $$ = true
  9882. }
  9883. TableNameListOpt:
  9884. %prec empty
  9885. {
  9886. $$ = []*ast.TableName{}
  9887. }
  9888. | TableNameList
  9889. TableNameListOpt2:
  9890. %prec empty
  9891. {
  9892. $$ = []*ast.TableName{}
  9893. }
  9894. | "TABLE" TableNameList
  9895. {
  9896. $$ = $2
  9897. }
  9898. WithReadLockOpt:
  9899. {
  9900. $$ = false
  9901. }
  9902. | "WITH" "READ" "LOCK"
  9903. {
  9904. $$ = true
  9905. }
  9906. Statement:
  9907. EmptyStmt
  9908. | AdminStmt
  9909. | AlterDatabaseStmt
  9910. | AlterTableStmt
  9911. | AlterUserStmt
  9912. | AlterImportStmt
  9913. | AlterInstanceStmt
  9914. | AlterSequenceStmt
  9915. | AnalyzeTableStmt
  9916. | BeginTransactionStmt
  9917. | BinlogStmt
  9918. | BRIEStmt
  9919. | CommitStmt
  9920. | DeallocateStmt
  9921. | DeleteFromStmt
  9922. | ExecuteStmt
  9923. | ExplainStmt
  9924. | ChangeStmt
  9925. | CreateDatabaseStmt
  9926. | CreateImportStmt
  9927. | CreateIndexStmt
  9928. | CreateTableStmt
  9929. | CreateViewStmt
  9930. | CreateUserStmt
  9931. | CreateRoleStmt
  9932. | CreateBindingStmt
  9933. | CreateSequenceStmt
  9934. | CreateStatisticsStmt
  9935. | DoStmt
  9936. | DropDatabaseStmt
  9937. | DropImportStmt
  9938. | DropIndexStmt
  9939. | DropTableStmt
  9940. | DropSequenceStmt
  9941. | DropViewStmt
  9942. | DropUserStmt
  9943. | DropRoleStmt
  9944. | DropStatisticsStmt
  9945. | DropStatsStmt
  9946. | DropBindingStmt
  9947. | FlushStmt
  9948. | FlashbackTableStmt
  9949. | GrantStmt
  9950. | GrantProxyStmt
  9951. | GrantRoleStmt
  9952. | CallStmt
  9953. | InsertIntoStmt
  9954. | IndexAdviseStmt
  9955. | KillStmt
  9956. | LoadDataStmt
  9957. | LoadStatsStmt
  9958. | PreparedStmt
  9959. | PurgeImportStmt
  9960. | RollbackStmt
  9961. | RenameTableStmt
  9962. | RenameUserStmt
  9963. | ReplaceIntoStmt
  9964. | RecoverTableStmt
  9965. | ResumeImportStmt
  9966. | RevokeStmt
  9967. | RevokeRoleStmt
  9968. | SetOprStmt1
  9969. | SetStmt
  9970. | SetRoleStmt
  9971. | SetDefaultRoleStmt
  9972. | SplitRegionStmt
  9973. | StopImportStmt
  9974. | ShowImportStmt
  9975. | ShowStmt
  9976. | SubSelect
  9977. {
  9978. // `(select 1)`; is a valid select statement
  9979. // TODO: This is used to fix issue #320. There may be a better solution.
  9980. $$ = $1.(*ast.SubqueryExpr).Query.(ast.StmtNode)
  9981. }
  9982. | TraceStmt
  9983. | TruncateTableStmt
  9984. | UpdateStmt
  9985. | UseStmt
  9986. | UnlockTablesStmt
  9987. | LockTablesStmt
  9988. | ShutdownStmt
  9989. TraceableStmt:
  9990. DeleteFromStmt
  9991. | UpdateStmt
  9992. | InsertIntoStmt
  9993. | ReplaceIntoStmt
  9994. | SetOprStmt1
  9995. | LoadDataStmt
  9996. | BeginTransactionStmt
  9997. | CommitStmt
  9998. | RollbackStmt
  9999. | SetStmt
  10000. ExplainableStmt:
  10001. DeleteFromStmt
  10002. | UpdateStmt
  10003. | InsertIntoStmt
  10004. | ReplaceIntoStmt
  10005. | SetOprStmt1
  10006. | AlterTableStmt
  10007. StatementList:
  10008. Statement
  10009. {
  10010. if $1 != nil {
  10011. s := $1
  10012. if lexer, ok := yylex.(stmtTexter); ok {
  10013. s.SetText(lexer.stmtText())
  10014. }
  10015. parser.result = append(parser.result, s)
  10016. }
  10017. }
  10018. | StatementList ';' Statement
  10019. {
  10020. if $3 != nil {
  10021. s := $3
  10022. if lexer, ok := yylex.(stmtTexter); ok {
  10023. s.SetText(lexer.stmtText())
  10024. }
  10025. parser.result = append(parser.result, s)
  10026. }
  10027. }
  10028. Constraint:
  10029. ConstraintKeywordOpt ConstraintElem
  10030. {
  10031. cst := $2.(*ast.Constraint)
  10032. if $1 != nil {
  10033. cst.Name = $1.(string)
  10034. }
  10035. $$ = cst
  10036. }
  10037. CheckConstraintKeyword:
  10038. "CHECK"
  10039. | "CONSTRAINT"
  10040. TableElement:
  10041. ColumnDef
  10042. | Constraint
  10043. TableElementList:
  10044. TableElement
  10045. {
  10046. if $1 != nil {
  10047. $$ = []interface{}{$1.(interface{})}
  10048. } else {
  10049. $$ = []interface{}{}
  10050. }
  10051. }
  10052. | TableElementList ',' TableElement
  10053. {
  10054. if $3 != nil {
  10055. $$ = append($1.([]interface{}), $3)
  10056. } else {
  10057. $$ = $1
  10058. }
  10059. }
  10060. TableElementListOpt:
  10061. /* empty */ %prec lowerThanCreateTableSelect
  10062. {
  10063. var columnDefs []*ast.ColumnDef
  10064. var constraints []*ast.Constraint
  10065. $$ = &ast.CreateTableStmt{
  10066. Cols: columnDefs,
  10067. Constraints: constraints,
  10068. }
  10069. }
  10070. | '(' TableElementList ')'
  10071. {
  10072. tes := $2.([]interface{})
  10073. var columnDefs []*ast.ColumnDef
  10074. var constraints []*ast.Constraint
  10075. for _, te := range tes {
  10076. switch te := te.(type) {
  10077. case *ast.ColumnDef:
  10078. columnDefs = append(columnDefs, te)
  10079. case *ast.Constraint:
  10080. constraints = append(constraints, te)
  10081. }
  10082. }
  10083. $$ = &ast.CreateTableStmt{
  10084. Cols: columnDefs,
  10085. Constraints: constraints,
  10086. }
  10087. }
  10088. TableOption:
  10089. PartDefOption
  10090. | DefaultKwdOpt CharsetKw EqOpt CharsetName
  10091. {
  10092. $$ = &ast.TableOption{Tp: ast.TableOptionCharset, StrValue: $4,
  10093. UintValue: ast.TableOptionCharsetWithoutConvertTo}
  10094. }
  10095. | DefaultKwdOpt "COLLATE" EqOpt CollationName
  10096. {
  10097. $$ = &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $4,
  10098. UintValue: ast.TableOptionCharsetWithoutConvertTo}
  10099. }
  10100. | "AUTO_INCREMENT" EqOpt LengthNum
  10101. {
  10102. $$ = &ast.TableOption{Tp: ast.TableOptionAutoIncrement, UintValue: $3.(uint64)}
  10103. }
  10104. | "AUTO_ID_CACHE" EqOpt LengthNum
  10105. {
  10106. $$ = &ast.TableOption{Tp: ast.TableOptionAutoIdCache, UintValue: $3.(uint64)}
  10107. }
  10108. | "AUTO_RANDOM_BASE" EqOpt LengthNum
  10109. {
  10110. $$ = &ast.TableOption{Tp: ast.TableOptionAutoRandomBase, UintValue: $3.(uint64)}
  10111. }
  10112. | "AVG_ROW_LENGTH" EqOpt LengthNum
  10113. {
  10114. $$ = &ast.TableOption{Tp: ast.TableOptionAvgRowLength, UintValue: $3.(uint64)}
  10115. }
  10116. | "CONNECTION" EqOpt stringLit
  10117. {
  10118. $$ = &ast.TableOption{Tp: ast.TableOptionConnection, StrValue: $3}
  10119. }
  10120. | "CHECKSUM" EqOpt LengthNum
  10121. {
  10122. $$ = &ast.TableOption{Tp: ast.TableOptionCheckSum, UintValue: $3.(uint64)}
  10123. }
  10124. | "TABLE_CHECKSUM" EqOpt LengthNum
  10125. {
  10126. $$ = &ast.TableOption{Tp: ast.TableOptionTableCheckSum, UintValue: $3.(uint64)}
  10127. }
  10128. | "PASSWORD" EqOpt stringLit
  10129. {
  10130. $$ = &ast.TableOption{Tp: ast.TableOptionPassword, StrValue: $3}
  10131. }
  10132. | "COMPRESSION" EqOpt stringLit
  10133. {
  10134. $$ = &ast.TableOption{Tp: ast.TableOptionCompression, StrValue: $3}
  10135. }
  10136. | "KEY_BLOCK_SIZE" EqOpt LengthNum
  10137. {
  10138. $$ = &ast.TableOption{Tp: ast.TableOptionKeyBlockSize, UintValue: $3.(uint64)}
  10139. }
  10140. | "DELAY_KEY_WRITE" EqOpt LengthNum
  10141. {
  10142. $$ = &ast.TableOption{Tp: ast.TableOptionDelayKeyWrite, UintValue: $3.(uint64)}
  10143. }
  10144. | RowFormat
  10145. {
  10146. $$ = &ast.TableOption{Tp: ast.TableOptionRowFormat, UintValue: $1.(uint64)}
  10147. }
  10148. | "STATS_PERSISTENT" EqOpt StatsPersistentVal
  10149. {
  10150. $$ = &ast.TableOption{Tp: ast.TableOptionStatsPersistent}
  10151. }
  10152. | "STATS_AUTO_RECALC" EqOpt LengthNum
  10153. {
  10154. n := $3.(uint64)
  10155. if n != 0 && n != 1 {
  10156. yylex.AppendError(yylex.Errorf("The value of STATS_AUTO_RECALC must be one of [0|1|DEFAULT]."))
  10157. return 1
  10158. }
  10159. $$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, UintValue: n}
  10160. yylex.AppendError(yylex.Errorf("The STATS_AUTO_RECALC is parsed but ignored by all storage engines."))
  10161. parser.lastErrorAsWarn()
  10162. }
  10163. | "STATS_AUTO_RECALC" EqOpt "DEFAULT"
  10164. {
  10165. $$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, Default: true}
  10166. yylex.AppendError(yylex.Errorf("The STATS_AUTO_RECALC is parsed but ignored by all storage engines."))
  10167. parser.lastErrorAsWarn()
  10168. }
  10169. | "STATS_SAMPLE_PAGES" EqOpt LengthNum
  10170. {
  10171. // Parse it but will ignore it.
  10172. // In MySQL, STATS_SAMPLE_PAGES=N(Where 0<N<=65535) or STAS_SAMPLE_PAGES=DEFAULT.
  10173. // Cause we don't support it, so we don't check range of the value.
  10174. $$ = &ast.TableOption{Tp: ast.TableOptionStatsSamplePages, UintValue: $3.(uint64)}
  10175. yylex.AppendError(yylex.Errorf("The STATS_SAMPLE_PAGES is parsed but ignored by all storage engines."))
  10176. parser.lastErrorAsWarn()
  10177. }
  10178. | "STATS_SAMPLE_PAGES" EqOpt "DEFAULT"
  10179. {
  10180. // Parse it but will ignore it.
  10181. // In MySQL, default value of STATS_SAMPLE_PAGES is 0.
  10182. $$ = &ast.TableOption{Tp: ast.TableOptionStatsSamplePages, Default: true}
  10183. yylex.AppendError(yylex.Errorf("The STATS_SAMPLE_PAGES is parsed but ignored by all storage engines."))
  10184. parser.lastErrorAsWarn()
  10185. }
  10186. | "SHARD_ROW_ID_BITS" EqOpt LengthNum
  10187. {
  10188. $$ = &ast.TableOption{Tp: ast.TableOptionShardRowID, UintValue: $3.(uint64)}
  10189. }
  10190. | "PRE_SPLIT_REGIONS" EqOpt LengthNum
  10191. {
  10192. $$ = &ast.TableOption{Tp: ast.TableOptionPreSplitRegion, UintValue: $3.(uint64)}
  10193. }
  10194. | "PACK_KEYS" EqOpt StatsPersistentVal
  10195. {
  10196. // Parse it but will ignore it.
  10197. $$ = &ast.TableOption{Tp: ast.TableOptionPackKeys}
  10198. }
  10199. | "STORAGE" "MEMORY"
  10200. {
  10201. // Parse it but will ignore it.
  10202. $$ = &ast.TableOption{Tp: ast.TableOptionStorageMedia, StrValue: "MEMORY"}
  10203. yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines."))
  10204. parser.lastErrorAsWarn()
  10205. }
  10206. | "STORAGE" "DISK"
  10207. {
  10208. // Parse it but will ignore it.
  10209. $$ = &ast.TableOption{Tp: ast.TableOptionStorageMedia, StrValue: "DISK"}
  10210. yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines."))
  10211. parser.lastErrorAsWarn()
  10212. }
  10213. | "SECONDARY_ENGINE" EqOpt "NULL"
  10214. {
  10215. // Parse it but will ignore it
  10216. // See https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L5977-L5984
  10217. $$ = &ast.TableOption{Tp: ast.TableOptionSecondaryEngineNull}
  10218. yylex.AppendError(yylex.Errorf("The SECONDARY_ENGINE clause is parsed but ignored by all storage engines."))
  10219. parser.lastErrorAsWarn()
  10220. }
  10221. | "SECONDARY_ENGINE" EqOpt StringName
  10222. {
  10223. // Parse it but will ignore it
  10224. // See https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L5977-L5984
  10225. $$ = &ast.TableOption{Tp: ast.TableOptionSecondaryEngine, StrValue: $3}
  10226. yylex.AppendError(yylex.Errorf("The SECONDARY_ENGINE clause is parsed but ignored by all storage engines."))
  10227. parser.lastErrorAsWarn()
  10228. }
  10229. | "UNION" EqOpt '(' TableNameListOpt ')'
  10230. {
  10231. // Parse it but will ignore it
  10232. $$ = &ast.TableOption{
  10233. Tp: ast.TableOptionUnion,
  10234. TableNames: $4.([]*ast.TableName),
  10235. }
  10236. yylex.AppendError(yylex.Errorf("The UNION option is parsed but ignored by all storage engines."))
  10237. parser.lastErrorAsWarn()
  10238. }
  10239. | "ENCRYPTION" EqOpt EncryptionOpt
  10240. {
  10241. // Parse it but will ignore it
  10242. $$ = &ast.TableOption{Tp: ast.TableOptionEncryption, StrValue: $3}
  10243. }
  10244. StatsPersistentVal:
  10245. "DEFAULT"
  10246. {}
  10247. | LengthNum
  10248. {}
  10249. CreateTableOptionListOpt:
  10250. /* empty */ %prec lowerThanCreateTableSelect
  10251. {
  10252. $$ = []*ast.TableOption{}
  10253. }
  10254. | TableOptionList %prec lowerThanComma
  10255. TableOptionList:
  10256. TableOption
  10257. {
  10258. $$ = []*ast.TableOption{$1.(*ast.TableOption)}
  10259. }
  10260. | TableOptionList TableOption
  10261. {
  10262. $$ = append($1.([]*ast.TableOption), $2.(*ast.TableOption))
  10263. }
  10264. | TableOptionList ',' TableOption
  10265. {
  10266. $$ = append($1.([]*ast.TableOption), $3.(*ast.TableOption))
  10267. }
  10268. OptTable:
  10269. {}
  10270. | "TABLE"
  10271. TruncateTableStmt:
  10272. "TRUNCATE" OptTable TableName
  10273. {
  10274. $$ = &ast.TruncateTableStmt{Table: $3.(*ast.TableName)}
  10275. }
  10276. RowFormat:
  10277. "ROW_FORMAT" EqOpt "DEFAULT"
  10278. {
  10279. $$ = ast.RowFormatDefault
  10280. }
  10281. | "ROW_FORMAT" EqOpt "DYNAMIC"
  10282. {
  10283. $$ = ast.RowFormatDynamic
  10284. }
  10285. | "ROW_FORMAT" EqOpt "FIXED"
  10286. {
  10287. $$ = ast.RowFormatFixed
  10288. }
  10289. | "ROW_FORMAT" EqOpt "COMPRESSED"
  10290. {
  10291. $$ = ast.RowFormatCompressed
  10292. }
  10293. | "ROW_FORMAT" EqOpt "REDUNDANT"
  10294. {
  10295. $$ = ast.RowFormatRedundant
  10296. }
  10297. | "ROW_FORMAT" EqOpt "COMPACT"
  10298. {
  10299. $$ = ast.RowFormatCompact
  10300. }
  10301. | "ROW_FORMAT" EqOpt "TOKUDB_DEFAULT"
  10302. {
  10303. $$ = ast.TokuDBRowFormatDefault
  10304. }
  10305. | "ROW_FORMAT" EqOpt "TOKUDB_FAST"
  10306. {
  10307. $$ = ast.TokuDBRowFormatFast
  10308. }
  10309. | "ROW_FORMAT" EqOpt "TOKUDB_SMALL"
  10310. {
  10311. $$ = ast.TokuDBRowFormatSmall
  10312. }
  10313. | "ROW_FORMAT" EqOpt "TOKUDB_ZLIB"
  10314. {
  10315. $$ = ast.TokuDBRowFormatZlib
  10316. }
  10317. | "ROW_FORMAT" EqOpt "TOKUDB_QUICKLZ"
  10318. {
  10319. $$ = ast.TokuDBRowFormatQuickLZ
  10320. }
  10321. | "ROW_FORMAT" EqOpt "TOKUDB_LZMA"
  10322. {
  10323. $$ = ast.TokuDBRowFormatLzma
  10324. }
  10325. | "ROW_FORMAT" EqOpt "TOKUDB_SNAPPY"
  10326. {
  10327. $$ = ast.TokuDBRowFormatSnappy
  10328. }
  10329. | "ROW_FORMAT" EqOpt "TOKUDB_UNCOMPRESSED"
  10330. {
  10331. $$ = ast.TokuDBRowFormatUncompressed
  10332. }
  10333. /*************************************Type Begin***************************************/
  10334. Type:
  10335. NumericType
  10336. | StringType
  10337. | DateAndTimeType
  10338. NumericType:
  10339. IntegerType OptFieldLen FieldOpts
  10340. {
  10341. // TODO: check flen 0
  10342. x := types.NewFieldType($1.(byte))
  10343. x.Flen = $2.(int)
  10344. if $2.(int) != types.UnspecifiedLength && types.TiDBStrictIntegerDisplayWidth {
  10345. yylex.AppendError(ErrWarnDeprecatedIntegerDisplayWidth)
  10346. parser.lastErrorAsWarn()
  10347. }
  10348. for _, o := range $3.([]*ast.TypeOpt) {
  10349. if o.IsUnsigned {
  10350. x.Flag |= mysql.UnsignedFlag
  10351. }
  10352. if o.IsZerofill {
  10353. x.Flag |= mysql.ZerofillFlag
  10354. }
  10355. }
  10356. $$ = x
  10357. }
  10358. | BooleanType FieldOpts
  10359. {
  10360. // TODO: check flen 0
  10361. x := types.NewFieldType($1.(byte))
  10362. x.Flen = 1
  10363. for _, o := range $2.([]*ast.TypeOpt) {
  10364. if o.IsUnsigned {
  10365. x.Flag |= mysql.UnsignedFlag
  10366. }
  10367. if o.IsZerofill {
  10368. x.Flag |= mysql.ZerofillFlag
  10369. }
  10370. }
  10371. $$ = x
  10372. }
  10373. | FixedPointType FloatOpt FieldOpts
  10374. {
  10375. fopt := $2.(*ast.FloatOpt)
  10376. x := types.NewFieldType($1.(byte))
  10377. x.Flen = fopt.Flen
  10378. x.Decimal = fopt.Decimal
  10379. for _, o := range $3.([]*ast.TypeOpt) {
  10380. if o.IsUnsigned {
  10381. x.Flag |= mysql.UnsignedFlag
  10382. }
  10383. if o.IsZerofill {
  10384. x.Flag |= mysql.ZerofillFlag
  10385. }
  10386. }
  10387. $$ = x
  10388. }
  10389. | FloatingPointType FloatOpt FieldOpts
  10390. {
  10391. fopt := $2.(*ast.FloatOpt)
  10392. x := types.NewFieldType($1.(byte))
  10393. // check for a double(10) for syntax error
  10394. if x.Tp == mysql.TypeDouble && parser.strictDoubleFieldType {
  10395. if fopt.Flen != types.UnspecifiedLength && fopt.Decimal == types.UnspecifiedLength {
  10396. yylex.AppendError(ErrSyntax)
  10397. return 1
  10398. }
  10399. }
  10400. x.Flen = fopt.Flen
  10401. if x.Tp == mysql.TypeFloat && fopt.Decimal == types.UnspecifiedLength && x.Flen <= mysql.MaxDoublePrecisionLength {
  10402. if x.Flen > mysql.MaxFloatPrecisionLength {
  10403. x.Tp = mysql.TypeDouble
  10404. }
  10405. x.Flen = types.UnspecifiedLength
  10406. }
  10407. x.Decimal = fopt.Decimal
  10408. for _, o := range $3.([]*ast.TypeOpt) {
  10409. if o.IsUnsigned {
  10410. x.Flag |= mysql.UnsignedFlag
  10411. }
  10412. if o.IsZerofill {
  10413. x.Flag |= mysql.ZerofillFlag
  10414. }
  10415. }
  10416. $$ = x
  10417. }
  10418. | BitValueType OptFieldLen
  10419. {
  10420. x := types.NewFieldType($1.(byte))
  10421. x.Flen = $2.(int)
  10422. if x.Flen == types.UnspecifiedLength {
  10423. x.Flen = 1
  10424. }
  10425. $$ = x
  10426. }
  10427. IntegerType:
  10428. "TINYINT"
  10429. {
  10430. $$ = mysql.TypeTiny
  10431. }
  10432. | "SMALLINT"
  10433. {
  10434. $$ = mysql.TypeShort
  10435. }
  10436. | "MEDIUMINT"
  10437. {
  10438. $$ = mysql.TypeInt24
  10439. }
  10440. | "INT"
  10441. {
  10442. $$ = mysql.TypeLong
  10443. }
  10444. | "INT1"
  10445. {
  10446. $$ = mysql.TypeTiny
  10447. }
  10448. | "INT2"
  10449. {
  10450. $$ = mysql.TypeShort
  10451. }
  10452. | "INT3"
  10453. {
  10454. $$ = mysql.TypeInt24
  10455. }
  10456. | "INT4"
  10457. {
  10458. $$ = mysql.TypeLong
  10459. }
  10460. | "INT8"
  10461. {
  10462. $$ = mysql.TypeLonglong
  10463. }
  10464. | "INTEGER"
  10465. {
  10466. $$ = mysql.TypeLong
  10467. }
  10468. | "BIGINT"
  10469. {
  10470. $$ = mysql.TypeLonglong
  10471. }
  10472. BooleanType:
  10473. "BOOL"
  10474. {
  10475. $$ = mysql.TypeTiny
  10476. }
  10477. | "BOOLEAN"
  10478. {
  10479. $$ = mysql.TypeTiny
  10480. }
  10481. OptInteger:
  10482. {}
  10483. | "INTEGER"
  10484. | "INT"
  10485. FixedPointType:
  10486. "DECIMAL"
  10487. {
  10488. $$ = mysql.TypeNewDecimal
  10489. }
  10490. | "NUMERIC"
  10491. {
  10492. $$ = mysql.TypeNewDecimal
  10493. }
  10494. | "FIXED"
  10495. {
  10496. $$ = mysql.TypeNewDecimal
  10497. }
  10498. FloatingPointType:
  10499. "FLOAT"
  10500. {
  10501. $$ = mysql.TypeFloat
  10502. }
  10503. | "REAL"
  10504. {
  10505. if parser.lexer.GetSQLMode().HasRealAsFloatMode() {
  10506. $$ = mysql.TypeFloat
  10507. } else {
  10508. $$ = mysql.TypeDouble
  10509. }
  10510. }
  10511. | "DOUBLE"
  10512. {
  10513. $$ = mysql.TypeDouble
  10514. }
  10515. | "DOUBLE" "PRECISION"
  10516. {
  10517. $$ = mysql.TypeDouble
  10518. }
  10519. BitValueType:
  10520. "BIT"
  10521. {
  10522. $$ = mysql.TypeBit
  10523. }
  10524. StringType:
  10525. Char FieldLen OptBinary
  10526. {
  10527. x := types.NewFieldType(mysql.TypeString)
  10528. x.Flen = $2.(int)
  10529. x.Charset = $3.(*ast.OptBinary).Charset
  10530. if $3.(*ast.OptBinary).IsBinary {
  10531. x.Flag |= mysql.BinaryFlag
  10532. }
  10533. $$ = x
  10534. }
  10535. | Char OptBinary
  10536. {
  10537. x := types.NewFieldType(mysql.TypeString)
  10538. x.Charset = $2.(*ast.OptBinary).Charset
  10539. if $2.(*ast.OptBinary).IsBinary {
  10540. x.Flag |= mysql.BinaryFlag
  10541. }
  10542. $$ = x
  10543. }
  10544. | NChar FieldLen OptBinary
  10545. {
  10546. x := types.NewFieldType(mysql.TypeString)
  10547. x.Flen = $2.(int)
  10548. x.Charset = $3.(*ast.OptBinary).Charset
  10549. if $3.(*ast.OptBinary).IsBinary {
  10550. x.Flag |= mysql.BinaryFlag
  10551. }
  10552. $$ = x
  10553. }
  10554. | NChar OptBinary
  10555. {
  10556. x := types.NewFieldType(mysql.TypeString)
  10557. x.Charset = $2.(*ast.OptBinary).Charset
  10558. if $2.(*ast.OptBinary).IsBinary {
  10559. x.Flag |= mysql.BinaryFlag
  10560. }
  10561. $$ = x
  10562. }
  10563. | Varchar FieldLen OptBinary
  10564. {
  10565. x := types.NewFieldType(mysql.TypeVarchar)
  10566. x.Flen = $2.(int)
  10567. x.Charset = $3.(*ast.OptBinary).Charset
  10568. if $3.(*ast.OptBinary).IsBinary {
  10569. x.Flag |= mysql.BinaryFlag
  10570. }
  10571. $$ = x
  10572. }
  10573. | NVarchar FieldLen OptBinary
  10574. {
  10575. x := types.NewFieldType(mysql.TypeVarchar)
  10576. x.Flen = $2.(int)
  10577. x.Charset = $3.(*ast.OptBinary).Charset
  10578. if $3.(*ast.OptBinary).IsBinary {
  10579. x.Flag |= mysql.BinaryFlag
  10580. }
  10581. $$ = x
  10582. }
  10583. | "BINARY" OptFieldLen
  10584. {
  10585. x := types.NewFieldType(mysql.TypeString)
  10586. x.Flen = $2.(int)
  10587. x.Charset = charset.CharsetBin
  10588. x.Collate = charset.CharsetBin
  10589. x.Flag |= mysql.BinaryFlag
  10590. $$ = x
  10591. }
  10592. | "VARBINARY" FieldLen
  10593. {
  10594. x := types.NewFieldType(mysql.TypeVarchar)
  10595. x.Flen = $2.(int)
  10596. x.Charset = charset.CharsetBin
  10597. x.Collate = charset.CharsetBin
  10598. x.Flag |= mysql.BinaryFlag
  10599. $$ = x
  10600. }
  10601. | BlobType
  10602. {
  10603. x := $1.(*types.FieldType)
  10604. x.Charset = charset.CharsetBin
  10605. x.Collate = charset.CharsetBin
  10606. x.Flag |= mysql.BinaryFlag
  10607. $$ = x
  10608. }
  10609. | TextType OptCharsetWithOptBinary
  10610. {
  10611. x := $1.(*types.FieldType)
  10612. x.Charset = $2.(*ast.OptBinary).Charset
  10613. if $2.(*ast.OptBinary).IsBinary {
  10614. x.Flag |= mysql.BinaryFlag
  10615. }
  10616. $$ = x
  10617. }
  10618. | "ENUM" '(' TextStringList ')' OptCharsetWithOptBinary
  10619. {
  10620. x := types.NewFieldType(mysql.TypeEnum)
  10621. x.Elems = $3.([]string)
  10622. fieldLen := -1 // enum_flen = max(ele_flen)
  10623. for i := range x.Elems {
  10624. x.Elems[i] = strings.TrimRight(x.Elems[i], " ")
  10625. if len(x.Elems[i]) > fieldLen {
  10626. fieldLen = len(x.Elems[i])
  10627. }
  10628. }
  10629. x.Flen = fieldLen
  10630. opt := $5.(*ast.OptBinary)
  10631. x.Charset = opt.Charset
  10632. if opt.IsBinary {
  10633. x.Flag |= mysql.BinaryFlag
  10634. }
  10635. $$ = x
  10636. }
  10637. | "SET" '(' TextStringList ')' OptCharsetWithOptBinary
  10638. {
  10639. x := types.NewFieldType(mysql.TypeSet)
  10640. x.Elems = $3.([]string)
  10641. fieldLen := len(x.Elems) - 1 // set_flen = sum(ele_flen) + number_of_ele - 1
  10642. for i := range x.Elems {
  10643. x.Elems[i] = strings.TrimRight(x.Elems[i], " ")
  10644. fieldLen += len(x.Elems[i])
  10645. }
  10646. x.Flen = fieldLen
  10647. opt := $5.(*ast.OptBinary)
  10648. x.Charset = opt.Charset
  10649. if opt.IsBinary {
  10650. x.Flag |= mysql.BinaryFlag
  10651. }
  10652. $$ = x
  10653. }
  10654. | "JSON"
  10655. {
  10656. x := types.NewFieldType(mysql.TypeJSON)
  10657. x.Decimal = 0
  10658. x.Charset = charset.CharsetBin
  10659. x.Collate = charset.CollationBin
  10660. $$ = x
  10661. }
  10662. | "LONG" Varchar OptCharsetWithOptBinary
  10663. {
  10664. x := types.NewFieldType(mysql.TypeMediumBlob)
  10665. x.Charset = $3.(*ast.OptBinary).Charset
  10666. if $3.(*ast.OptBinary).IsBinary {
  10667. x.Flag |= mysql.BinaryFlag
  10668. }
  10669. $$ = x
  10670. }
  10671. | "LONG" OptCharsetWithOptBinary
  10672. {
  10673. x := types.NewFieldType(mysql.TypeMediumBlob)
  10674. x.Charset = $2.(*ast.OptBinary).Charset
  10675. if $2.(*ast.OptBinary).IsBinary {
  10676. x.Flag |= mysql.BinaryFlag
  10677. }
  10678. $$ = x
  10679. }
  10680. Char:
  10681. "CHARACTER"
  10682. | "CHAR"
  10683. NChar:
  10684. "NCHAR"
  10685. | "NATIONAL" "CHARACTER"
  10686. | "NATIONAL" "CHAR"
  10687. Varchar:
  10688. "CHARACTER" "VARYING"
  10689. | "CHAR" "VARYING"
  10690. | "VARCHAR"
  10691. | "VARCHARACTER"
  10692. NVarchar:
  10693. "NATIONAL" "VARCHAR"
  10694. | "NATIONAL" "VARCHARACTER"
  10695. | "NVARCHAR"
  10696. | "NCHAR" "VARCHAR"
  10697. | "NCHAR" "VARCHARACTER"
  10698. | "NATIONAL" "CHARACTER" "VARYING"
  10699. | "NATIONAL" "CHAR" "VARYING"
  10700. | "NCHAR" "VARYING"
  10701. Year:
  10702. "YEAR"
  10703. | "SQL_TSI_YEAR"
  10704. BlobType:
  10705. "TINYBLOB"
  10706. {
  10707. x := types.NewFieldType(mysql.TypeTinyBlob)
  10708. $$ = x
  10709. }
  10710. | "BLOB" OptFieldLen
  10711. {
  10712. x := types.NewFieldType(mysql.TypeBlob)
  10713. x.Flen = $2.(int)
  10714. $$ = x
  10715. }
  10716. | "MEDIUMBLOB"
  10717. {
  10718. x := types.NewFieldType(mysql.TypeMediumBlob)
  10719. $$ = x
  10720. }
  10721. | "LONGBLOB"
  10722. {
  10723. x := types.NewFieldType(mysql.TypeLongBlob)
  10724. $$ = x
  10725. }
  10726. | "LONG" "VARBINARY"
  10727. {
  10728. x := types.NewFieldType(mysql.TypeMediumBlob)
  10729. $$ = x
  10730. }
  10731. TextType:
  10732. "TINYTEXT"
  10733. {
  10734. x := types.NewFieldType(mysql.TypeTinyBlob)
  10735. $$ = x
  10736. }
  10737. | "TEXT" OptFieldLen
  10738. {
  10739. x := types.NewFieldType(mysql.TypeBlob)
  10740. x.Flen = $2.(int)
  10741. $$ = x
  10742. }
  10743. | "MEDIUMTEXT"
  10744. {
  10745. x := types.NewFieldType(mysql.TypeMediumBlob)
  10746. $$ = x
  10747. }
  10748. | "LONGTEXT"
  10749. {
  10750. x := types.NewFieldType(mysql.TypeLongBlob)
  10751. $$ = x
  10752. }
  10753. OptCharsetWithOptBinary:
  10754. OptBinary
  10755. | "ASCII"
  10756. {
  10757. $$ = &ast.OptBinary{
  10758. IsBinary: false,
  10759. Charset: charset.CharsetLatin1,
  10760. }
  10761. }
  10762. | "UNICODE"
  10763. {
  10764. name, _, err := charset.GetCharsetInfo("ucs2")
  10765. if err != nil {
  10766. yylex.AppendError(ErrUnknownCharacterSet.GenWithStackByArgs("ucs2"))
  10767. return 1
  10768. }
  10769. $$ = &ast.OptBinary{
  10770. IsBinary: false,
  10771. Charset: name,
  10772. }
  10773. }
  10774. | "BYTE"
  10775. {
  10776. $$ = &ast.OptBinary{
  10777. IsBinary: false,
  10778. Charset: "",
  10779. }
  10780. }
  10781. DateAndTimeType:
  10782. "DATE"
  10783. {
  10784. x := types.NewFieldType(mysql.TypeDate)
  10785. $$ = x
  10786. }
  10787. | "DATETIME" OptFieldLen
  10788. {
  10789. x := types.NewFieldType(mysql.TypeDatetime)
  10790. x.Flen = mysql.MaxDatetimeWidthNoFsp
  10791. x.Decimal = $2.(int)
  10792. if x.Decimal > 0 {
  10793. x.Flen = x.Flen + 1 + x.Decimal
  10794. }
  10795. $$ = x
  10796. }
  10797. | "TIMESTAMP" OptFieldLen
  10798. {
  10799. x := types.NewFieldType(mysql.TypeTimestamp)
  10800. x.Flen = mysql.MaxDatetimeWidthNoFsp
  10801. x.Decimal = $2.(int)
  10802. if x.Decimal > 0 {
  10803. x.Flen = x.Flen + 1 + x.Decimal
  10804. }
  10805. $$ = x
  10806. }
  10807. | "TIME" OptFieldLen
  10808. {
  10809. x := types.NewFieldType(mysql.TypeDuration)
  10810. x.Flen = mysql.MaxDurationWidthNoFsp
  10811. x.Decimal = $2.(int)
  10812. if x.Decimal > 0 {
  10813. x.Flen = x.Flen + 1 + x.Decimal
  10814. }
  10815. $$ = x
  10816. }
  10817. | Year OptFieldLen FieldOpts
  10818. {
  10819. x := types.NewFieldType(mysql.TypeYear)
  10820. x.Flen = $2.(int)
  10821. if x.Flen != types.UnspecifiedLength && x.Flen != 4 {
  10822. yylex.AppendError(ErrInvalidYearColumnLength.GenWithStackByArgs())
  10823. return -1
  10824. }
  10825. $$ = x
  10826. }
  10827. FieldLen:
  10828. '(' LengthNum ')'
  10829. {
  10830. $$ = int($2.(uint64))
  10831. }
  10832. OptFieldLen:
  10833. {
  10834. $$ = types.UnspecifiedLength
  10835. }
  10836. | FieldLen
  10837. FieldOpt:
  10838. "UNSIGNED"
  10839. {
  10840. $$ = &ast.TypeOpt{IsUnsigned: true}
  10841. }
  10842. | "SIGNED"
  10843. {
  10844. $$ = &ast.TypeOpt{IsUnsigned: false}
  10845. }
  10846. | "ZEROFILL"
  10847. {
  10848. $$ = &ast.TypeOpt{IsZerofill: true, IsUnsigned: true}
  10849. }
  10850. FieldOpts:
  10851. {
  10852. $$ = []*ast.TypeOpt{}
  10853. }
  10854. | FieldOpts FieldOpt
  10855. {
  10856. $$ = append($1.([]*ast.TypeOpt), $2.(*ast.TypeOpt))
  10857. }
  10858. FloatOpt:
  10859. {
  10860. $$ = &ast.FloatOpt{Flen: types.UnspecifiedLength, Decimal: types.UnspecifiedLength}
  10861. }
  10862. | FieldLen
  10863. {
  10864. $$ = &ast.FloatOpt{Flen: $1.(int), Decimal: types.UnspecifiedLength}
  10865. }
  10866. | Precision
  10867. Precision:
  10868. '(' LengthNum ',' LengthNum ')'
  10869. {
  10870. $$ = &ast.FloatOpt{Flen: int($2.(uint64)), Decimal: int($4.(uint64))}
  10871. }
  10872. OptBinMod:
  10873. {
  10874. $$ = false
  10875. }
  10876. | "BINARY"
  10877. {
  10878. $$ = true
  10879. }
  10880. OptBinary:
  10881. {
  10882. $$ = &ast.OptBinary{
  10883. IsBinary: false,
  10884. Charset: "",
  10885. }
  10886. }
  10887. | "BINARY" OptCharset
  10888. {
  10889. $$ = &ast.OptBinary{
  10890. IsBinary: true,
  10891. Charset: $2,
  10892. }
  10893. }
  10894. | CharsetKw CharsetName OptBinMod
  10895. {
  10896. $$ = &ast.OptBinary{
  10897. IsBinary: $3.(bool),
  10898. Charset: $2,
  10899. }
  10900. }
  10901. OptCharset:
  10902. {
  10903. $$ = ""
  10904. }
  10905. | CharsetKw CharsetName
  10906. {
  10907. $$ = $2
  10908. }
  10909. CharsetKw:
  10910. "CHARACTER" "SET"
  10911. | "CHARSET"
  10912. | "CHAR" "SET"
  10913. OptCollate:
  10914. {
  10915. $$ = ""
  10916. }
  10917. | "COLLATE" CollationName
  10918. {
  10919. $$ = $2
  10920. }
  10921. StringList:
  10922. stringLit
  10923. {
  10924. $$ = []string{$1}
  10925. }
  10926. | StringList ',' stringLit
  10927. {
  10928. $$ = append($1.([]string), $3)
  10929. }
  10930. TextString:
  10931. stringLit
  10932. | hexLit
  10933. {
  10934. $$ = $1.(ast.BinaryLiteral).ToString()
  10935. }
  10936. | bitLit
  10937. {
  10938. $$ = $1.(ast.BinaryLiteral).ToString()
  10939. }
  10940. TextStringList:
  10941. TextString
  10942. {
  10943. $$ = []string{$1}
  10944. }
  10945. | TextStringList ',' TextString
  10946. {
  10947. $$ = append($1.([]string), $3)
  10948. }
  10949. StringName:
  10950. stringLit
  10951. | Identifier
  10952. StringNameOrBRIEOptionKeyword:
  10953. StringName
  10954. | "IGNORE"
  10955. | "REPLACE"
  10956. /***********************************************************************************
  10957. * Update Statement
  10958. * See https://dev.mysql.com/doc/refman/5.7/en/update.html
  10959. ***********************************************************************************/
  10960. UpdateStmt:
  10961. UpdateStmtNoWith
  10962. | WithClause UpdateStmtNoWith
  10963. {
  10964. u := $2.(*ast.UpdateStmt)
  10965. u.With = $1.(*ast.WithClause)
  10966. $$ = u
  10967. }
  10968. UpdateStmtNoWith:
  10969. "UPDATE" TableOptimizerHintsOpt PriorityOpt IgnoreOptional TableRef "SET" AssignmentList WhereClauseOptional OrderByOptional LimitClause
  10970. {
  10971. var refs *ast.Join
  10972. if x, ok := $5.(*ast.Join); ok {
  10973. refs = x
  10974. } else {
  10975. refs = &ast.Join{Left: $5.(ast.ResultSetNode)}
  10976. }
  10977. st := &ast.UpdateStmt{
  10978. Priority: $3.(mysql.PriorityEnum),
  10979. TableRefs: &ast.TableRefsClause{TableRefs: refs},
  10980. List: $7.([]*ast.Assignment),
  10981. IgnoreErr: $4.(bool),
  10982. }
  10983. if $2 != nil {
  10984. st.TableHints = $2.([]*ast.TableOptimizerHint)
  10985. }
  10986. if $8 != nil {
  10987. st.Where = $8.(ast.ExprNode)
  10988. }
  10989. if $9 != nil {
  10990. st.Order = $9.(*ast.OrderByClause)
  10991. }
  10992. if $10 != nil {
  10993. st.Limit = $10.(*ast.Limit)
  10994. }
  10995. $$ = st
  10996. }
  10997. | "UPDATE" TableOptimizerHintsOpt PriorityOpt IgnoreOptional TableRefs "SET" AssignmentList WhereClauseOptional
  10998. {
  10999. st := &ast.UpdateStmt{
  11000. Priority: $3.(mysql.PriorityEnum),
  11001. TableRefs: &ast.TableRefsClause{TableRefs: $5.(*ast.Join)},
  11002. List: $7.([]*ast.Assignment),
  11003. IgnoreErr: $4.(bool),
  11004. }
  11005. if $2 != nil {
  11006. st.TableHints = $2.([]*ast.TableOptimizerHint)
  11007. }
  11008. if $8 != nil {
  11009. st.Where = $8.(ast.ExprNode)
  11010. }
  11011. $$ = st
  11012. }
  11013. UseStmt:
  11014. "USE" DBName
  11015. {
  11016. $$ = &ast.UseStmt{DBName: $2}
  11017. }
  11018. WhereClause:
  11019. "WHERE" Expression
  11020. {
  11021. $$ = $2
  11022. }
  11023. WhereClauseOptional:
  11024. {
  11025. $$ = nil
  11026. }
  11027. | WhereClause
  11028. CommaOpt:
  11029. {}
  11030. | ','
  11031. {}
  11032. /************************************************************************************
  11033. * Account Management Statements
  11034. * https://dev.mysql.com/doc/refman/5.7/en/account-management-sql.html
  11035. ************************************************************************************/
  11036. CreateUserStmt:
  11037. "CREATE" "USER" IfNotExists UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions
  11038. {
  11039. // See https://dev.mysql.com/doc/refman/5.7/en/create-user.html
  11040. $$ = &ast.CreateUserStmt{
  11041. IsCreateRole: false,
  11042. IfNotExists: $3.(bool),
  11043. Specs: $4.([]*ast.UserSpec),
  11044. TLSOptions: $5.([]*ast.TLSOption),
  11045. ResourceOptions: $6.([]*ast.ResourceOption),
  11046. PasswordOrLockOptions: $7.([]*ast.PasswordOrLockOption),
  11047. }
  11048. }
  11049. CreateRoleStmt:
  11050. "CREATE" "ROLE" IfNotExists RoleSpecList
  11051. {
  11052. // See https://dev.mysql.com/doc/refman/8.0/en/create-role.html
  11053. $$ = &ast.CreateUserStmt{
  11054. IsCreateRole: true,
  11055. IfNotExists: $3.(bool),
  11056. Specs: $4.([]*ast.UserSpec),
  11057. }
  11058. }
  11059. /* See http://dev.mysql.com/doc/refman/5.7/en/alter-user.html */
  11060. AlterUserStmt:
  11061. "ALTER" "USER" IfExists UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions
  11062. {
  11063. $$ = &ast.AlterUserStmt{
  11064. IfExists: $3.(bool),
  11065. Specs: $4.([]*ast.UserSpec),
  11066. TLSOptions: $5.([]*ast.TLSOption),
  11067. ResourceOptions: $6.([]*ast.ResourceOption),
  11068. PasswordOrLockOptions: $7.([]*ast.PasswordOrLockOption),
  11069. }
  11070. }
  11071. | "ALTER" "USER" IfExists "USER" '(' ')' "IDENTIFIED" "BY" AuthString
  11072. {
  11073. auth := &ast.AuthOption{
  11074. AuthString: $9,
  11075. ByAuthString: true,
  11076. }
  11077. $$ = &ast.AlterUserStmt{
  11078. IfExists: $3.(bool),
  11079. CurrentAuth: auth,
  11080. }
  11081. }
  11082. /* See https://dev.mysql.com/doc/refman/8.0/en/alter-instance.html */
  11083. AlterInstanceStmt:
  11084. "ALTER" "INSTANCE" InstanceOption
  11085. {
  11086. $$ = $3.(*ast.AlterInstanceStmt)
  11087. }
  11088. InstanceOption:
  11089. "RELOAD" "TLS"
  11090. {
  11091. $$ = &ast.AlterInstanceStmt{
  11092. ReloadTLS: true,
  11093. }
  11094. }
  11095. | "RELOAD" "TLS" "NO" "ROLLBACK" "ON" "ERROR"
  11096. {
  11097. $$ = &ast.AlterInstanceStmt{
  11098. ReloadTLS: true,
  11099. NoRollbackOnError: true,
  11100. }
  11101. }
  11102. UserSpec:
  11103. Username AuthOption
  11104. {
  11105. userSpec := &ast.UserSpec{
  11106. User: $1.(*auth.UserIdentity),
  11107. }
  11108. if $2 != nil {
  11109. userSpec.AuthOpt = $2.(*ast.AuthOption)
  11110. }
  11111. $$ = userSpec
  11112. }
  11113. UserSpecList:
  11114. UserSpec
  11115. {
  11116. $$ = []*ast.UserSpec{$1.(*ast.UserSpec)}
  11117. }
  11118. | UserSpecList ',' UserSpec
  11119. {
  11120. $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec))
  11121. }
  11122. ConnectionOptions:
  11123. {
  11124. l := []*ast.ResourceOption{}
  11125. $$ = l
  11126. }
  11127. | "WITH" ConnectionOptionList
  11128. {
  11129. $$ = $2
  11130. yylex.AppendError(yylex.Errorf("TiDB does not support WITH ConnectionOptions now, they would be parsed but ignored."))
  11131. parser.lastErrorAsWarn()
  11132. }
  11133. ConnectionOptionList:
  11134. ConnectionOption
  11135. {
  11136. $$ = []*ast.ResourceOption{$1.(*ast.ResourceOption)}
  11137. }
  11138. | ConnectionOptionList ConnectionOption
  11139. {
  11140. l := $1.([]*ast.ResourceOption)
  11141. l = append(l, $2.(*ast.ResourceOption))
  11142. $$ = l
  11143. }
  11144. ConnectionOption:
  11145. "MAX_QUERIES_PER_HOUR" Int64Num
  11146. {
  11147. $$ = &ast.ResourceOption{
  11148. Type: ast.MaxQueriesPerHour,
  11149. Count: $2.(int64),
  11150. }
  11151. }
  11152. | "MAX_UPDATES_PER_HOUR" Int64Num
  11153. {
  11154. $$ = &ast.ResourceOption{
  11155. Type: ast.MaxUpdatesPerHour,
  11156. Count: $2.(int64),
  11157. }
  11158. }
  11159. | "MAX_CONNECTIONS_PER_HOUR" Int64Num
  11160. {
  11161. $$ = &ast.ResourceOption{
  11162. Type: ast.MaxConnectionsPerHour,
  11163. Count: $2.(int64),
  11164. }
  11165. }
  11166. | "MAX_USER_CONNECTIONS" Int64Num
  11167. {
  11168. $$ = &ast.ResourceOption{
  11169. Type: ast.MaxUserConnections,
  11170. Count: $2.(int64),
  11171. }
  11172. }
  11173. RequireClauseOpt:
  11174. {
  11175. $$ = []*ast.TLSOption{}
  11176. }
  11177. | RequireClause
  11178. RequireClause:
  11179. "REQUIRE" "NONE"
  11180. {
  11181. t := &ast.TLSOption{
  11182. Type: ast.TslNone,
  11183. }
  11184. $$ = []*ast.TLSOption{t}
  11185. }
  11186. | "REQUIRE" "SSL"
  11187. {
  11188. t := &ast.TLSOption{
  11189. Type: ast.Ssl,
  11190. }
  11191. $$ = []*ast.TLSOption{t}
  11192. }
  11193. | "REQUIRE" "X509"
  11194. {
  11195. t := &ast.TLSOption{
  11196. Type: ast.X509,
  11197. }
  11198. $$ = []*ast.TLSOption{t}
  11199. }
  11200. | "REQUIRE" RequireList
  11201. {
  11202. $$ = $2
  11203. }
  11204. RequireList:
  11205. RequireListElement
  11206. {
  11207. $$ = []*ast.TLSOption{$1.(*ast.TLSOption)}
  11208. }
  11209. | RequireList "AND" RequireListElement
  11210. {
  11211. l := $1.([]*ast.TLSOption)
  11212. l = append(l, $3.(*ast.TLSOption))
  11213. $$ = l
  11214. }
  11215. | RequireList RequireListElement
  11216. {
  11217. l := $1.([]*ast.TLSOption)
  11218. l = append(l, $2.(*ast.TLSOption))
  11219. $$ = l
  11220. }
  11221. RequireListElement:
  11222. "ISSUER" stringLit
  11223. {
  11224. $$ = &ast.TLSOption{
  11225. Type: ast.Issuer,
  11226. Value: $2,
  11227. }
  11228. }
  11229. | "SUBJECT" stringLit
  11230. {
  11231. $$ = &ast.TLSOption{
  11232. Type: ast.Subject,
  11233. Value: $2,
  11234. }
  11235. }
  11236. | "CIPHER" stringLit
  11237. {
  11238. $$ = &ast.TLSOption{
  11239. Type: ast.Cipher,
  11240. Value: $2,
  11241. }
  11242. }
  11243. | "SAN" stringLit
  11244. {
  11245. $$ = &ast.TLSOption{
  11246. Type: ast.SAN,
  11247. Value: $2,
  11248. }
  11249. }
  11250. PasswordOrLockOptions:
  11251. {
  11252. l := []*ast.PasswordOrLockOption{}
  11253. $$ = l
  11254. }
  11255. | PasswordOrLockOptionList
  11256. {
  11257. $$ = $1
  11258. yylex.AppendError(yylex.Errorf("TiDB does not support PASSWORD EXPIRE and ACCOUNT LOCK now, they would be parsed but ignored."))
  11259. parser.lastErrorAsWarn()
  11260. }
  11261. PasswordOrLockOptionList:
  11262. PasswordOrLockOption
  11263. {
  11264. $$ = []*ast.PasswordOrLockOption{$1.(*ast.PasswordOrLockOption)}
  11265. }
  11266. | PasswordOrLockOptionList PasswordOrLockOption
  11267. {
  11268. l := $1.([]*ast.PasswordOrLockOption)
  11269. l = append(l, $2.(*ast.PasswordOrLockOption))
  11270. $$ = l
  11271. }
  11272. PasswordOrLockOption:
  11273. "ACCOUNT" "UNLOCK"
  11274. {
  11275. $$ = &ast.PasswordOrLockOption{
  11276. Type: ast.Unlock,
  11277. }
  11278. }
  11279. | "ACCOUNT" "LOCK"
  11280. {
  11281. $$ = &ast.PasswordOrLockOption{
  11282. Type: ast.Lock,
  11283. }
  11284. }
  11285. | PasswordExpire
  11286. {
  11287. $$ = &ast.PasswordOrLockOption{
  11288. Type: ast.PasswordExpire,
  11289. }
  11290. }
  11291. | PasswordExpire "INTERVAL" Int64Num "DAY"
  11292. {
  11293. $$ = &ast.PasswordOrLockOption{
  11294. Type: ast.PasswordExpireInterval,
  11295. Count: $3.(int64),
  11296. }
  11297. }
  11298. | PasswordExpire "NEVER"
  11299. {
  11300. $$ = &ast.PasswordOrLockOption{
  11301. Type: ast.PasswordExpireNever,
  11302. }
  11303. }
  11304. | PasswordExpire "DEFAULT"
  11305. {
  11306. $$ = &ast.PasswordOrLockOption{
  11307. Type: ast.PasswordExpireDefault,
  11308. }
  11309. }
  11310. PasswordExpire:
  11311. "PASSWORD" "EXPIRE" ClearPasswordExpireOptions
  11312. {
  11313. $$ = nil
  11314. }
  11315. ClearPasswordExpireOptions:
  11316. {
  11317. $$ = nil
  11318. }
  11319. AuthOption:
  11320. {
  11321. $$ = nil
  11322. }
  11323. | "IDENTIFIED" "BY" AuthString
  11324. {
  11325. $$ = &ast.AuthOption{
  11326. AuthString: $3,
  11327. ByAuthString: true,
  11328. }
  11329. }
  11330. | "IDENTIFIED" "WITH" StringName
  11331. {
  11332. $$ = nil
  11333. }
  11334. | "IDENTIFIED" "WITH" StringName "BY" AuthString
  11335. {
  11336. $$ = &ast.AuthOption{
  11337. AuthString: $5,
  11338. ByAuthString: true,
  11339. }
  11340. }
  11341. | "IDENTIFIED" "WITH" StringName "AS" HashString
  11342. {
  11343. $$ = &ast.AuthOption{
  11344. HashString: $5,
  11345. }
  11346. }
  11347. | "IDENTIFIED" "BY" "PASSWORD" HashString
  11348. {
  11349. $$ = &ast.AuthOption{
  11350. HashString: $4,
  11351. }
  11352. }
  11353. HashString:
  11354. stringLit
  11355. RoleSpec:
  11356. Rolename
  11357. {
  11358. role := $1.(*auth.RoleIdentity)
  11359. roleSpec := &ast.UserSpec{
  11360. User: &auth.UserIdentity{
  11361. Username: role.Username,
  11362. Hostname: role.Hostname,
  11363. },
  11364. IsRole: true,
  11365. }
  11366. $$ = roleSpec
  11367. }
  11368. RoleSpecList:
  11369. RoleSpec
  11370. {
  11371. $$ = []*ast.UserSpec{$1.(*ast.UserSpec)}
  11372. }
  11373. | RoleSpecList ',' RoleSpec
  11374. {
  11375. $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec))
  11376. }
  11377. BindableStmt:
  11378. SetOprStmt1
  11379. | UpdateStmt
  11380. | DeleteWithoutUsingStmt
  11381. | InsertIntoStmt
  11382. | ReplaceIntoStmt
  11383. /*******************************************************************
  11384. *
  11385. * Create Binding Statement
  11386. *
  11387. * Example:
  11388. * CREATE GLOBAL BINDING FOR select Col1,Col2 from table USING select Col1,Col2 from table use index(Col1)
  11389. *******************************************************************/
  11390. CreateBindingStmt:
  11391. "CREATE" GlobalScope "BINDING" "FOR" BindableStmt "USING" BindableStmt
  11392. {
  11393. startOffset := parser.startOffset(&yyS[yypt-2])
  11394. endOffset := parser.startOffset(&yyS[yypt-1])
  11395. originStmt := $5
  11396. originStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset]))
  11397. startOffset = parser.startOffset(&yyS[yypt])
  11398. hintedStmt := $7
  11399. hintedStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
  11400. x := &ast.CreateBindingStmt{
  11401. OriginNode: originStmt,
  11402. HintedNode: hintedStmt,
  11403. GlobalScope: $2.(bool),
  11404. }
  11405. $$ = x
  11406. }
  11407. /*******************************************************************
  11408. *
  11409. * Drop Binding Statement
  11410. *
  11411. * Example:
  11412. * DROP GLOBAL BINDING FOR select Col1,Col2 from table
  11413. *******************************************************************/
  11414. DropBindingStmt:
  11415. "DROP" GlobalScope "BINDING" "FOR" BindableStmt
  11416. {
  11417. startOffset := parser.startOffset(&yyS[yypt])
  11418. originStmt := $5
  11419. originStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
  11420. x := &ast.DropBindingStmt{
  11421. OriginNode: originStmt,
  11422. GlobalScope: $2.(bool),
  11423. }
  11424. $$ = x
  11425. }
  11426. | "DROP" GlobalScope "BINDING" "FOR" BindableStmt "USING" BindableStmt
  11427. {
  11428. startOffset := parser.startOffset(&yyS[yypt-2])
  11429. endOffset := parser.startOffset(&yyS[yypt-1])
  11430. originStmt := $5
  11431. originStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset]))
  11432. startOffset = parser.startOffset(&yyS[yypt])
  11433. hintedStmt := $7
  11434. hintedStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
  11435. x := &ast.DropBindingStmt{
  11436. OriginNode: originStmt,
  11437. HintedNode: hintedStmt,
  11438. GlobalScope: $2.(bool),
  11439. }
  11440. $$ = x
  11441. }
  11442. /*************************************************************************************
  11443. * Grant statement
  11444. * See https://dev.mysql.com/doc/refman/5.7/en/grant.html
  11445. *************************************************************************************/
  11446. GrantStmt:
  11447. "GRANT" RoleOrPrivElemList "ON" ObjectType PrivLevel "TO" UserSpecList RequireClauseOpt WithGrantOptionOpt
  11448. {
  11449. p, err := convertToPriv($2.([]*ast.RoleOrPriv))
  11450. if err != nil {
  11451. yylex.AppendError(err)
  11452. return 1
  11453. }
  11454. $$ = &ast.GrantStmt{
  11455. Privs: p,
  11456. ObjectType: $4.(ast.ObjectTypeType),
  11457. Level: $5.(*ast.GrantLevel),
  11458. Users: $7.([]*ast.UserSpec),
  11459. TLSOptions: $8.([]*ast.TLSOption),
  11460. WithGrant: $9.(bool),
  11461. }
  11462. }
  11463. GrantProxyStmt:
  11464. "GRANT" "PROXY" "ON" Username "TO" UsernameList WithGrantOptionOpt
  11465. {
  11466. $$ = &ast.GrantProxyStmt{
  11467. LocalUser: $4.(*auth.UserIdentity),
  11468. ExternalUsers: $6.([]*auth.UserIdentity),
  11469. WithGrant: $7.(bool),
  11470. }
  11471. }
  11472. GrantRoleStmt:
  11473. "GRANT" RoleOrPrivElemList "TO" UsernameList
  11474. {
  11475. r, err := convertToRole($2.([]*ast.RoleOrPriv))
  11476. if err != nil {
  11477. yylex.AppendError(err)
  11478. return 1
  11479. }
  11480. $$ = &ast.GrantRoleStmt{
  11481. Roles: r,
  11482. Users: $4.([]*auth.UserIdentity),
  11483. }
  11484. }
  11485. WithGrantOptionOpt:
  11486. {
  11487. $$ = false
  11488. }
  11489. | "WITH" "GRANT" "OPTION"
  11490. {
  11491. $$ = true
  11492. }
  11493. | "WITH" "MAX_QUERIES_PER_HOUR" NUM
  11494. {
  11495. $$ = false
  11496. }
  11497. | "WITH" "MAX_UPDATES_PER_HOUR" NUM
  11498. {
  11499. $$ = false
  11500. }
  11501. | "WITH" "MAX_CONNECTIONS_PER_HOUR" NUM
  11502. {
  11503. $$ = false
  11504. }
  11505. | "WITH" "MAX_USER_CONNECTIONS" NUM
  11506. {
  11507. $$ = false
  11508. }
  11509. ExtendedPriv:
  11510. identifier
  11511. {
  11512. $$ = []string{$1}
  11513. }
  11514. | ExtendedPriv identifier
  11515. {
  11516. $$ = append($1.([]string), $2)
  11517. }
  11518. RoleOrPrivElem:
  11519. PrivElem
  11520. {
  11521. $$ = &ast.RoleOrPriv{
  11522. Node: $1,
  11523. }
  11524. }
  11525. | RolenameWithoutIdent
  11526. {
  11527. $$ = &ast.RoleOrPriv{
  11528. Node: $1,
  11529. }
  11530. }
  11531. | ExtendedPriv
  11532. {
  11533. $$ = &ast.RoleOrPriv{
  11534. Symbols: strings.Join($1.([]string), " "),
  11535. }
  11536. }
  11537. | "LOAD" "FROM" "S3"
  11538. {
  11539. $$ = &ast.RoleOrPriv{
  11540. Symbols: "LOAD FROM S3",
  11541. }
  11542. }
  11543. | "SELECT" "INTO" "S3"
  11544. {
  11545. $$ = &ast.RoleOrPriv{
  11546. Symbols: "SELECT INTO S3",
  11547. }
  11548. }
  11549. RoleOrPrivElemList:
  11550. RoleOrPrivElem
  11551. {
  11552. $$ = []*ast.RoleOrPriv{$1.(*ast.RoleOrPriv)}
  11553. }
  11554. | RoleOrPrivElemList ',' RoleOrPrivElem
  11555. {
  11556. $$ = append($1.([]*ast.RoleOrPriv), $3.(*ast.RoleOrPriv))
  11557. }
  11558. PrivElem:
  11559. PrivType
  11560. {
  11561. $$ = &ast.PrivElem{
  11562. Priv: $1.(mysql.PrivilegeType),
  11563. }
  11564. }
  11565. | PrivType '(' ColumnNameList ')'
  11566. {
  11567. $$ = &ast.PrivElem{
  11568. Priv: $1.(mysql.PrivilegeType),
  11569. Cols: $3.([]*ast.ColumnName),
  11570. }
  11571. }
  11572. PrivType:
  11573. "ALL"
  11574. {
  11575. $$ = mysql.AllPriv
  11576. }
  11577. | "ALL" "PRIVILEGES"
  11578. {
  11579. $$ = mysql.AllPriv
  11580. }
  11581. | "ALTER"
  11582. {
  11583. $$ = mysql.AlterPriv
  11584. }
  11585. | "CREATE"
  11586. {
  11587. $$ = mysql.CreatePriv
  11588. }
  11589. | "CREATE" "USER"
  11590. {
  11591. $$ = mysql.CreateUserPriv
  11592. }
  11593. | "CREATE" "TABLESPACE"
  11594. {
  11595. $$ = mysql.CreateTablespacePriv
  11596. }
  11597. | "TRIGGER"
  11598. {
  11599. $$ = mysql.TriggerPriv
  11600. }
  11601. | "DELETE"
  11602. {
  11603. $$ = mysql.DeletePriv
  11604. }
  11605. | "DROP"
  11606. {
  11607. $$ = mysql.DropPriv
  11608. }
  11609. | "PROCESS"
  11610. {
  11611. $$ = mysql.ProcessPriv
  11612. }
  11613. | "EXECUTE"
  11614. {
  11615. $$ = mysql.ExecutePriv
  11616. }
  11617. | "INDEX"
  11618. {
  11619. $$ = mysql.IndexPriv
  11620. }
  11621. | "INSERT"
  11622. {
  11623. $$ = mysql.InsertPriv
  11624. }
  11625. | "SELECT"
  11626. {
  11627. $$ = mysql.SelectPriv
  11628. }
  11629. | "SUPER"
  11630. {
  11631. $$ = mysql.SuperPriv
  11632. }
  11633. | "SHOW" "DATABASES"
  11634. {
  11635. $$ = mysql.ShowDBPriv
  11636. }
  11637. | "UPDATE"
  11638. {
  11639. $$ = mysql.UpdatePriv
  11640. }
  11641. | "GRANT" "OPTION"
  11642. {
  11643. $$ = mysql.GrantPriv
  11644. }
  11645. | "REFERENCES"
  11646. {
  11647. $$ = mysql.ReferencesPriv
  11648. }
  11649. | "REPLICATION" "SLAVE"
  11650. {
  11651. $$ = mysql.ReplicationSlavePriv
  11652. }
  11653. | "REPLICATION" "CLIENT"
  11654. {
  11655. $$ = mysql.ReplicationClientPriv
  11656. }
  11657. | "USAGE"
  11658. {
  11659. $$ = mysql.UsagePriv
  11660. }
  11661. | "RELOAD"
  11662. {
  11663. $$ = mysql.ReloadPriv
  11664. }
  11665. | "FILE"
  11666. {
  11667. $$ = mysql.FilePriv
  11668. }
  11669. | "CONFIG"
  11670. {
  11671. $$ = mysql.ConfigPriv
  11672. }
  11673. | "CREATE" "TEMPORARY" "TABLES"
  11674. {
  11675. $$ = mysql.CreateTMPTablePriv
  11676. }
  11677. | "LOCK" "TABLES"
  11678. {
  11679. $$ = mysql.LockTablesPriv
  11680. }
  11681. | "CREATE" "VIEW"
  11682. {
  11683. $$ = mysql.CreateViewPriv
  11684. }
  11685. | "SHOW" "VIEW"
  11686. {
  11687. $$ = mysql.ShowViewPriv
  11688. }
  11689. | "CREATE" "ROLE"
  11690. {
  11691. $$ = mysql.CreateRolePriv
  11692. }
  11693. | "DROP" "ROLE"
  11694. {
  11695. $$ = mysql.DropRolePriv
  11696. }
  11697. | "CREATE" "ROUTINE"
  11698. {
  11699. $$ = mysql.CreateRoutinePriv
  11700. }
  11701. | "ALTER" "ROUTINE"
  11702. {
  11703. $$ = mysql.AlterRoutinePriv
  11704. }
  11705. | "EVENT"
  11706. {
  11707. $$ = mysql.EventPriv
  11708. }
  11709. | "SHUTDOWN"
  11710. {
  11711. $$ = mysql.ShutdownPriv
  11712. }
  11713. ObjectType:
  11714. %prec lowerThanFunction
  11715. {
  11716. $$ = ast.ObjectTypeNone
  11717. }
  11718. | "TABLE"
  11719. {
  11720. $$ = ast.ObjectTypeTable
  11721. }
  11722. | "FUNCTION"
  11723. {
  11724. $$ = ast.ObjectTypeFunction
  11725. }
  11726. | "PROCEDURE"
  11727. {
  11728. $$ = ast.ObjectTypeProcedure
  11729. }
  11730. PrivLevel:
  11731. '*'
  11732. {
  11733. $$ = &ast.GrantLevel{
  11734. Level: ast.GrantLevelDB,
  11735. }
  11736. }
  11737. | '*' '.' '*'
  11738. {
  11739. $$ = &ast.GrantLevel{
  11740. Level: ast.GrantLevelGlobal,
  11741. }
  11742. }
  11743. | Identifier '.' '*'
  11744. {
  11745. $$ = &ast.GrantLevel{
  11746. Level: ast.GrantLevelDB,
  11747. DBName: $1,
  11748. }
  11749. }
  11750. | Identifier '.' Identifier
  11751. {
  11752. $$ = &ast.GrantLevel{
  11753. Level: ast.GrantLevelTable,
  11754. DBName: $1,
  11755. TableName: $3,
  11756. }
  11757. }
  11758. | Identifier
  11759. {
  11760. $$ = &ast.GrantLevel{
  11761. Level: ast.GrantLevelTable,
  11762. TableName: $1,
  11763. }
  11764. }
  11765. /**************************************RevokeStmt*******************************************
  11766. * See https://dev.mysql.com/doc/refman/5.7/en/revoke.html
  11767. *******************************************************************************************/
  11768. RevokeStmt:
  11769. "REVOKE" RoleOrPrivElemList "ON" ObjectType PrivLevel "FROM" UserSpecList
  11770. {
  11771. p, err := convertToPriv($2.([]*ast.RoleOrPriv))
  11772. if err != nil {
  11773. yylex.AppendError(err)
  11774. return 1
  11775. }
  11776. $$ = &ast.RevokeStmt{
  11777. Privs: p,
  11778. ObjectType: $4.(ast.ObjectTypeType),
  11779. Level: $5.(*ast.GrantLevel),
  11780. Users: $7.([]*ast.UserSpec),
  11781. }
  11782. }
  11783. RevokeRoleStmt:
  11784. "REVOKE" RoleOrPrivElemList "FROM" UsernameList
  11785. {
  11786. r, err := convertToRole($2.([]*ast.RoleOrPriv))
  11787. if err != nil {
  11788. yylex.AppendError(err)
  11789. return 1
  11790. }
  11791. $$ = &ast.RevokeRoleStmt{
  11792. Roles: r,
  11793. Users: $4.([]*auth.UserIdentity),
  11794. }
  11795. }
  11796. /**************************************LoadDataStmt*****************************************
  11797. * See https://dev.mysql.com/doc/refman/5.7/en/load-data.html
  11798. *******************************************************************************************/
  11799. LoadDataStmt:
  11800. "LOAD" "DATA" LocalOpt "INFILE" stringLit DuplicateOpt "INTO" "TABLE" TableName CharsetOpt Fields Lines IgnoreLines ColumnNameOrUserVarListOptWithBrackets LoadDataSetSpecOpt
  11801. {
  11802. x := &ast.LoadDataStmt{
  11803. Path: $5,
  11804. OnDuplicate: $6.(ast.OnDuplicateKeyHandlingType),
  11805. Table: $9.(*ast.TableName),
  11806. ColumnsAndUserVars: $14.([]*ast.ColumnNameOrUserVar),
  11807. IgnoreLines: $13.(uint64),
  11808. }
  11809. if $3 != nil {
  11810. x.IsLocal = true
  11811. // See https://dev.mysql.com/doc/refman/5.7/en/load-data.html#load-data-duplicate-key-handling
  11812. // If you do not specify IGNORE or REPLACE modifier , then we set default behavior to IGNORE when LOCAL modifier is specified
  11813. if x.OnDuplicate == ast.OnDuplicateKeyHandlingError {
  11814. x.OnDuplicate = ast.OnDuplicateKeyHandlingIgnore
  11815. }
  11816. }
  11817. if $11 != nil {
  11818. x.FieldsInfo = $11.(*ast.FieldsClause)
  11819. }
  11820. if $12 != nil {
  11821. x.LinesInfo = $12.(*ast.LinesClause)
  11822. }
  11823. if $15 != nil {
  11824. x.ColumnAssignments = $15.([]*ast.Assignment)
  11825. }
  11826. columns := []*ast.ColumnName{}
  11827. for _, v := range x.ColumnsAndUserVars {
  11828. if v.ColumnName != nil {
  11829. columns = append(columns, v.ColumnName)
  11830. }
  11831. }
  11832. x.Columns = columns
  11833. $$ = x
  11834. }
  11835. IgnoreLines:
  11836. {
  11837. $$ = uint64(0)
  11838. }
  11839. | "IGNORE" NUM "LINES"
  11840. {
  11841. $$ = getUint64FromNUM($2)
  11842. }
  11843. CharsetOpt:
  11844. {}
  11845. | "CHARACTER" "SET" CharsetName
  11846. LocalOpt:
  11847. {
  11848. $$ = nil
  11849. }
  11850. | "LOCAL"
  11851. {
  11852. $$ = $1
  11853. }
  11854. Fields:
  11855. {
  11856. escape := "\\"
  11857. $$ = &ast.FieldsClause{
  11858. Terminated: "\t",
  11859. Escaped: escape[0],
  11860. }
  11861. }
  11862. | FieldsOrColumns FieldItemList
  11863. {
  11864. fieldsClause := &ast.FieldsClause{
  11865. Terminated: "\t",
  11866. Escaped: []byte("\\")[0],
  11867. }
  11868. fieldItems := $2.([]*ast.FieldItem)
  11869. for _, item := range fieldItems {
  11870. switch item.Type {
  11871. case ast.Terminated:
  11872. fieldsClause.Terminated = item.Value
  11873. case ast.Enclosed:
  11874. var enclosed byte
  11875. if len(item.Value) > 0 {
  11876. enclosed = item.Value[0]
  11877. }
  11878. fieldsClause.Enclosed = enclosed
  11879. if item.OptEnclosed {
  11880. fieldsClause.OptEnclosed = true
  11881. }
  11882. case ast.Escaped:
  11883. var escaped byte
  11884. if len(item.Value) > 0 {
  11885. escaped = item.Value[0]
  11886. }
  11887. fieldsClause.Escaped = escaped
  11888. }
  11889. }
  11890. $$ = fieldsClause
  11891. }
  11892. FieldsOrColumns:
  11893. "FIELDS"
  11894. | "COLUMNS"
  11895. FieldItemList:
  11896. FieldItemList FieldItem
  11897. {
  11898. fieldItems := $1.([]*ast.FieldItem)
  11899. $$ = append(fieldItems, $2.(*ast.FieldItem))
  11900. }
  11901. | FieldItem
  11902. {
  11903. fieldItems := make([]*ast.FieldItem, 1, 1)
  11904. fieldItems[0] = $1.(*ast.FieldItem)
  11905. $$ = fieldItems
  11906. }
  11907. FieldItem:
  11908. "TERMINATED" "BY" FieldTerminator
  11909. {
  11910. $$ = &ast.FieldItem{
  11911. Type: ast.Terminated,
  11912. Value: $3,
  11913. }
  11914. }
  11915. | "OPTIONALLY" "ENCLOSED" "BY" FieldTerminator
  11916. {
  11917. str := $4
  11918. if str != "\\" && len(str) > 1 {
  11919. yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs())
  11920. return 1
  11921. }
  11922. $$ = &ast.FieldItem{
  11923. Type: ast.Enclosed,
  11924. Value: str,
  11925. OptEnclosed: true,
  11926. }
  11927. }
  11928. | "ENCLOSED" "BY" FieldTerminator
  11929. {
  11930. str := $3
  11931. if str != "\\" && len(str) > 1 {
  11932. yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs())
  11933. return 1
  11934. }
  11935. $$ = &ast.FieldItem{
  11936. Type: ast.Enclosed,
  11937. Value: str,
  11938. }
  11939. }
  11940. | "ESCAPED" "BY" FieldTerminator
  11941. {
  11942. str := $3
  11943. if str != "\\" && len(str) > 1 {
  11944. yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs())
  11945. return 1
  11946. }
  11947. $$ = &ast.FieldItem{
  11948. Type: ast.Escaped,
  11949. Value: str,
  11950. }
  11951. }
  11952. FieldTerminator:
  11953. stringLit
  11954. | hexLit
  11955. {
  11956. $$ = $1.(ast.BinaryLiteral).ToString()
  11957. }
  11958. | bitLit
  11959. {
  11960. $$ = $1.(ast.BinaryLiteral).ToString()
  11961. }
  11962. Lines:
  11963. {
  11964. $$ = &ast.LinesClause{Terminated: "\n"}
  11965. }
  11966. | "LINES" Starting LinesTerminated
  11967. {
  11968. $$ = &ast.LinesClause{Starting: $2, Terminated: $3}
  11969. }
  11970. Starting:
  11971. {
  11972. $$ = ""
  11973. }
  11974. | "STARTING" "BY" stringLit
  11975. {
  11976. $$ = $3
  11977. }
  11978. LinesTerminated:
  11979. {
  11980. $$ = "\n"
  11981. }
  11982. | "TERMINATED" "BY" stringLit
  11983. {
  11984. $$ = $3
  11985. }
  11986. LoadDataSetSpecOpt:
  11987. {
  11988. $$ = nil
  11989. }
  11990. | "SET" LoadDataSetList
  11991. {
  11992. $$ = $2
  11993. }
  11994. LoadDataSetList:
  11995. LoadDataSetList ',' LoadDataSetItem
  11996. {
  11997. l := $1.([]*ast.Assignment)
  11998. $$ = append(l, $3.(*ast.Assignment))
  11999. }
  12000. | LoadDataSetItem
  12001. {
  12002. $$ = []*ast.Assignment{$1.(*ast.Assignment)}
  12003. }
  12004. LoadDataSetItem:
  12005. SimpleIdent "=" ExprOrDefault
  12006. {
  12007. $$ = &ast.Assignment{
  12008. Column: $1.(*ast.ColumnNameExpr).Name,
  12009. Expr: $3,
  12010. }
  12011. }
  12012. /*********************************************************************
  12013. * Lock/Unlock Tables
  12014. * See http://dev.mysql.com/doc/refman/5.7/en/lock-tables.html
  12015. * All the statement leaves empty. This is used to prevent mysqldump error.
  12016. *********************************************************************/
  12017. UnlockTablesStmt:
  12018. "UNLOCK" TablesTerminalSym
  12019. {
  12020. $$ = &ast.UnlockTablesStmt{}
  12021. }
  12022. LockTablesStmt:
  12023. "LOCK" TablesTerminalSym TableLockList
  12024. {
  12025. $$ = &ast.LockTablesStmt{
  12026. TableLocks: $3.([]ast.TableLock),
  12027. }
  12028. }
  12029. TablesTerminalSym:
  12030. "TABLES"
  12031. | "TABLE"
  12032. TableLock:
  12033. TableName LockType
  12034. {
  12035. $$ = ast.TableLock{
  12036. Table: $1.(*ast.TableName),
  12037. Type: $2.(model.TableLockType),
  12038. }
  12039. }
  12040. LockType:
  12041. "READ"
  12042. {
  12043. $$ = model.TableLockRead
  12044. }
  12045. | "READ" "LOCAL"
  12046. {
  12047. $$ = model.TableLockReadLocal
  12048. }
  12049. | "WRITE"
  12050. {
  12051. $$ = model.TableLockWrite
  12052. }
  12053. | "WRITE" "LOCAL"
  12054. {
  12055. $$ = model.TableLockWriteLocal
  12056. }
  12057. TableLockList:
  12058. TableLock
  12059. {
  12060. $$ = []ast.TableLock{$1.(ast.TableLock)}
  12061. }
  12062. | TableLockList ',' TableLock
  12063. {
  12064. $$ = append($1.([]ast.TableLock), $3.(ast.TableLock))
  12065. }
  12066. /********************************************************************
  12067. * Kill Statement
  12068. * See https://dev.mysql.com/doc/refman/5.7/en/kill.html
  12069. *******************************************************************/
  12070. KillStmt:
  12071. KillOrKillTiDB NUM
  12072. {
  12073. $$ = &ast.KillStmt{
  12074. ConnectionID: getUint64FromNUM($2),
  12075. TiDBExtension: $1.(bool),
  12076. }
  12077. }
  12078. | KillOrKillTiDB "CONNECTION" NUM
  12079. {
  12080. $$ = &ast.KillStmt{
  12081. ConnectionID: getUint64FromNUM($3),
  12082. TiDBExtension: $1.(bool),
  12083. }
  12084. }
  12085. | KillOrKillTiDB "QUERY" NUM
  12086. {
  12087. $$ = &ast.KillStmt{
  12088. ConnectionID: getUint64FromNUM($3),
  12089. Query: true,
  12090. TiDBExtension: $1.(bool),
  12091. }
  12092. }
  12093. KillOrKillTiDB:
  12094. "KILL"
  12095. {
  12096. $$ = false
  12097. }
  12098. /* KILL TIDB is a special grammar extension in TiDB, it can be used only when
  12099. the client connect to TiDB directly, not proxied under LVS. */
  12100. | "KILL" "TIDB"
  12101. {
  12102. $$ = true
  12103. }
  12104. LoadStatsStmt:
  12105. "LOAD" "STATS" stringLit
  12106. {
  12107. $$ = &ast.LoadStatsStmt{
  12108. Path: $3,
  12109. }
  12110. }
  12111. /********************************************************************************************
  12112. *
  12113. * Create Sequence Statement
  12114. *
  12115. * Example:
  12116. * CREATE [TEMPORARY] SEQUENCE [IF NOT EXISTS] sequence_name
  12117. * [ INCREMENT [ BY | = ] increment ]
  12118. * [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]
  12119. * [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]
  12120. * [ START [ WITH | = ] start ]
  12121. * [ CACHE [=] cache | NOCACHE | NO CACHE]
  12122. * [ CYCLE | NOCYCLE | NO CYCLE]
  12123. * [table_options]
  12124. ********************************************************************************************/
  12125. CreateSequenceStmt:
  12126. "CREATE" "SEQUENCE" IfNotExists TableName CreateSequenceOptionListOpt CreateTableOptionListOpt
  12127. {
  12128. $$ = &ast.CreateSequenceStmt{
  12129. IfNotExists: $3.(bool),
  12130. Name: $4.(*ast.TableName),
  12131. SeqOptions: $5.([]*ast.SequenceOption),
  12132. TblOptions: $6.([]*ast.TableOption),
  12133. }
  12134. }
  12135. CreateSequenceOptionListOpt:
  12136. {
  12137. $$ = []*ast.SequenceOption{}
  12138. }
  12139. | SequenceOptionList
  12140. SequenceOptionList:
  12141. SequenceOption
  12142. {
  12143. $$ = []*ast.SequenceOption{$1.(*ast.SequenceOption)}
  12144. }
  12145. | SequenceOptionList SequenceOption
  12146. {
  12147. $$ = append($1.([]*ast.SequenceOption), $2.(*ast.SequenceOption))
  12148. }
  12149. SequenceOption:
  12150. "INCREMENT" EqOpt SignedNum
  12151. {
  12152. $$ = &ast.SequenceOption{Tp: ast.SequenceOptionIncrementBy, IntValue: $3.(int64)}
  12153. }
  12154. | "INCREMENT" "BY" SignedNum
  12155. {
  12156. $$ = &ast.SequenceOption{Tp: ast.SequenceOptionIncrementBy, IntValue: $3.(int64)}
  12157. }
  12158. | "START" EqOpt SignedNum
  12159. {
  12160. $$ = &ast.SequenceOption{Tp: ast.SequenceStartWith, IntValue: $3.(int64)}
  12161. }
  12162. | "START" "WITH" SignedNum
  12163. {
  12164. $$ = &ast.SequenceOption{Tp: ast.SequenceStartWith, IntValue: $3.(int64)}
  12165. }
  12166. | "MINVALUE" EqOpt SignedNum
  12167. {
  12168. $$ = &ast.SequenceOption{Tp: ast.SequenceMinValue, IntValue: $3.(int64)}
  12169. }
  12170. | "NOMINVALUE"
  12171. {
  12172. $$ = &ast.SequenceOption{Tp: ast.SequenceNoMinValue}
  12173. }
  12174. | "NO" "MINVALUE"
  12175. {
  12176. $$ = &ast.SequenceOption{Tp: ast.SequenceNoMinValue}
  12177. }
  12178. | "MAXVALUE" EqOpt SignedNum
  12179. {
  12180. $$ = &ast.SequenceOption{Tp: ast.SequenceMaxValue, IntValue: $3.(int64)}
  12181. }
  12182. | "NOMAXVALUE"
  12183. {
  12184. $$ = &ast.SequenceOption{Tp: ast.SequenceNoMaxValue}
  12185. }
  12186. | "NO" "MAXVALUE"
  12187. {
  12188. $$ = &ast.SequenceOption{Tp: ast.SequenceNoMaxValue}
  12189. }
  12190. | "CACHE" EqOpt SignedNum
  12191. {
  12192. $$ = &ast.SequenceOption{Tp: ast.SequenceCache, IntValue: $3.(int64)}
  12193. }
  12194. | "NOCACHE"
  12195. {
  12196. $$ = &ast.SequenceOption{Tp: ast.SequenceNoCache}
  12197. }
  12198. | "NO" "CACHE"
  12199. {
  12200. $$ = &ast.SequenceOption{Tp: ast.SequenceNoCache}
  12201. }
  12202. | "CYCLE"
  12203. {
  12204. $$ = &ast.SequenceOption{Tp: ast.SequenceCycle}
  12205. }
  12206. | "NOCYCLE"
  12207. {
  12208. $$ = &ast.SequenceOption{Tp: ast.SequenceNoCycle}
  12209. }
  12210. | "NO" "CYCLE"
  12211. {
  12212. $$ = &ast.SequenceOption{Tp: ast.SequenceNoCycle}
  12213. }
  12214. SignedNum:
  12215. Int64Num
  12216. | '+' Int64Num
  12217. {
  12218. $$ = $2
  12219. }
  12220. | '-' NUM
  12221. {
  12222. unsigned_num := getUint64FromNUM($2)
  12223. if unsigned_num > 9223372036854775808 {
  12224. yylex.AppendError(yylex.Errorf("the Signed Value should be at the range of [-9223372036854775808, 9223372036854775807]."))
  12225. return 1
  12226. } else if unsigned_num == 9223372036854775808 {
  12227. signed_one := int64(1)
  12228. $$ = signed_one << 63
  12229. } else {
  12230. $$ = -int64(unsigned_num)
  12231. }
  12232. }
  12233. DropSequenceStmt:
  12234. "DROP" "SEQUENCE" IfExists TableNameList
  12235. {
  12236. $$ = &ast.DropSequenceStmt{
  12237. IfExists: $3.(bool),
  12238. Sequences: $4.([]*ast.TableName),
  12239. }
  12240. }
  12241. /********************************************************************************************
  12242. *
  12243. * Alter Sequence Statement
  12244. *
  12245. * Example:
  12246. * ALTER SEQUENCE [IF EXISTS] sequence_name
  12247. * [ INCREMENT [ BY | = ] increment ]
  12248. * [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]
  12249. * [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]
  12250. * [ START [ WITH | = ] start ]
  12251. * [ CACHE [=] cache | NOCACHE | NO CACHE]
  12252. * [ CYCLE | NOCYCLE | NO CYCLE]
  12253. * [ RESTART [WITH | = ] restart ]
  12254. ********************************************************************************************/
  12255. AlterSequenceStmt:
  12256. "ALTER" "SEQUENCE" IfExists TableName AlterSequenceOptionList
  12257. {
  12258. $$ = &ast.AlterSequenceStmt{
  12259. IfExists: $3.(bool),
  12260. Name: $4.(*ast.TableName),
  12261. SeqOptions: $5.([]*ast.SequenceOption),
  12262. }
  12263. }
  12264. AlterSequenceOptionList:
  12265. AlterSequenceOption
  12266. {
  12267. $$ = []*ast.SequenceOption{$1.(*ast.SequenceOption)}
  12268. }
  12269. | AlterSequenceOptionList AlterSequenceOption
  12270. {
  12271. $$ = append($1.([]*ast.SequenceOption), $2.(*ast.SequenceOption))
  12272. }
  12273. AlterSequenceOption:
  12274. SequenceOption
  12275. | "RESTART"
  12276. {
  12277. $$ = &ast.SequenceOption{Tp: ast.SequenceRestart}
  12278. }
  12279. | "RESTART" EqOpt SignedNum
  12280. {
  12281. $$ = &ast.SequenceOption{Tp: ast.SequenceRestartWith, IntValue: $3.(int64)}
  12282. }
  12283. | "RESTART" "WITH" SignedNum
  12284. {
  12285. $$ = &ast.SequenceOption{Tp: ast.SequenceRestartWith, IntValue: $3.(int64)}
  12286. }
  12287. /********************************************************************
  12288. * Index Advisor Statement
  12289. *
  12290. * INDEX ADVISE
  12291. * [LOCAL]
  12292. * INFILE 'file_name'
  12293. * [MAX_MINUTES number]
  12294. * [MAX_IDXNUM
  12295. * [PER_TABLE number]
  12296. * [PER_DB number]
  12297. * ]
  12298. * [LINES
  12299. * [STARTING BY 'string']
  12300. * [TERMINATED BY 'string']
  12301. * ]
  12302. *******************************************************************/
  12303. IndexAdviseStmt:
  12304. "INDEX" "ADVISE" LocalOpt "INFILE" stringLit MaxMinutesOpt MaxIndexNumOpt Lines
  12305. {
  12306. x := &ast.IndexAdviseStmt{
  12307. Path: $5,
  12308. MaxMinutes: $6.(uint64),
  12309. }
  12310. if $3 != nil {
  12311. x.IsLocal = true
  12312. }
  12313. if $7 != nil {
  12314. x.MaxIndexNum = $7.(*ast.MaxIndexNumClause)
  12315. }
  12316. if $8 != nil {
  12317. x.LinesInfo = $8.(*ast.LinesClause)
  12318. }
  12319. $$ = x
  12320. }
  12321. MaxMinutesOpt:
  12322. {
  12323. $$ = uint64(ast.UnspecifiedSize)
  12324. }
  12325. | "MAX_MINUTES" NUM
  12326. {
  12327. $$ = getUint64FromNUM($2)
  12328. }
  12329. MaxIndexNumOpt:
  12330. {
  12331. $$ = nil
  12332. }
  12333. | "MAX_IDXNUM" PerTable PerDB
  12334. {
  12335. $$ = &ast.MaxIndexNumClause{
  12336. PerTable: $2.(uint64),
  12337. PerDB: $3.(uint64),
  12338. }
  12339. }
  12340. PerTable:
  12341. {
  12342. $$ = uint64(ast.UnspecifiedSize)
  12343. }
  12344. | "PER_TABLE" NUM
  12345. {
  12346. $$ = getUint64FromNUM($2)
  12347. }
  12348. PerDB:
  12349. {
  12350. $$ = uint64(ast.UnspecifiedSize)
  12351. }
  12352. | "PER_DB" NUM
  12353. {
  12354. $$ = getUint64FromNUM($2)
  12355. }
  12356. EncryptionOpt:
  12357. stringLit
  12358. {
  12359. // Parse it but will ignore it
  12360. switch $1 {
  12361. case "Y", "y":
  12362. yylex.AppendError(yylex.Errorf("The ENCRYPTION clause is parsed but ignored by all storage engines."))
  12363. parser.lastErrorAsWarn()
  12364. case "N", "n":
  12365. break
  12366. default:
  12367. yylex.AppendError(ErrWrongValue.GenWithStackByArgs("argument (should be Y or N)", $1))
  12368. return 1
  12369. }
  12370. $$ = $1
  12371. }
  12372. ValuesStmtList:
  12373. RowStmt
  12374. {
  12375. $$ = append([]*ast.RowExpr{}, $1.(*ast.RowExpr))
  12376. }
  12377. | ValuesStmtList ',' RowStmt
  12378. {
  12379. $$ = append($1.([]*ast.RowExpr), $3.(*ast.RowExpr))
  12380. }
  12381. RowStmt:
  12382. "ROW" RowValue
  12383. {
  12384. $$ = &ast.RowExpr{Values: $2.([]ast.ExprNode)}
  12385. }
  12386. %%