12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015 |
- %{
- // Copyright 2013 The ql Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSES/QL-LICENSE file.
- // Copyright 2015 PingCAP, Inc.
- //
- // Licensed under the Apache License, Version 2.0 (the "License");
- // you may not use this file except in compliance with the License.
- // You may obtain a copy of the License at
- //
- // http://www.apache.org/licenses/LICENSE-2.0
- //
- // Unless required by applicable law or agreed to in writing, software
- // distributed under the License is distributed on an "AS IS" BASIS,
- // See the License for the specific language governing permissions and
- // limitations under the License.
- // Initial yacc source generated by ebnf2y[1]
- // at 2013-10-04 23:10:47.861401015 +0200 CEST
- //
- // $ ebnf2y -o ql.y -oe ql.ebnf -start StatementList -pkg ql -p _
- //
- // [1]: http://github.com/cznic/ebnf2y
- package parser
- import (
- "strings"
- "github.com/pingcap/parser/mysql"
- "github.com/pingcap/parser/ast"
- "github.com/pingcap/parser/model"
- "github.com/pingcap/parser/opcode"
- "github.com/pingcap/parser/auth"
- "github.com/pingcap/parser/charset"
- "github.com/pingcap/parser/types"
- )
- %}
- %union {
- offset int // offset
- item interface{}
- ident string
- expr ast.ExprNode
- statement ast.StmtNode
- }
- %token <ident>
- /*yy:token "%c" */
- identifier "identifier"
- /*yy:token "_%c" */
- underscoreCS "UNDERSCORE_CHARSET"
- /*yy:token "\"%c\"" */
- stringLit "string literal"
- singleAtIdentifier "identifier with single leading at"
- doubleAtIdentifier "identifier with double leading at"
- invalid "a special token never used by parser, used by lexer to indicate error"
- hintComment "an optimizer hint"
- andand "&&"
- pipes "||"
- /* The following tokens belong to ODBCDateTimeType. */
- odbcDateType "d"
- odbcTimeType "t"
- odbcTimestampType "ts"
- /* The following tokens belong to ReservedKeyword. Notice: make sure these tokens are contained in ReservedKeyword. */
- add "ADD"
- all "ALL"
- alter "ALTER"
- analyze "ANALYZE"
- and "AND"
- as "AS"
- asc "ASC"
- between "BETWEEN"
- bigIntType "BIGINT"
- binaryType "BINARY"
- blobType "BLOB"
- both "BOTH"
- by "BY"
- call "CALL"
- cascade "CASCADE"
- caseKwd "CASE"
- change "CHANGE"
- character "CHARACTER"
- charType "CHAR"
- check "CHECK"
- collate "COLLATE"
- column "COLUMN"
- constraint "CONSTRAINT"
- convert "CONVERT"
- create "CREATE"
- cross "CROSS"
- cumeDist "CUME_DIST"
- currentDate "CURRENT_DATE"
- currentTime "CURRENT_TIME"
- currentTs "CURRENT_TIMESTAMP"
- currentUser "CURRENT_USER"
- currentRole "CURRENT_ROLE"
- database "DATABASE"
- databases "DATABASES"
- dayHour "DAY_HOUR"
- dayMicrosecond "DAY_MICROSECOND"
- dayMinute "DAY_MINUTE"
- daySecond "DAY_SECOND"
- decimalType "DECIMAL"
- defaultKwd "DEFAULT"
- delayed "DELAYED"
- deleteKwd "DELETE"
- denseRank "DENSE_RANK"
- desc "DESC"
- describe "DESCRIBE"
- distinct "DISTINCT"
- distinctRow "DISTINCTROW"
- div "DIV"
- doubleType "DOUBLE"
- drop "DROP"
- dual "DUAL"
- elseKwd "ELSE"
- enclosed "ENCLOSED"
- escaped "ESCAPED"
- exists "EXISTS"
- explain "EXPLAIN"
- except "EXCEPT"
- falseKwd "FALSE"
- fetch "FETCH"
- firstValue "FIRST_VALUE"
- floatType "FLOAT"
- forKwd "FOR"
- force "FORCE"
- foreign "FOREIGN"
- from "FROM"
- fulltext "FULLTEXT"
- generated "GENERATED"
- grant "GRANT"
- group "GROUP"
- groups "GROUPS"
- having "HAVING"
- highPriority "HIGH_PRIORITY"
- hourMicrosecond "HOUR_MICROSECOND"
- hourMinute "HOUR_MINUTE"
- hourSecond "HOUR_SECOND"
- ifKwd "IF"
- ignore "IGNORE"
- in "IN"
- index "INDEX"
- infile "INFILE"
- inner "INNER"
- integerType "INTEGER"
- intersect "INTERSECT"
- interval "INTERVAL"
- into "INTO"
- outfile "OUTFILE"
- is "IS"
- insert "INSERT"
- intType "INT"
- int1Type "INT1"
- int2Type "INT2"
- int3Type "INT3"
- int4Type "INT4"
- int8Type "INT8"
- join "JOIN"
- key "KEY"
- keys "KEYS"
- kill "KILL"
- lag "LAG"
- lastValue "LAST_VALUE"
- lead "LEAD"
- leading "LEADING"
- left "LEFT"
- like "LIKE"
- limit "LIMIT"
- lines "LINES"
- linear "LINEAR"
- load "LOAD"
- localTime "LOCALTIME"
- localTs "LOCALTIMESTAMP"
- lock "LOCK"
- longblobType "LONGBLOB"
- longtextType "LONGTEXT"
- lowPriority "LOW_PRIORITY"
- match "MATCH"
- maxValue "MAXVALUE"
- mediumblobType "MEDIUMBLOB"
- mediumIntType "MEDIUMINT"
- mediumtextType "MEDIUMTEXT"
- minuteMicrosecond "MINUTE_MICROSECOND"
- minuteSecond "MINUTE_SECOND"
- mod "MOD"
- not "NOT"
- noWriteToBinLog "NO_WRITE_TO_BINLOG"
- nthValue "NTH_VALUE"
- ntile "NTILE"
- null "NULL"
- numericType "NUMERIC"
- on "ON"
- optimize "OPTIMIZE"
- option "OPTION"
- optionally "OPTIONALLY"
- or "OR"
- order "ORDER"
- outer "OUTER"
- over "OVER"
- partition "PARTITION"
- percentRank "PERCENT_RANK"
- placement "PLACEMENT"
- precisionType "PRECISION"
- primary "PRIMARY"
- procedure "PROCEDURE"
- rangeKwd "RANGE"
- rank "RANK"
- read "READ"
- realType "REAL"
- recursive "RECURSIVE"
- references "REFERENCES"
- regexpKwd "REGEXP"
- release "RELEASE"
- rename "RENAME"
- repeat "REPEAT"
- replace "REPLACE"
- require "REQUIRE"
- restrict "RESTRICT"
- revoke "REVOKE"
- right "RIGHT"
- rlike "RLIKE"
- row "ROW"
- rows "ROWS"
- rowNumber "ROW_NUMBER"
- secondMicrosecond "SECOND_MICROSECOND"
- selectKwd "SELECT"
- set "SET"
- show "SHOW"
- smallIntType "SMALLINT"
- spatial "SPATIAL"
- sql "SQL"
- sqlBigResult "SQL_BIG_RESULT"
- sqlCalcFoundRows "SQL_CALC_FOUND_ROWS"
- sqlSmallResult "SQL_SMALL_RESULT"
- ssl "SSL"
- starting "STARTING"
- statsExtended "STATS_EXTENDED"
- straightJoin "STRAIGHT_JOIN"
- tableKwd "TABLE"
- tableSample "TABLESAMPLE"
- stored "STORED"
- terminated "TERMINATED"
- then "THEN"
- tinyblobType "TINYBLOB"
- tinyIntType "TINYINT"
- tinytextType "TINYTEXT"
- to "TO"
- trailing "TRAILING"
- trigger "TRIGGER"
- trueKwd "TRUE"
- unique "UNIQUE"
- union "UNION"
- unlock "UNLOCK"
- unsigned "UNSIGNED"
- update "UPDATE"
- usage "USAGE"
- use "USE"
- using "USING"
- utcDate "UTC_DATE"
- utcTimestamp "UTC_TIMESTAMP"
- utcTime "UTC_TIME"
- values "VALUES"
- long "LONG"
- varcharType "VARCHAR"
- varcharacter "VARCHARACTER"
- varbinaryType "VARBINARY"
- varying "VARYING"
- virtual "VIRTUAL"
- when "WHEN"
- where "WHERE"
- write "WRITE"
- window "WINDOW"
- with "WITH"
- xor "XOR"
- yearMonth "YEAR_MONTH"
- zerofill "ZEROFILL"
- natural "NATURAL"
- /* The following tokens belong to UnReservedKeyword. Notice: make sure these tokens are contained in UnReservedKeyword. */
- account "ACCOUNT"
- action "ACTION"
- advise "ADVISE"
- after "AFTER"
- against "AGAINST"
- ago "AGO"
- algorithm "ALGORITHM"
- always "ALWAYS"
- any "ANY"
- ascii "ASCII"
- autoIdCache "AUTO_ID_CACHE"
- autoIncrement "AUTO_INCREMENT"
- autoRandom "AUTO_RANDOM"
- autoRandomBase "AUTO_RANDOM_BASE"
- avg "AVG"
- avgRowLength "AVG_ROW_LENGTH"
- backend "BACKEND"
- backup "BACKUP"
- backups "BACKUPS"
- begin "BEGIN"
- bernoulli "BERNOULLI"
- binding "BINDING"
- bindings "BINDINGS"
- binlog "BINLOG"
- bitType "BIT"
- block "BLOCK"
- booleanType "BOOLEAN"
- boolType "BOOL"
- btree "BTREE"
- byteType "BYTE"
- cache "CACHE"
- capture "CAPTURE"
- cascaded "CASCADED"
- causal "CAUSAL"
- chain "CHAIN"
- charsetKwd "CHARSET"
- checkpoint "CHECKPOINT"
- checksum "CHECKSUM"
- cipher "CIPHER"
- cleanup "CLEANUP"
- client "CLIENT"
- clientErrorsSummary "CLIENT_ERRORS_SUMMARY"
- coalesce "COALESCE"
- collation "COLLATION"
- columnFormat "COLUMN_FORMAT"
- columns "COLUMNS"
- config "CONFIG"
- comment "COMMENT"
- commit "COMMIT"
- committed "COMMITTED"
- compact "COMPACT"
- compressed "COMPRESSED"
- compression "COMPRESSION"
- concurrency "CONCURRENCY"
- connection "CONNECTION"
- consistency "CONSISTENCY"
- consistent "CONSISTENT"
- constraints "CONSTRAINTS"
- context "CONTEXT"
- cpu "CPU"
- csvBackslashEscape "CSV_BACKSLASH_ESCAPE"
- csvDelimiter "CSV_DELIMITER"
- csvHeader "CSV_HEADER"
- csvNotNull "CSV_NOT_NULL"
- csvNull "CSV_NULL"
- csvSeparator "CSV_SEPARATOR"
- csvTrimLastSeparators "CSV_TRIM_LAST_SEPARATORS"
- current "CURRENT"
- clustered "CLUSTERED"
- cycle "CYCLE"
- data "DATA"
- datetimeType "DATETIME"
- dateType "DATE"
- day "DAY"
- deallocate "DEALLOCATE"
- definer "DEFINER"
- delayKeyWrite "DELAY_KEY_WRITE"
- directory "DIRECTORY"
- disable "DISABLE"
- discard "DISCARD"
- disk "DISK"
- do "DO"
- duplicate "DUPLICATE"
- dynamic "DYNAMIC"
- enable "ENABLE"
- encryption "ENCRYPTION"
- end "END"
- enforced "ENFORCED"
- engine "ENGINE"
- engines "ENGINES"
- enum "ENUM"
- errorKwd "ERROR"
- escape "ESCAPE"
- event "EVENT"
- events "EVENTS"
- evolve "EVOLVE"
- exchange "EXCHANGE"
- exclusive "EXCLUSIVE"
- execute "EXECUTE"
- expansion "EXPANSION"
- expire "EXPIRE"
- extended "EXTENDED"
- faultsSym "FAULTS"
- fields "FIELDS"
- file "FILE"
- first "FIRST"
- fixed "FIXED"
- flush "FLUSH"
- following "FOLLOWING"
- format "FORMAT"
- full "FULL"
- function "FUNCTION"
- general "GENERAL"
- global "GLOBAL"
- grants "GRANTS"
- hash "HASH"
- histogram "HISTOGRAM"
- history "HISTORY"
- hosts "HOSTS"
- hour "HOUR"
- identified "IDENTIFIED"
- identSQLErrors "ERRORS"
- importKwd "IMPORT"
- imports "IMPORTS"
- increment "INCREMENT"
- incremental "INCREMENTAL"
- indexes "INDEXES"
- insertMethod "INSERT_METHOD"
- instance "INSTANCE"
- invisible "INVISIBLE"
- invoker "INVOKER"
- io "IO"
- ipc "IPC"
- isolation "ISOLATION"
- issuer "ISSUER"
- jsonType "JSON"
- keyBlockSize "KEY_BLOCK_SIZE"
- labels "LABELS"
- language "LANGUAGE"
- last "LAST"
- lastBackup "LAST_BACKUP"
- lastval "LASTVAL"
- less "LESS"
- level "LEVEL"
- list "LIST"
- local "LOCAL"
- locked "LOCKED"
- location "LOCATION"
- logs "LOGS"
- master "MASTER"
- max_idxnum "MAX_IDXNUM"
- max_minutes "MAX_MINUTES"
- maxConnectionsPerHour "MAX_CONNECTIONS_PER_HOUR"
- maxQueriesPerHour "MAX_QUERIES_PER_HOUR"
- maxRows "MAX_ROWS"
- maxUpdatesPerHour "MAX_UPDATES_PER_HOUR"
- maxUserConnections "MAX_USER_CONNECTIONS"
- mb "MB"
- memory "MEMORY"
- merge "MERGE"
- microsecond "MICROSECOND"
- minRows "MIN_ROWS"
- minute "MINUTE"
- minValue "MINVALUE"
- mode "MODE"
- modify "MODIFY"
- month "MONTH"
- names "NAMES"
- national "NATIONAL"
- ncharType "NCHAR"
- never "NEVER"
- next "NEXT"
- nextval "NEXTVAL"
- no "NO"
- nocache "NOCACHE"
- nocycle "NOCYCLE"
- nodegroup "NODEGROUP"
- nomaxvalue "NOMAXVALUE"
- nominvalue "NOMINVALUE"
- nonclustered "NONCLUSTERED"
- none "NONE"
- nowait "NOWAIT"
- nvarcharType "NVARCHAR"
- nulls "NULLS"
- off "OFF"
- offset "OFFSET"
- onDuplicate "ON_DUPLICATE"
- online "ONLINE"
- only "ONLY"
- open "OPEN"
- optional "OPTIONAL"
- packKeys "PACK_KEYS"
- pageSym "PAGE"
- parser "PARSER"
- partial "PARTIAL"
- partitioning "PARTITIONING"
- partitions "PARTITIONS"
- password "PASSWORD"
- percent "PERCENT"
- per_db "PER_DB"
- per_table "PER_TABLE"
- pipesAsOr
- plugins "PLUGINS"
- policy "POLICY"
- preSplitRegions "PRE_SPLIT_REGIONS"
- preceding "PRECEDING"
- prepare "PREPARE"
- privileges "PRIVILEGES"
- process "PROCESS"
- processlist "PROCESSLIST"
- profile "PROFILE"
- profiles "PROFILES"
- proxy "PROXY"
- purge "PURGE"
- quarter "QUARTER"
- queries "QUERIES"
- query "QUERY"
- quick "QUICK"
- rateLimit "RATE_LIMIT"
- rebuild "REBUILD"
- recover "RECOVER"
- redundant "REDUNDANT"
- reload "RELOAD"
- remove "REMOVE"
- reorganize "REORGANIZE"
- repair "REPAIR"
- repeatable "REPEATABLE"
- replica "REPLICA"
- replicas "REPLICAS"
- replication "REPLICATION"
- required "REQUIRED"
- respect "RESPECT"
- restart "RESTART"
- restore "RESTORE"
- restores "RESTORES"
- resume "RESUME"
- reverse "REVERSE"
- role "ROLE"
- rollback "ROLLBACK"
- routine "ROUTINE"
- rowCount "ROW_COUNT"
- rowFormat "ROW_FORMAT"
- rtree "RTREE"
- san "SAN"
- second "SECOND"
- secondaryEngine "SECONDARY_ENGINE"
- secondaryLoad "SECONDARY_LOAD"
- secondaryUnload "SECONDARY_UNLOAD"
- security "SECURITY"
- sendCredentialsToTiKV "SEND_CREDENTIALS_TO_TIKV"
- separator "SEPARATOR"
- sequence "SEQUENCE"
- serial "SERIAL"
- serializable "SERIALIZABLE"
- session "SESSION"
- setval "SETVAL"
- shardRowIDBits "SHARD_ROW_ID_BITS"
- share "SHARE"
- shared "SHARED"
- shutdown "SHUTDOWN"
- signed "SIGNED"
- simple "SIMPLE"
- skip "SKIP"
- skipSchemaFiles "SKIP_SCHEMA_FILES"
- slave "SLAVE"
- slow "SLOW"
- snapshot "SNAPSHOT"
- some "SOME"
- source "SOURCE"
- sqlBufferResult "SQL_BUFFER_RESULT"
- sqlCache "SQL_CACHE"
- sqlNoCache "SQL_NO_CACHE"
- sqlTsiDay "SQL_TSI_DAY"
- sqlTsiHour "SQL_TSI_HOUR"
- sqlTsiMinute "SQL_TSI_MINUTE"
- sqlTsiMonth "SQL_TSI_MONTH"
- sqlTsiQuarter "SQL_TSI_QUARTER"
- sqlTsiSecond "SQL_TSI_SECOND"
- sqlTsiWeek "SQL_TSI_WEEK"
- sqlTsiYear "SQL_TSI_YEAR"
- start "START"
- statsAutoRecalc "STATS_AUTO_RECALC"
- statsPersistent "STATS_PERSISTENT"
- statsSamplePages "STATS_SAMPLE_PAGES"
- status "STATUS"
- storage "STORAGE"
- strictFormat "STRICT_FORMAT"
- subject "SUBJECT"
- subpartition "SUBPARTITION"
- subpartitions "SUBPARTITIONS"
- super "SUPER"
- swaps "SWAPS"
- switchesSym "SWITCHES"
- system "SYSTEM"
- systemTime "SYSTEM_TIME"
- tableChecksum "TABLE_CHECKSUM"
- tables "TABLES"
- tablespace "TABLESPACE"
- temporary "TEMPORARY"
- temptable "TEMPTABLE"
- textType "TEXT"
- than "THAN"
- tikvImporter "TIKV_IMPORTER"
- timestampType "TIMESTAMP"
- timeType "TIME"
- tp "TYPE"
- trace "TRACE"
- traditional "TRADITIONAL"
- transaction "TRANSACTION"
- triggers "TRIGGERS"
- truncate "TRUNCATE"
- unbounded "UNBOUNDED"
- uncommitted "UNCOMMITTED"
- undefined "UNDEFINED"
- unicodeSym "UNICODE"
- unknown "UNKNOWN"
- user "USER"
- validation "VALIDATION"
- value "VALUE"
- variables "VARIABLES"
- view "VIEW"
- visible "VISIBLE"
- warnings "WARNINGS"
- week "WEEK"
- weightString "WEIGHT_STRING"
- without "WITHOUT"
- x509 "X509"
- yearType "YEAR"
- wait "WAIT"
- /* The following tokens belong to NotKeywordToken. Notice: make sure these tokens are contained in NotKeywordToken. */
- addDate "ADDDATE"
- approxCountDistinct "APPROX_COUNT_DISTINCT"
- approxPercentile "APPROX_PERCENTILE"
- bitAnd "BIT_AND"
- bitOr "BIT_OR"
- bitXor "BIT_XOR"
- bound "BOUND"
- cast "CAST"
- copyKwd "COPY"
- curTime "CURTIME"
- dateAdd "DATE_ADD"
- dateSub "DATE_SUB"
- exact "EXACT"
- extract "EXTRACT"
- flashback "FLASHBACK"
- getFormat "GET_FORMAT"
- groupConcat "GROUP_CONCAT"
- next_row_id "NEXT_ROW_ID"
- inplace "INPLACE"
- instant "INSTANT"
- internal "INTERNAL"
- min "MIN"
- max "MAX"
- now "NOW"
- position "POSITION"
- recent "RECENT"
- running "RUNNING"
- s3 "S3"
- staleness "STALENESS"
- std "STD"
- stddev "STDDEV"
- stddevPop "STDDEV_POP"
- stddevSamp "STDDEV_SAMP"
- stop "STOP"
- strict "STRICT"
- strong "STRONG"
- subDate "SUBDATE"
- sum "SUM"
- substring "SUBSTRING"
- timestampAdd "TIMESTAMPADD"
- timestampDiff "TIMESTAMPDIFF"
- tokudbDefault "TOKUDB_DEFAULT"
- tokudbFast "TOKUDB_FAST"
- tokudbLzma "TOKUDB_LZMA"
- tokudbQuickLZ "TOKUDB_QUICKLZ"
- tokudbSnappy "TOKUDB_SNAPPY"
- tokudbSmall "TOKUDB_SMALL"
- tokudbUncompressed "TOKUDB_UNCOMPRESSED"
- tokudbZlib "TOKUDB_ZLIB"
- top "TOP"
- trim "TRIM"
- variance "VARIANCE"
- varPop "VAR_POP"
- varSamp "VAR_SAMP"
- exprPushdownBlacklist "EXPR_PUSHDOWN_BLACKLIST"
- optRuleBlacklist "OPT_RULE_BLACKLIST"
- jsonArrayagg "JSON_ARRAYAGG"
- jsonObjectAgg "JSON_OBJECTAGG"
- tls "TLS"
- follower "FOLLOWER"
- leader "LEADER"
- learner "LEARNER"
- voter "VOTER"
- /* The following tokens belong to TiDBKeyword. Notice: make sure these tokens are contained in TiDBKeyword. */
- admin "ADMIN"
- buckets "BUCKETS"
- builtins "BUILTINS"
- cancel "CANCEL"
- cardinality "CARDINALITY"
- cmSketch "CMSKETCH"
- correlation "CORRELATION"
- ddl "DDL"
- dependency "DEPENDENCY"
- depth "DEPTH"
- drainer "DRAINER"
- jobs "JOBS"
- job "JOB"
- nodeID "NODE_ID"
- nodeState "NODE_STATE"
- optimistic "OPTIMISTIC"
- pessimistic "PESSIMISTIC"
- pump "PUMP"
- samples "SAMPLES"
- statistics "STATISTICS"
- stats "STATS"
- statsMeta "STATS_META"
- statsHistograms "STATS_HISTOGRAMS"
- statsBuckets "STATS_BUCKETS"
- statsHealthy "STATS_HEALTHY"
- statsTopN "STATS_TOPN"
- telemetry "TELEMETRY"
- telemetryID "TELEMETRY_ID"
- tidb "TIDB"
- tiFlash "TIFLASH"
- topn "TOPN"
- split "SPLIT"
- width "WIDTH"
- reset "RESET"
- regions "REGIONS"
- region "REGION"
- builtinAddDate
- builtinBitAnd
- builtinBitOr
- builtinBitXor
- builtinCast
- builtinCount
- builtinApproxCountDistinct
- builtinApproxPercentile
- builtinCurDate
- builtinCurTime
- builtinDateAdd
- builtinDateSub
- builtinExtract
- builtinGroupConcat
- builtinMax
- builtinMin
- builtinNow
- builtinPosition
- builtinSubDate
- builtinSubstring
- builtinSum
- builtinSysDate
- builtinStddevPop
- builtinStddevSamp
- builtinTrim
- builtinUser
- builtinVarPop
- builtinVarSamp
- %token <item>
- /*yy:token "1.%d" */
- floatLit "floating-point literal"
- /*yy:token "1.%d" */
- decLit "decimal literal"
- /*yy:token "%d" */
- intLit "integer literal"
- /*yy:token "%x" */
- hexLit "hexadecimal literal"
- /*yy:token "%b" */
- bitLit "bit literal"
- andnot "&^"
- assignmentEq ":="
- eq "="
- ge ">="
- le "<="
- jss "->"
- juss "->>"
- lsh "<<"
- neq "!="
- neqSynonym "<>"
- nulleq "<=>"
- paramMarker "?"
- rsh ">>"
- %token not2
- %type <expr>
- Expression "expression"
- MaxValueOrExpression "maxvalue or expression"
- BoolPri "boolean primary expression"
- ExprOrDefault "expression or default"
- PredicateExpr "Predicate expression factor"
- SetExpr "Set variable statement value's expression"
- BitExpr "bit expression"
- SimpleExpr "simple expression"
- SimpleIdent "Simple Identifier expression"
- SumExpr "aggregate functions"
- FunctionCallGeneric "Function call with Identifier"
- FunctionCallKeyword "Function call with keyword as function name"
- FunctionCallNonKeyword "Function call with nonkeyword as function name"
- Literal "literal value"
- Variable "User or system variable"
- SystemVariable "System defined variable name"
- UserVariable "User defined variable name"
- SubSelect "Sub Select"
- SubSelect2 "Sub Select2"
- StringLiteral "text literal"
- ExpressionOpt "Optional expression"
- SignedLiteral "Literal or NumLiteral with sign"
- DefaultValueExpr "DefaultValueExpr(Now or Signed Literal)"
- NowSymOptionFraction "NowSym with optional fraction part"
- CharsetNameOrDefault "Character set name or default"
- NextValueForSequence "Default nextval expression"
- FunctionNameSequence "Function with sequence function call"
- WindowFuncCall "WINDOW function call"
- RepeatableOpt "Repeatable optional in sample clause"
- ProcedureCall "Procedure call with Identifier or identifier"
- %type <statement>
- AdminStmt "Check table statement or show ddl statement"
- AlterDatabaseStmt "Alter database statement"
- AlterTableStmt "Alter table statement"
- AlterUserStmt "Alter user statement"
- AlterImportStmt "ALTER IMPORT statement"
- AlterInstanceStmt "Alter instance statement"
- AlterSequenceStmt "Alter sequence statement"
- AnalyzeTableStmt "Analyze table statement"
- BeginTransactionStmt "BEGIN TRANSACTION statement"
- BinlogStmt "Binlog base64 statement"
- BRIEStmt "BACKUP or RESTORE statement"
- CommitStmt "COMMIT statement"
- CreateTableStmt "CREATE TABLE statement"
- CreateViewStmt "CREATE VIEW statement"
- CreateUserStmt "CREATE User statement"
- CreateRoleStmt "CREATE Role statement"
- CreateDatabaseStmt "Create Database Statement"
- CreateIndexStmt "CREATE INDEX statement"
- CreateImportStmt "CREATE IMPORT statement"
- CreateBindingStmt "CREATE BINDING statement"
- CreateSequenceStmt "CREATE SEQUENCE statement"
- CreateStatisticsStmt "CREATE STATISTICS statement"
- DoStmt "Do statement"
- DropDatabaseStmt "DROP DATABASE statement"
- DropImportStmt "DROP IMPORT statement"
- DropIndexStmt "DROP INDEX statement"
- DropStatisticsStmt "DROP STATISTICS statement"
- DropStatsStmt "DROP STATS statement"
- DropTableStmt "DROP TABLE statement"
- DropSequenceStmt "DROP SEQUENCE statement"
- DropUserStmt "DROP USER"
- DropRoleStmt "DROP ROLE"
- DropViewStmt "DROP VIEW statement"
- DropBindingStmt "DROP BINDING statement"
- DeallocateStmt "Deallocate prepared statement"
- DeleteFromStmt "DELETE FROM statement"
- DeleteWithoutUsingStmt "Normal DELETE statement"
- DeleteWithUsingStmt "DELETE USING statement"
- EmptyStmt "empty statement"
- ExecuteStmt "Execute statement"
- ExplainStmt "EXPLAIN statement"
- ExplainableStmt "explainable statement"
- FlushStmt "Flush statement"
- FlashbackTableStmt "Flashback table statement"
- GrantStmt "Grant statement"
- GrantProxyStmt "Grant proxy statement"
- GrantRoleStmt "Grant role statement"
- InsertIntoStmt "INSERT INTO statement"
- CallStmt "CALL statement"
- IndexAdviseStmt "INDEX ADVISE statement"
- KillStmt "Kill statement"
- LoadDataStmt "Load data statement"
- LoadStatsStmt "Load statistic statement"
- LockTablesStmt "Lock tables statement"
- PreparedStmt "PreparedStmt"
- PurgeImportStmt "PURGE IMPORT statement that removes a IMPORT task record"
- SelectStmt "SELECT statement"
- RenameTableStmt "rename table statement"
- RenameUserStmt "rename user statement"
- ReplaceIntoStmt "REPLACE INTO statement"
- RecoverTableStmt "recover table statement"
- ResumeImportStmt "RESUME IMPORT statement"
- RevokeStmt "Revoke statement"
- RevokeRoleStmt "Revoke role statement"
- RollbackStmt "ROLLBACK statement"
- SplitRegionStmt "Split index region statement"
- SetStmt "Set variable statement"
- ChangeStmt "Change statement"
- SetRoleStmt "Set active role statement"
- SetDefaultRoleStmt "Set default statement for some user"
- ShowImportStmt "SHOW IMPORT statement"
- ShowStmt "Show engines/databases/tables/user/columns/warnings/status statement"
- Statement "statement"
- StopImportStmt "STOP IMPORT statement"
- TraceStmt "TRACE statement"
- TraceableStmt "traceable statement"
- TruncateTableStmt "TRUNCATE TABLE statement"
- UnlockTablesStmt "Unlock tables statement"
- UpdateStmt "UPDATE statement"
- SetOprStmt "Union/Except/Intersect select statement"
- SetOprStmt1 "Union/Except/Intersect select statement1"
- SetOprStmt2 "Union/Except/Intersect select statement2"
- UseStmt "USE statement"
- ShutdownStmt "SHUTDOWN statement"
- CreateViewSelectOpt "Select/Union/Except/Intersect statement in CREATE VIEW ... AS SELECT"
- BindableStmt "Statement that can be created binding on"
- SelectStmtNoWith "Select statement with CTE clause"
- UpdateStmtNoWith "Update statement with CTE clause"
- %type <item>
- AdminShowSlow "Admin Show Slow statement"
- AllOrPartitionNameList "All or partition name list"
- AlgorithmClause "Alter table algorithm"
- AlterTablePartitionOpt "Alter table partition option"
- AlterTableSpec "Alter table specification"
- AlterTableSpecList "Alter table specification list"
- AlterTableSpecListOpt "Alter table specification list optional"
- AlterSequenceOption "Alter sequence option"
- AlterSequenceOptionList "Alter sequence option list"
- AnalyzeOption "Analyze option"
- AnalyzeOptionList "Analyze option list"
- AnalyzeOptionListOpt "Optional analyze option list"
- AnyOrAll "Any or All for subquery"
- Assignment "assignment"
- AssignmentList "assignment list"
- AssignmentListOpt "assignment list opt"
- AuthOption "User auth option"
- Boolean "Boolean (0, 1, false, true)"
- OptionalBraces "optional braces"
- CastType "Cast function target type"
- ClearPasswordExpireOptions "Clear password expire options"
- ColumnDef "table column definition"
- ColumnDefList "table column definition list"
- ColumnName "column name"
- ColumnNameOrUserVariable "column name or user variable"
- ColumnNameList "column name list"
- ColumnNameOrUserVariableList "column name or user variable list"
- ColumnList "column list"
- ColumnNameListOpt "column name list opt"
- IdentList "identifier list"
- IdentListWithParenOpt "column name list opt with parentheses"
- ColumnNameOrUserVarListOpt "column name or user vairiabe list opt"
- ColumnNameOrUserVarListOptWithBrackets "column name or user variable list opt with brackets"
- ColumnSetValue "insert statement set value by column name"
- ColumnSetValueList "insert statement set value by column name list"
- CompareOp "Compare opcode"
- ColumnOption "column definition option"
- ColumnOptionList "column definition option list"
- VirtualOrStored "indicate generated column is stored or not"
- ColumnOptionListOpt "optional column definition option list"
- CommonTableExpr "Common table expression"
- CompletionTypeWithinTransaction "overwrite system variable completion_type within current transaction"
- ConnectionOption "single connection options"
- ConnectionOptionList "connection options for CREATE USER statement"
- ConnectionOptions "optional connection options for CREATE USER statement"
- Constraint "table constraint"
- ConstraintElem "table constraint element"
- ConstraintKeywordOpt "Constraint Keyword or empty"
- CreateSequenceOptionListOpt "create sequence list opt"
- CreateTableOptionListOpt "create table option list opt"
- CreateTableSelectOpt "Select/Union statement in CREATE TABLE ... SELECT"
- DatabaseOption "CREATE Database specification"
- DatabaseOptionList "CREATE Database specification list"
- DatabaseOptionListOpt "CREATE Database specification list opt"
- DistinctOpt "Explicit distinct option"
- DefaultFalseDistinctOpt "Distinct option which defaults to false"
- DefaultTrueDistinctOpt "Distinct option which defaults to true"
- BuggyDefaultFalseDistinctOpt "Distinct option which accepts DISTINCT ALL and defaults to false"
- RequireClause "Encrypted connections options"
- RequireClauseOpt "optional Encrypted connections options"
- EqOpt "= or empty"
- ErrorHandling "specify exit, replace or skip when meet error"
- EscapedTableRef "escaped table reference"
- ExpressionList "expression list"
- ExtendedPriv "Extended privileges like LOAD FROM S3 or dynamic privileges"
- MaxValueOrExpressionList "maxvalue or expression list"
- ExpressionListOpt "expression list opt"
- FetchFirstOpt "Fetch First/Next Option"
- FuncDatetimePrecListOpt "Function datetime precision list opt"
- FuncDatetimePrecList "Function datetime precision list"
- Field "field expression"
- Fields "Fields clause"
- FieldList "field expression list"
- FlushOption "Flush option"
- InstanceOption "Instance option"
- FulltextSearchModifierOpt "Fulltext modifier"
- PluginNameList "Plugin Name List"
- TableRefsClause "Table references clause"
- FieldItem "Field item for load data clause"
- FieldItemList "Field items for load data clause"
- FuncDatetimePrec "Function datetime precision"
- GetFormatSelector "{DATE|DATETIME|TIME|TIMESTAMP}"
- GlobalScope "The scope of variable"
- GroupByClause "GROUP BY clause"
- HavingClause "HAVING clause"
- HandleRange "handle range"
- HandleRangeList "handle range list"
- IfExists "If Exists"
- IfNotExists "If Not Exists"
- IfNotRunning "If Not Running"
- IfRunning "If Running"
- IgnoreOptional "IGNORE or empty"
- ImportTruncate "truncate all data or data related to errors"
- IndexHint "index hint"
- IndexHintList "index hint list"
- IndexHintListOpt "index hint list opt"
- IndexHintScope "index hint scope"
- IndexHintType "index hint type"
- IndexInvisible "index visible/invisible"
- IndexKeyTypeOpt "index key type"
- IndexLockAndAlgorithmOpt "index lock and algorithm"
- IndexNameAndTypeOpt "index name and index type"
- IndexNameList "index name list"
- IndexOption "Index Option"
- IndexOptionList "Index Option List or empty"
- IndexType "index type"
- IndexName "index name"
- IndexTypeName "index type name"
- IndexTypeOpt "optional index type"
- IndexPartSpecification "Index column name or expression"
- IndexPartSpecificationList "List of index column name or expression"
- IndexPartSpecificationListOpt "Optional list of index column name or expression"
- InsertValues "Rest part of INSERT/REPLACE INTO statement"
- JoinTable "join table"
- JoinType "join type"
- KillOrKillTiDB "Kill or Kill TiDB"
- LocationLabelList "location label name list"
- LikeTableWithOrWithoutParen "LIKE table_name or ( LIKE table_name )"
- LimitClause "LIMIT clause"
- LimitOption "Limit option could be integer or parameter marker."
- Lines "Lines clause"
- LoadDataSetSpecOpt "Optional load data specification"
- LoadDataSetList "Load data specifications"
- LoadDataSetItem "Single load data specification"
- LocalOpt "Local opt"
- LockClause "Alter table lock clause"
- LogTypeOpt "Optional log type used in FLUSH statements"
- NumLiteral "Num/Int/Float/Decimal Literal"
- NoWriteToBinLogAliasOpt "NO_WRITE_TO_BINLOG alias LOCAL or empty"
- ObjectType "Grant statement object type"
- OnDuplicateKeyUpdate "ON DUPLICATE KEY UPDATE value list"
- DuplicateOpt "[IGNORE|REPLACE] in CREATE TABLE ... SELECT statement or LOAD DATA statement"
- OptErrors "ERRORS or empty"
- OptFull "Full or empty"
- OptTemporary "TEMPORARY or empty"
- OptOrder "Optional ordering keyword: ASC/DESC. Default to ASC"
- Order "Ordering keyword: ASC or DESC"
- OptionLevel "3 levels used by lightning config"
- OrderBy "ORDER BY clause"
- OrReplace "or replace"
- ByItem "BY item"
- OrderByOptional "Optional ORDER BY clause optional"
- ByList "BY list"
- AlterOrderItem "Alter Order item"
- AlterOrderList "Alter Order list"
- QuickOptional "QUICK or empty"
- PartitionDefinition "Partition definition"
- PartitionDefinitionList "Partition definition list"
- PartitionDefinitionListOpt "Partition definition list option"
- PartitionKeyAlgorithmOpt "ALGORITHM = n option for KEY partition"
- PartitionMethod "Partition method"
- PartitionOpt "Partition option"
- PartitionNameList "Partition name list"
- PartitionNameListOpt "table partition names list optional"
- PartitionNumOpt "PARTITION NUM option"
- PartDefValuesOpt "VALUES {LESS THAN {(expr | value_list) | MAXVALUE} | IN {value_list}"
- PartDefOptionList "PartDefOption list"
- PartDefOption "COMMENT [=] xxx | TABLESPACE [=] tablespace_name | ENGINE [=] xxx"
- PasswordExpire "Single password option for create user statement"
- PasswordOrLockOption "Single password or lock option for create user statement"
- PasswordOrLockOptionList "Password or lock options for create user statement"
- PasswordOrLockOptions "Optional password or lock options for create user statement"
- ColumnPosition "Column position [First|After ColumnName]"
- PrepareSQL "Prepare statement sql string"
- Priority "Statement priority"
- PriorityOpt "Statement priority option"
- PrivElem "Privilege element"
- PrivLevel "Privilege scope"
- PrivType "Privilege type"
- ReferDef "Reference definition"
- OnDelete "ON DELETE clause"
- OnUpdate "ON UPDATE clause"
- OnDeleteUpdateOpt "optional ON DELETE and UPDATE clause"
- OptGConcatSeparator "optional GROUP_CONCAT SEPARATOR"
- ReferOpt "reference option"
- ReorganizePartitionRuleOpt "optional reorganize partition partition list and definitions"
- RequireList "require list"
- RequireListElement "require list element"
- Rolename "Rolename"
- RolenameComposed "Rolename that composed with more than 1 symbol"
- RolenameList "RolenameList"
- RolenameWithoutIdent "Rolename except identifier"
- RoleOrPrivElem "Element that may be a Rolename or PrivElem"
- RoleOrPrivElemList "RoleOrPrivElem list"
- RoleSpec "Rolename and auth option"
- RoleSpecList "Rolename and auth option list"
- RowFormat "Row format option"
- RowValue "Row value"
- RowStmt "Row constructor"
- SelectLockOpt "SELECT lock options"
- SelectStmtSQLCache "SELECT statement optional SQL_CAHCE/SQL_NO_CACHE"
- SelectStmtFieldList "SELECT statement field list"
- SelectStmtLimit "SELECT statement LIMIT clause"
- SelectStmtLimitOpt "SELECT statement optional LIMIT clause"
- SelectStmtOpt "Select statement option"
- SelectStmtOpts "Select statement options"
- SelectStmtOptsList "Select statement options list"
- SelectStmtBasic "SELECT statement from constant value"
- SelectStmtFromDualTable "SELECT statement from dual table"
- SelectStmtFromTable "SELECT statement from table"
- SelectStmtGroup "SELECT statement optional GROUP BY clause"
- SelectStmtIntoOption "SELECT statement into clause"
- SequenceOption "Create sequence option"
- SequenceOptionList "Create sequence option list"
- SetRoleOpt "Set role options"
- SetDefaultRoleOpt "Set default role options"
- SetOpr "Set operator contain UNION, EXCEPT and INTERSECT"
- SetOprClause "Union/Except/Intersect select clause"
- SetOprClauseList "Union/Except/Intersect select clause list"
- ShowTargetFilterable "Show target that can be filtered by WHERE or LIKE"
- ShowTableAliasOpt "Show table alias option"
- ShowLikeOrWhereOpt "Show like or where clause option"
- ShowProfileArgsOpt "Show profile args option"
- ShowProfileTypesOpt "Show profile types option"
- ShowProfileType "Show profile type"
- ShowProfileTypes "Show profile types"
- SplitOption "Split Option"
- SplitSyntaxOption "Split syntax Option"
- StatementList "statement list"
- StatsPersistentVal "stats_persistent value"
- StatsType "stats type value"
- StringList "string list"
- SubPartDefinition "SubPartition definition"
- SubPartDefinitionList "SubPartition definition list"
- SubPartDefinitionListOpt "SubPartition definition list optional"
- SubPartitionMethod "SubPartition method"
- SubPartitionOpt "SubPartition option"
- SubPartitionNumOpt "SubPartition NUM option"
- TableAliasRefList "table alias reference list"
- TableAsName "table alias name"
- TableAsNameOpt "table alias name optional"
- TableElement "table definition element"
- TableElementList "table definition element list"
- TableElementListOpt "table definition element list optional"
- TableFactor "table factor"
- TableLock "Table name and lock type"
- TableLockList "Table lock list"
- TableName "Table name"
- TableNameOptWild "Table name with optional wildcard"
- TableNameList "Table name list"
- TableNameListOpt "Table name list opt"
- TableNameListOpt2 "Optional table name list with a preceding TABLE"
- TableOption "create table option"
- TableOptionList "create table option list"
- TableRef "table reference"
- TableRefs "table references"
- TableSampleOpt "table sample clause optional"
- TableSampleMethodOpt "table sample method optional"
- TableSampleUnitOpt "table sample unit optional"
- TableToTable "rename table to table"
- TableToTableList "rename table to table by list"
- TextStringList "text string list"
- TimeUnit "Time unit for 'DATE_ADD', 'DATE_SUB', 'ADDDATE', 'SUBDATE', 'EXTRACT'"
- TimestampUnit "Time unit for 'TIMESTAMPADD' and 'TIMESTAMPDIFF'"
- TimestampBound "Timestamp bound for start transaction with timestamp mode"
- LockType "Table locks type"
- TransactionChar "Transaction characteristic"
- TransactionChars "Transaction characteristic list"
- TrimDirection "Trim string direction"
- SetOprOpt "Union/Except/Intersect Option(empty/ALL/DISTINCT)"
- Username "Username"
- UsernameList "UsernameList"
- UserSpec "Username and auth option"
- UserSpecList "Username and auth option list"
- UserVariableList "User defined variable name list"
- UserToUser "rename user to user"
- UserToUserList "rename user to user by list"
- UsingRoles "UsingRoles is role option for SHOW GRANT"
- Values "values"
- ValuesList "values list"
- ValuesOpt "values optional"
- ValuesStmtList "VALUES statement field list"
- VariableAssignment "set variable value"
- VariableAssignmentList "set variable value list"
- ViewAlgorithm "view algorithm"
- ViewCheckOption "view check option"
- ViewDefiner "view definer"
- ViewName "view name"
- ViewFieldList "create view statement field list"
- ViewSQLSecurity "view sql security"
- WhereClause "WHERE clause"
- WhereClauseOptional "Optional WHERE clause"
- WhenClause "When clause"
- WhenClauseList "When clause list"
- WithClustered "With Clustered Index Enabled"
- WithClause "With Clause"
- WithList "With list"
- WithReadLockOpt "With Read Lock opt"
- WithGrantOptionOpt "With Grant Option opt"
- WithValidation "with validation"
- WithValidationOpt "optional with validation"
- Writeable "Table writeable status"
- ElseOpt "Optional else clause"
- Type "Types"
- OptExistingWindowName "Optional existing WINDOW name"
- OptFromFirstLast "Optional FROM FIRST/LAST"
- OptLLDefault "Optional LEAD/LAG default"
- OptLeadLagInfo "Optional LEAD/LAG info"
- OptNullTreatment "Optional NULL treatment"
- OptPartitionClause "Optional PARTITION clause"
- OptWild "Optional Wildcard"
- OptWindowOrderByClause "Optional ORDER BY clause in WINDOW"
- OptWindowFrameClause "Optional FRAME clause in WINDOW"
- OptWindowingClause "Optional OVER clause"
- WindowingClause "OVER clause"
- WindowClauseOptional "Optional WINDOW clause"
- WindowDefinitionList "WINDOW definition list"
- WindowDefinition "WINDOW definition"
- WindowFrameUnits "WINDOW frame units"
- WindowFrameBetween "WINDOW frame between"
- WindowFrameBound "WINDOW frame bound"
- WindowFrameExtent "WINDOW frame extent"
- WindowFrameStart "WINDOW frame start"
- WindowName "WINDOW name"
- WindowNameOrSpec "WINDOW name or spec"
- WindowSpec "WINDOW spec"
- WindowSpecDetails "WINDOW spec details"
- BetweenOrNotOp "Between predicate"
- IsOrNotOp "Is predicate"
- InOrNotOp "In predicate"
- LikeOrNotOp "Like predicate"
- RegexpOrNotOp "Regexp predicate"
- NumericType "Numeric types"
- IntegerType "Integer Types types"
- BooleanType "Boolean Types types"
- FixedPointType "Exact value types"
- FloatingPointType "Approximate value types"
- BitValueType "bit value types"
- StringType "String types"
- BlobType "Blob types"
- TextType "Text types"
- DateAndTimeType "Date and Time types"
- OptFieldLen "Field length or empty"
- FieldLen "Field length"
- FieldOpts "Field type definition option list"
- FieldOpt "Field type definition option"
- FloatOpt "Floating-point type option"
- Precision "Floating-point precision option"
- OptBinary "Optional BINARY"
- OptBinMod "Optional BINARY mode"
- OptCharsetWithOptBinary "Optional BINARY or ASCII or UNICODE or BYTE"
- IgnoreLines "Ignore num(int) lines"
- Int64Num "a number that can be safely converted to int64"
- NUM "A number"
- NumList "Some numbers"
- LengthNum "Field length num(uint64)"
- SignedNum "Signed num(int64)"
- TableOptimizerHints "Table level optimizer hints"
- TableOptimizerHintsOpt "Table level optimizer hints option"
- EnforcedOrNot "{ENFORCED|NOT ENFORCED}"
- EnforcedOrNotOpt "Optional {ENFORCED|NOT ENFORCED}"
- EnforcedOrNotOrNotNullOpt "{[ENFORCED|NOT ENFORCED|NOT NULL]}"
- Match "[MATCH FULL | MATCH PARTIAL | MATCH SIMPLE]"
- MatchOpt "optional MATCH clause"
- MaxMinutesOpt "MAX_MINUTES num(int)"
- MaxIndexNumOpt "MAX_IDXNUM clause"
- PerTable "Max index number PER_TABLE"
- PerDB "Max index number PER_DB"
- BRIETables "List of tables or databases for BRIE statements"
- DBNameList "List of database names"
- BRIEOption "Single BRIE option"
- BRIEOptions "List of BRIE options"
- BRIEIntegerOptionName "Name of a BRIE option which takes an integer as input"
- BRIEBooleanOptionName "Name of a BRIE option which takes a boolean as input"
- BRIEStringOptionName "Name of a BRIE option which takes a string as input"
- BRIEKeywordOptionName "Name of a BRIE option which takes a case-insensitive string as input"
- PlacementCount "Placement rules count option"
- PlacementLabelConstraints "Placement rules label constraints option"
- PlacementRole "Placement rules role option"
- PlacementOptions "Placement rules options"
- PlacementSpec "Placement rules specification"
- PlacementSpecList "Placement rules specifications"
- %type <ident>
- AsOpt "AS or EmptyString"
- KeyOrIndex "{KEY|INDEX}"
- ColumnKeywordOpt "Column keyword or empty"
- PrimaryOpt "Optional primary keyword"
- NowSym "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP"
- NowSymFunc "CURRENT_TIMESTAMP/LOCALTIME/LOCALTIMESTAMP/NOW"
- DefaultKwdOpt "optional DEFAULT keyword"
- DatabaseSym "DATABASE or SCHEMA"
- ExplainSym "EXPLAIN or DESCRIBE or DESC"
- RegexpSym "REGEXP or RLIKE"
- IntoOpt "INTO or EmptyString"
- ValueSym "Value or Values"
- NotSym "Not token"
- Char "{CHAR|CHARACTER}"
- NChar "{NCHAR|NATIONAL CHARACTER|NATIONAL CHAR}"
- Varchar "{VARCHAR|VARCHARACTER|CHARACTER VARYING|CHAR VARYING}"
- NVarchar "{NATIONAL VARCHAR|NATIONAL VARCHARACTER|NVARCHAR|NCHAR VARCHAR|NATIONAL CHARACTER VARYING|NATIONAL CHAR VARYING|NCHAR VARYING}"
- Year "{YEAR|SQL_TSI_YEAR}"
- DeallocateSym "Deallocate or drop"
- OuterOpt "optional OUTER clause"
- CrossOpt "Cross join option"
- TablesTerminalSym "{TABLE|TABLES}"
- IsolationLevel "Isolation level"
- ShowIndexKwd "Show index/indexs/key keyword"
- DistinctKwd "DISTINCT/DISTINCTROW keyword"
- FromOrIn "From or In"
- OptTable "Optional table keyword"
- OptInteger "Optional Integer keyword"
- CharsetKw "charset or charater set"
- CommaOpt "optional comma"
- logAnd "logical and operator"
- logOr "logical or operator"
- LinearOpt "linear or empty"
- FieldsOrColumns "Fields or columns"
- StorageMedia "{DISK|MEMORY|DEFAULT}"
- EncryptionOpt "Encryption option 'Y' or 'N'"
- FirstOrNext "FIRST or NEXT"
- RowOrRows "ROW or ROWS"
- %type <ident>
- ODBCDateTimeType "ODBC type keywords for date and time literals"
- Identifier "identifier or unreserved keyword"
- NotKeywordToken "Tokens not mysql keyword but treated specially"
- UnReservedKeyword "MySQL unreserved keywords"
- TiDBKeyword "TiDB added keywords"
- FunctionNameConflict "Built-in function call names which are conflict with keywords"
- FunctionNameOptionalBraces "Function with optional braces, all of them are reserved keywords."
- FunctionNameDatetimePrecision "Function with optional datetime precision, all of them are reserved keywords."
- FunctionNameDateArith "Date arith function call names (date_add or date_sub)"
- FunctionNameDateArithMultiForms "Date arith function call names (adddate or subdate)"
- VariableName "A simple Identifier like xx or the xx.xx form"
- ConfigItemName "A config item like aa or aa.bb or aa.bb-cc.dd"
- AuthString "Password string value"
- CharsetName "Character set name"
- CollationName "Collation name"
- ColumnFormat "Column format"
- DBName "Database Name"
- ExplainFormatType "explain format type"
- FieldAsName "Field alias name"
- FieldAsNameOpt "Field alias name opt"
- FieldTerminator "Field terminator"
- FlashbackToNewName "Flashback to new name"
- HashString "Hashed string"
- LikeEscapeOpt "like escape option"
- LinesTerminated "Lines terminated by"
- OptCharset "Optional Character setting"
- OptCollate "Optional Collate setting"
- PasswordOpt "Password option"
- RoleNameString "role name string"
- ShowDatabaseNameOpt "Show tables/columns statement database name option"
- Starting "Starting by"
- StringName "string literal or identifier"
- StringNameOrBRIEOptionKeyword "string literal or identifier or keyword used for BRIE options"
- Symbol "Constraint Symbol"
- TextString "text string item"
- %precedence empty
- %precedence lowerThanSelectOpt
- %precedence sqlBufferResult
- %precedence sqlBigResult
- %precedence sqlSmallResult
- %precedence sqlCache sqlNoCache
- %precedence lowerThanIntervalKeyword
- %precedence interval
- %precedence next
- %precedence lowerThanValueKeyword
- %precedence value
- %precedence lowerThanStringLitToken
- %precedence stringLit
- %precedence lowerThanSetKeyword
- %precedence set
- %precedence selectKwd
- %precedence lowerThanSelectStmt
- %precedence lowerThanInsertValues
- %precedence insertValues
- %precedence lowerThanCreateTableSelect
- %precedence createTableSelect
- %precedence lowerThanCharsetKwd
- %precedence charsetKwd
- %precedence lowerThanKey
- %precedence key
- %precedence lowerThanLocal
- %precedence local
- %precedence lowerThanRemove
- %precedence remove
- %precedence lowerThenOrder
- %precedence order
- %precedence lowerThanFunction
- %precedence function
- /* A dummy token to force the priority of TableRef production in a join. */
- %left tableRefPriority
- %left join straightJoin inner cross left right full natural
- %precedence lowerThanOn
- %precedence on using
- %right assignmentEq
- %left pipes or pipesAsOr
- %left xor
- %left andand and
- %left between
- %precedence lowerThanEq
- %left eq ge le neq neqSynonym '>' '<' is like in
- %left '|'
- %left '&'
- %left rsh lsh
- %left '-' '+'
- %left '*' '/' '%' div mod
- %left '^'
- %left '~' neg
- %precedence lowerThanNot
- %right not not2
- %right collate
- %right encryption
- %left labels
- %precedence lowerThanParenthese
- %precedence '(' ')'
- %precedence higherThanParenthese
- %precedence quick
- %precedence escape
- %precedence lowerThanComma
- %precedence ','
- %precedence higherThanComma
- %start Start
- %%
- Start:
- StatementList
- /**************************************AlterTableStmt***************************************
- * See https://dev.mysql.com/doc/refman/5.7/en/alter-table.html
- *******************************************************************************************/
- AlterTableStmt:
- "ALTER" IgnoreOptional "TABLE" TableName AlterTableSpecListOpt AlterTablePartitionOpt
- {
- specs := $5.([]*ast.AlterTableSpec)
- if $6 != nil {
- specs = append(specs, $6.(*ast.AlterTableSpec))
- }
- $$ = &ast.AlterTableStmt{
- Table: $4.(*ast.TableName),
- Specs: specs,
- }
- }
- | "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, PartitionNames: $7.([]model.CIStr), AnalyzeOpts: $8.([]ast.AnalyzeOpt)}
- }
- | "ALTER" IgnoreOptional "TABLE" TableName "ANALYZE" "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{
- TableNames: []*ast.TableName{$4.(*ast.TableName)},
- PartitionNames: $7.([]model.CIStr),
- IndexNames: $9.([]model.CIStr),
- IndexFlag: true,
- AnalyzeOpts: $10.([]ast.AnalyzeOpt),
- }
- }
- PlacementRole:
- "ROLE" "=" "FOLLOWER"
- {
- $$ = ast.PlacementRoleFollower
- }
- | "ROLE" "=" "LEADER"
- {
- $$ = ast.PlacementRoleLeader
- }
- | "ROLE" "=" "LEARNER"
- {
- $$ = ast.PlacementRoleLearner
- }
- | "ROLE" "=" "VOTER"
- {
- $$ = ast.PlacementRoleVoter
- }
- PlacementCount:
- "REPLICAS" "=" LengthNum
- {
- cnt := $3.(uint64)
- if cnt == 0 {
- yylex.AppendError(yylex.Errorf("Invalid placement option REPLICAS, it is not allowed to be 0"))
- return 1
- }
- $$ = cnt
- }
- PlacementLabelConstraints:
- "CONSTRAINTS" "=" stringLit
- {
- $$ = $3
- }
- PlacementOptions:
- PlacementCount
- {
- $$ = &ast.PlacementSpec{
- Replicas: $1.(uint64),
- }
- }
- | PlacementLabelConstraints
- {
- $$ = &ast.PlacementSpec{
- Constraints: $1.(string),
- }
- }
- | PlacementRole
- {
- $$ = &ast.PlacementSpec{
- Role: $1.(ast.PlacementRole),
- }
- }
- | PlacementOptions PlacementCount
- {
- spec := $1.(*ast.PlacementSpec)
- if spec.Replicas != 0 {
- yylex.AppendError(yylex.Errorf("Duplicate placement option REPLICAS"))
- return 1
- }
- spec.Replicas = $2.(uint64)
- $$ = spec
- }
- | PlacementOptions PlacementLabelConstraints
- {
- spec := $1.(*ast.PlacementSpec)
- if len(spec.Constraints) > 0 {
- yylex.AppendError(yylex.Errorf("Duplicate placement option CONSTRAINTS"))
- return 1
- }
- spec.Constraints = $2.(string)
- $$ = spec
- }
- | PlacementOptions PlacementRole
- {
- spec := $1.(*ast.PlacementSpec)
- if spec.Role != ast.PlacementRoleNone {
- yylex.AppendError(yylex.Errorf("Duplicate placement option ROLE"))
- return 1
- }
- spec.Role = $2.(ast.PlacementRole)
- $$ = spec
- }
- PlacementSpec:
- "ADD" "PLACEMENT" "POLICY" PlacementOptions
- {
- spec := $4.(*ast.PlacementSpec)
- spec.Tp = ast.PlacementAdd
- $$ = spec
- }
- | "ALTER" "PLACEMENT" "POLICY" PlacementOptions
- {
- spec := $4.(*ast.PlacementSpec)
- spec.Tp = ast.PlacementAlter
- $$ = spec
- }
- | "DROP" "PLACEMENT" "POLICY" PlacementRole
- {
- spec := &ast.PlacementSpec{Role: $4.(ast.PlacementRole)}
- spec.Tp = ast.PlacementDrop
- $$ = spec
- }
- PlacementSpecList:
- PlacementSpec
- {
- $$ = []*ast.PlacementSpec{$1.(*ast.PlacementSpec)}
- }
- | PlacementSpecList ',' PlacementSpec
- {
- $$ = append($1.([]*ast.PlacementSpec), $3.(*ast.PlacementSpec))
- }
- AlterTablePartitionOpt:
- PartitionOpt
- {
- if $1 != nil {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTablePartition,
- Partition: $1.(*ast.PartitionOptions),
- }
- } else {
- $$ = nil
- }
- }
- | "REMOVE" "PARTITIONING"
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableRemovePartitioning,
- }
- }
- | "REORGANIZE" "PARTITION" NoWriteToBinLogAliasOpt ReorganizePartitionRuleOpt
- {
- ret := $4.(*ast.AlterTableSpec)
- ret.NoWriteToBinlog = $3.(bool)
- $$ = ret
- }
- LocationLabelList:
- {
- $$ = []string{}
- }
- | "LOCATION" "LABELS" StringList
- {
- $$ = $3
- }
- AlterTableSpec:
- TableOptionList %prec higherThanComma
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableOption,
- Options: $1.([]*ast.TableOption),
- }
- }
- | "SET" "TIFLASH" "REPLICA" LengthNum LocationLabelList
- {
- tiflashReplicaSpec := &ast.TiFlashReplicaSpec{
- Count: $4.(uint64),
- Labels: $5.([]string),
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableSetTiFlashReplica,
- TiFlashReplica: tiflashReplicaSpec,
- }
- }
- | "CONVERT" "TO" CharsetKw CharsetName OptCollate
- {
- op := &ast.AlterTableSpec{
- Tp: ast.AlterTableOption,
- Options: []*ast.TableOption{{Tp: ast.TableOptionCharset, StrValue: $4,
- UintValue: ast.TableOptionCharsetWithConvertTo}},
- }
- if $5 != "" {
- op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5})
- }
- $$ = op
- }
- | "CONVERT" "TO" CharsetKw "DEFAULT" OptCollate
- {
- op := &ast.AlterTableSpec{
- Tp: ast.AlterTableOption,
- Options: []*ast.TableOption{{Tp: ast.TableOptionCharset, Default: true,
- UintValue: ast.TableOptionCharsetWithConvertTo}},
- }
- if $5 != "" {
- op.Options = append(op.Options, &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $5})
- }
- $$ = op
- }
- | "ADD" ColumnKeywordOpt IfNotExists ColumnDef ColumnPosition
- {
- $$ = &ast.AlterTableSpec{
- IfNotExists: $3.(bool),
- Tp: ast.AlterTableAddColumns,
- NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)},
- Position: $5.(*ast.ColumnPosition),
- }
- }
- | "ADD" ColumnKeywordOpt IfNotExists '(' TableElementList ')'
- {
- tes := $5.([]interface{})
- var columnDefs []*ast.ColumnDef
- var constraints []*ast.Constraint
- for _, te := range tes {
- switch te := te.(type) {
- case *ast.ColumnDef:
- columnDefs = append(columnDefs, te)
- case *ast.Constraint:
- constraints = append(constraints, te)
- }
- }
- $$ = &ast.AlterTableSpec{
- IfNotExists: $3.(bool),
- Tp: ast.AlterTableAddColumns,
- NewColumns: columnDefs,
- NewConstraints: constraints,
- }
- }
- | "ADD" Constraint
- {
- constraint := $2.(*ast.Constraint)
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAddConstraint,
- Constraint: constraint,
- }
- }
- | "ADD" "PARTITION" IfNotExists NoWriteToBinLogAliasOpt PartitionDefinitionListOpt
- {
- var defs []*ast.PartitionDefinition
- if $5 != nil {
- defs = $5.([]*ast.PartitionDefinition)
- }
- noWriteToBinlog := $4.(bool)
- if noWriteToBinlog {
- yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now."))
- parser.lastErrorAsWarn()
- }
- $$ = &ast.AlterTableSpec{
- IfNotExists: $3.(bool),
- NoWriteToBinlog: noWriteToBinlog,
- Tp: ast.AlterTableAddPartitions,
- PartDefinitions: defs,
- }
- }
- | "ADD" "PARTITION" IfNotExists NoWriteToBinLogAliasOpt "PARTITIONS" NUM
- {
- noWriteToBinlog := $4.(bool)
- if noWriteToBinlog {
- yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now."))
- parser.lastErrorAsWarn()
- }
- $$ = &ast.AlterTableSpec{
- IfNotExists: $3.(bool),
- NoWriteToBinlog: noWriteToBinlog,
- Tp: ast.AlterTableAddPartitions,
- Num: getUint64FromNUM($6),
- }
- }
- | "ADD" "STATS_EXTENDED" IfNotExists Identifier StatsType '(' ColumnNameList ')'
- {
- statsSpec := &ast.StatisticsSpec{
- StatsName: $4,
- StatsType: $5.(uint8),
- Columns: $7.([]*ast.ColumnName),
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAddStatistics,
- IfNotExists: $3.(bool),
- Statistics: statsSpec,
- }
- }
- | "ALTER" "PARTITION" Identifier PlacementSpecList %prec lowerThanComma
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAlterPartition,
- PartitionNames: []model.CIStr{model.NewCIStr($3)},
- PlacementSpecs: $4.([]*ast.PlacementSpec),
- }
- }
- | "CHECK" "PARTITION" AllOrPartitionNameList
- {
- yylex.AppendError(yylex.Errorf("The CHECK PARTITIONING clause is parsed but not implement yet."))
- parser.lastErrorAsWarn()
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableCheckPartitions,
- }
- if $3 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $3.([]model.CIStr)
- }
- $$ = ret
- }
- | "COALESCE" "PARTITION" NoWriteToBinLogAliasOpt NUM
- {
- noWriteToBinlog := $3.(bool)
- if noWriteToBinlog {
- yylex.AppendError(yylex.Errorf("The NO_WRITE_TO_BINLOG option is parsed but ignored for now."))
- parser.lastErrorAsWarn()
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableCoalescePartitions,
- NoWriteToBinlog: noWriteToBinlog,
- Num: getUint64FromNUM($4),
- }
- }
- | "DROP" ColumnKeywordOpt IfExists ColumnName RestrictOrCascadeOpt
- {
- $$ = &ast.AlterTableSpec{
- IfExists: $3.(bool),
- Tp: ast.AlterTableDropColumn,
- OldColumnName: $4.(*ast.ColumnName),
- }
- }
- | "DROP" "PRIMARY" "KEY"
- {
- $$ = &ast.AlterTableSpec{Tp: ast.AlterTableDropPrimaryKey}
- }
- | "DROP" "PARTITION" IfExists PartitionNameList %prec lowerThanComma
- {
- $$ = &ast.AlterTableSpec{
- IfExists: $3.(bool),
- Tp: ast.AlterTableDropPartition,
- PartitionNames: $4.([]model.CIStr),
- }
- }
- | "DROP" "STATS_EXTENDED" IfExists Identifier
- {
- statsSpec := &ast.StatisticsSpec{
- StatsName: $4,
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableDropStatistics,
- IfExists: $3.(bool),
- Statistics: statsSpec,
- }
- }
- | "EXCHANGE" "PARTITION" Identifier "WITH" "TABLE" TableName WithValidationOpt
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableExchangePartition,
- PartitionNames: []model.CIStr{model.NewCIStr($3)},
- NewTable: $6.(*ast.TableName),
- WithValidation: $7.(bool),
- }
- }
- | "TRUNCATE" "PARTITION" AllOrPartitionNameList
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableTruncatePartition,
- }
- if $3 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $3.([]model.CIStr)
- }
- $$ = ret
- }
- | "OPTIMIZE" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList
- {
- ret := &ast.AlterTableSpec{
- NoWriteToBinlog: $3.(bool),
- Tp: ast.AlterTableOptimizePartition,
- }
- if $4 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $4.([]model.CIStr)
- }
- $$ = ret
- }
- | "REPAIR" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList
- {
- ret := &ast.AlterTableSpec{
- NoWriteToBinlog: $3.(bool),
- Tp: ast.AlterTableRepairPartition,
- }
- if $4 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $4.([]model.CIStr)
- }
- $$ = ret
- }
- | "IMPORT" "PARTITION" AllOrPartitionNameList "TABLESPACE"
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableImportPartitionTablespace,
- }
- if $3 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $3.([]model.CIStr)
- }
- $$ = ret
- yylex.AppendError(yylex.Errorf("The IMPORT PARTITION TABLESPACE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "DISCARD" "PARTITION" AllOrPartitionNameList "TABLESPACE"
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableDiscardPartitionTablespace,
- }
- if $3 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $3.([]model.CIStr)
- }
- $$ = ret
- yylex.AppendError(yylex.Errorf("The DISCARD PARTITION TABLESPACE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "IMPORT" "TABLESPACE"
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableImportTablespace,
- }
- $$ = ret
- yylex.AppendError(yylex.Errorf("The IMPORT TABLESPACE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "DISCARD" "TABLESPACE"
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableDiscardTablespace,
- }
- $$ = ret
- yylex.AppendError(yylex.Errorf("The DISCARD TABLESPACE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "REBUILD" "PARTITION" NoWriteToBinLogAliasOpt AllOrPartitionNameList
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableRebuildPartition,
- NoWriteToBinlog: $3.(bool),
- }
- if $4 == nil {
- ret.OnAllPartitions = true
- } else {
- ret.PartitionNames = $4.([]model.CIStr)
- }
- $$ = ret
- }
- | "DROP" KeyOrIndex IfExists Identifier
- {
- $$ = &ast.AlterTableSpec{
- IfExists: $3.(bool),
- Tp: ast.AlterTableDropIndex,
- Name: $4,
- }
- }
- | "DROP" "FOREIGN" "KEY" IfExists Symbol
- {
- $$ = &ast.AlterTableSpec{
- IfExists: $4.(bool),
- Tp: ast.AlterTableDropForeignKey,
- Name: $5,
- }
- }
- | "ORDER" "BY" AlterOrderList %prec lowerThenOrder
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableOrderByColumns,
- OrderByList: $3.([]*ast.AlterOrderItem),
- }
- }
- | "DISABLE" "KEYS"
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableDisableKeys,
- }
- }
- | "ENABLE" "KEYS"
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableEnableKeys,
- }
- }
- | "MODIFY" ColumnKeywordOpt IfExists ColumnDef ColumnPosition
- {
- $$ = &ast.AlterTableSpec{
- IfExists: $3.(bool),
- Tp: ast.AlterTableModifyColumn,
- NewColumns: []*ast.ColumnDef{$4.(*ast.ColumnDef)},
- Position: $5.(*ast.ColumnPosition),
- }
- }
- | "CHANGE" ColumnKeywordOpt IfExists ColumnName ColumnDef ColumnPosition
- {
- $$ = &ast.AlterTableSpec{
- IfExists: $3.(bool),
- Tp: ast.AlterTableChangeColumn,
- OldColumnName: $4.(*ast.ColumnName),
- NewColumns: []*ast.ColumnDef{$5.(*ast.ColumnDef)},
- Position: $6.(*ast.ColumnPosition),
- }
- }
- | "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" SignedLiteral
- {
- option := &ast.ColumnOption{Expr: $6}
- colDef := &ast.ColumnDef{
- Name: $3.(*ast.ColumnName),
- Options: []*ast.ColumnOption{option},
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAlterColumn,
- NewColumns: []*ast.ColumnDef{colDef},
- }
- }
- | "ALTER" ColumnKeywordOpt ColumnName "SET" "DEFAULT" '(' Expression ')'
- {
- option := &ast.ColumnOption{Expr: $7}
- colDef := &ast.ColumnDef{
- Name: $3.(*ast.ColumnName),
- Options: []*ast.ColumnOption{option},
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAlterColumn,
- NewColumns: []*ast.ColumnDef{colDef},
- }
- }
- | "ALTER" ColumnKeywordOpt ColumnName "DROP" "DEFAULT"
- {
- colDef := &ast.ColumnDef{
- Name: $3.(*ast.ColumnName),
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAlterColumn,
- NewColumns: []*ast.ColumnDef{colDef},
- }
- }
- | "RENAME" "COLUMN" Identifier "TO" Identifier
- {
- oldColName := &ast.ColumnName{Name: model.NewCIStr($3)}
- newColName := &ast.ColumnName{Name: model.NewCIStr($5)}
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableRenameColumn,
- OldColumnName: oldColName,
- NewColumnName: newColName,
- }
- }
- | "RENAME" "TO" TableName
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableRenameTable,
- NewTable: $3.(*ast.TableName),
- }
- }
- | "RENAME" EqOpt TableName
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableRenameTable,
- NewTable: $3.(*ast.TableName),
- }
- }
- | "RENAME" "AS" TableName
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableRenameTable,
- NewTable: $3.(*ast.TableName),
- }
- }
- | "RENAME" KeyOrIndex Identifier "TO" Identifier
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableRenameIndex,
- FromKey: model.NewCIStr($3),
- ToKey: model.NewCIStr($5),
- }
- }
- | LockClause
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableLock,
- LockType: $1.(ast.LockType),
- }
- }
- | Writeable
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableWriteable,
- Writeable: $1.(bool),
- }
- }
- | AlgorithmClause
- {
- // Parse it and ignore it. Just for compatibility.
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAlgorithm,
- Algorithm: $1.(ast.AlgorithmType),
- }
- }
- | "FORCE"
- {
- // Parse it and ignore it. Just for compatibility.
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableForce,
- }
- }
- | "WITH" "VALIDATION"
- {
- // Parse it and ignore it. Just for compatibility.
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableWithValidation,
- }
- }
- | "WITHOUT" "VALIDATION"
- {
- // Parse it and ignore it. Just for compatibility.
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableWithoutValidation,
- }
- }
- // Added in MySQL 8.0.13, see: https://dev.mysql.com/doc/refman/8.0/en/keywords.html for details
- | "SECONDARY_LOAD"
- {
- // Parse it and ignore it. Just for compatibility.
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableSecondaryLoad,
- }
- yylex.AppendError(yylex.Errorf("The SECONDARY_LOAD clause is parsed but not implement yet."))
- parser.lastErrorAsWarn()
- }
- // Added in MySQL 8.0.13, see: https://dev.mysql.com/doc/refman/8.0/en/keywords.html for details
- | "SECONDARY_UNLOAD"
- {
- // Parse it and ignore it. Just for compatibility.
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableSecondaryUnload,
- }
- yylex.AppendError(yylex.Errorf("The SECONDARY_UNLOAD VALIDATION clause is parsed but not implement yet."))
- parser.lastErrorAsWarn()
- }
- | "ALTER" CheckConstraintKeyword Identifier EnforcedOrNot
- {
- c := &ast.Constraint{
- Name: $3,
- Enforced: $4.(bool),
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableAlterCheck,
- Constraint: c,
- }
- }
- | "DROP" CheckConstraintKeyword Identifier
- {
- // Parse it and ignore it. Just for compatibility.
- c := &ast.Constraint{
- Name: $3,
- }
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableDropCheck,
- Constraint: c,
- }
- }
- | "ALTER" "INDEX" Identifier IndexInvisible
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTableIndexInvisible,
- IndexName: model.NewCIStr($3),
- Visibility: $4.(ast.IndexVisibility),
- }
- }
- | PlacementSpecList %prec lowerThanComma
- {
- $$ = &ast.AlterTableSpec{
- Tp: ast.AlterTablePlacement,
- PlacementSpecs: $1.([]*ast.PlacementSpec),
- }
- }
- ReorganizePartitionRuleOpt:
- /* empty */ %prec lowerThanRemove
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableReorganizePartition,
- OnAllPartitions: true,
- }
- $$ = ret
- }
- | PartitionNameList "INTO" '(' PartitionDefinitionList ')'
- {
- ret := &ast.AlterTableSpec{
- Tp: ast.AlterTableReorganizePartition,
- PartitionNames: $1.([]model.CIStr),
- PartDefinitions: $4.([]*ast.PartitionDefinition),
- }
- $$ = ret
- }
- AllOrPartitionNameList:
- "ALL"
- {
- $$ = nil
- }
- | PartitionNameList %prec lowerThanComma
- WithValidationOpt:
- {
- $$ = true
- }
- | WithValidation
- WithValidation:
- "WITH" "VALIDATION"
- {
- $$ = true
- }
- | "WITHOUT" "VALIDATION"
- {
- $$ = false
- }
- WithClustered:
- "CLUSTERED"
- {
- $$ = model.PrimaryKeyTypeClustered
- }
- | "NONCLUSTERED"
- {
- $$ = model.PrimaryKeyTypeNonClustered
- }
- AlgorithmClause:
- "ALGORITHM" EqOpt "DEFAULT"
- {
- $$ = ast.AlgorithmTypeDefault
- }
- | "ALGORITHM" EqOpt "COPY"
- {
- $$ = ast.AlgorithmTypeCopy
- }
- | "ALGORITHM" EqOpt "INPLACE"
- {
- $$ = ast.AlgorithmTypeInplace
- }
- | "ALGORITHM" EqOpt "INSTANT"
- {
- $$ = ast.AlgorithmTypeInstant
- }
- | "ALGORITHM" EqOpt identifier
- {
- yylex.AppendError(ErrUnknownAlterAlgorithm.GenWithStackByArgs($1))
- return 1
- }
- LockClause:
- "LOCK" EqOpt "DEFAULT"
- {
- $$ = ast.LockTypeDefault
- }
- | "LOCK" EqOpt Identifier
- {
- id := strings.ToUpper($3)
- if id == "NONE" {
- $$ = ast.LockTypeNone
- } else if id == "SHARED" {
- $$ = ast.LockTypeShared
- } else if id == "EXCLUSIVE" {
- $$ = ast.LockTypeExclusive
- } else {
- yylex.AppendError(ErrUnknownAlterLock.GenWithStackByArgs($3))
- return 1
- }
- }
- Writeable:
- "READ" "WRITE"
- {
- $$ = true
- }
- | "READ" "ONLY"
- {
- $$ = false
- }
- KeyOrIndex:
- "KEY"
- | "INDEX"
- KeyOrIndexOpt:
- {}
- | KeyOrIndex
- ColumnKeywordOpt:
- {}
- | "COLUMN"
- ColumnPosition:
- {
- $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionNone}
- }
- | "FIRST"
- {
- $$ = &ast.ColumnPosition{Tp: ast.ColumnPositionFirst}
- }
- | "AFTER" ColumnName
- {
- $$ = &ast.ColumnPosition{
- Tp: ast.ColumnPositionAfter,
- RelativeColumn: $2.(*ast.ColumnName),
- }
- }
- AlterTableSpecListOpt:
- /* empty */
- {
- $$ = make([]*ast.AlterTableSpec, 0, 1)
- }
- | AlterTableSpecList
- AlterTableSpecList:
- AlterTableSpec
- {
- $$ = []*ast.AlterTableSpec{$1.(*ast.AlterTableSpec)}
- }
- | AlterTableSpecList ',' AlterTableSpec
- {
- $$ = append($1.([]*ast.AlterTableSpec), $3.(*ast.AlterTableSpec))
- }
- PartitionNameList:
- Identifier
- {
- $$ = []model.CIStr{model.NewCIStr($1)}
- }
- | PartitionNameList ',' Identifier
- {
- $$ = append($1.([]model.CIStr), model.NewCIStr($3))
- }
- ConstraintKeywordOpt:
- {
- $$ = nil
- }
- | "CONSTRAINT"
- {
- $$ = nil
- }
- | "CONSTRAINT" Symbol
- {
- $$ = $2
- }
- Symbol:
- Identifier
- /**************************************RenameTableStmt***************************************
- * See http://dev.mysql.com/doc/refman/5.7/en/rename-table.html
- *
- * RENAME TABLE
- * tbl_name TO new_tbl_name
- * [, tbl_name2 TO new_tbl_name2] ...
- *******************************************************************************************/
- RenameTableStmt:
- "RENAME" "TABLE" TableToTableList
- {
- $$ = &ast.RenameTableStmt{
- TableToTables: $3.([]*ast.TableToTable),
- }
- }
- TableToTableList:
- TableToTable
- {
- $$ = []*ast.TableToTable{$1.(*ast.TableToTable)}
- }
- | TableToTableList ',' TableToTable
- {
- $$ = append($1.([]*ast.TableToTable), $3.(*ast.TableToTable))
- }
- TableToTable:
- TableName "TO" TableName
- {
- $$ = &ast.TableToTable{
- OldTable: $1.(*ast.TableName),
- NewTable: $3.(*ast.TableName),
- }
- }
- /**************************************RenameUserStmt***************************************
- * See https://dev.mysql.com/doc/refman/5.7/en/rename-user.html
- *
- * RENAME USER
- * old_user TO new_user
- * [, old_user2 TO new_user2] ...
- *******************************************************************************************/
- RenameUserStmt:
- "RENAME" "USER" UserToUserList
- {
- $$ = &ast.RenameUserStmt{
- UserToUsers: $3.([]*ast.UserToUser),
- }
- }
- UserToUserList:
- UserToUser
- {
- $$ = []*ast.UserToUser{$1.(*ast.UserToUser)}
- }
- | UserToUserList ',' UserToUser
- {
- $$ = append($1.([]*ast.UserToUser), $3.(*ast.UserToUser))
- }
- UserToUser:
- Username "TO" Username
- {
- $$ = &ast.UserToUser{
- OldUser: $1.(*auth.UserIdentity),
- NewUser: $3.(*auth.UserIdentity),
- }
- }
- /*******************************************************************
- *
- * Recover Table Statement
- *
- * Example:
- * RECOVER TABLE t1;
- * RECOVER TABLE BY JOB 100;
- *
- *******************************************************************/
- RecoverTableStmt:
- "RECOVER" "TABLE" "BY" "JOB" Int64Num
- {
- $$ = &ast.RecoverTableStmt{
- JobID: $5.(int64),
- }
- }
- | "RECOVER" "TABLE" TableName
- {
- $$ = &ast.RecoverTableStmt{
- Table: $3.(*ast.TableName),
- }
- }
- | "RECOVER" "TABLE" TableName Int64Num
- {
- $$ = &ast.RecoverTableStmt{
- Table: $3.(*ast.TableName),
- JobNum: $4.(int64),
- }
- }
- /*******************************************************************
- *
- * Flush Back Table Statement
- *
- * Example:
- *
- *******************************************************************/
- FlashbackTableStmt:
- "FLASHBACK" "TABLE" TableName FlashbackToNewName
- {
- $$ = &ast.FlashBackTableStmt{
- Table: $3.(*ast.TableName),
- NewName: $4,
- }
- }
- FlashbackToNewName:
- {
- $$ = ""
- }
- | "TO" Identifier
- {
- $$ = $2
- }
- /*******************************************************************
- *
- * Split index region statement
- *
- * Example:
- * SPLIT TABLE table_name INDEX index_name BY (val1...),(val2...)...
- *
- *******************************************************************/
- SplitRegionStmt:
- "SPLIT" SplitSyntaxOption "TABLE" TableName PartitionNameListOpt SplitOption
- {
- $$ = &ast.SplitRegionStmt{
- SplitSyntaxOpt: $2.(*ast.SplitSyntaxOption),
- Table: $4.(*ast.TableName),
- PartitionNames: $5.([]model.CIStr),
- SplitOpt: $6.(*ast.SplitOption),
- }
- }
- | "SPLIT" SplitSyntaxOption "TABLE" TableName PartitionNameListOpt "INDEX" Identifier SplitOption
- {
- $$ = &ast.SplitRegionStmt{
- SplitSyntaxOpt: $2.(*ast.SplitSyntaxOption),
- Table: $4.(*ast.TableName),
- PartitionNames: $5.([]model.CIStr),
- IndexName: model.NewCIStr($7),
- SplitOpt: $8.(*ast.SplitOption),
- }
- }
- SplitOption:
- "BETWEEN" RowValue "AND" RowValue "REGIONS" Int64Num
- {
- $$ = &ast.SplitOption{
- Lower: $2.([]ast.ExprNode),
- Upper: $4.([]ast.ExprNode),
- Num: $6.(int64),
- }
- }
- | "BY" ValuesList
- {
- $$ = &ast.SplitOption{
- ValueLists: $2.([][]ast.ExprNode),
- }
- }
- SplitSyntaxOption:
- /* empty */
- {
- $$ = &ast.SplitSyntaxOption{}
- }
- | "REGION" "FOR"
- {
- $$ = &ast.SplitSyntaxOption{
- HasRegionFor: true,
- }
- }
- | "PARTITION"
- {
- $$ = &ast.SplitSyntaxOption{
- HasPartition: true,
- }
- }
- | "REGION" "FOR" "PARTITION"
- {
- $$ = &ast.SplitSyntaxOption{
- HasRegionFor: true,
- HasPartition: true,
- }
- }
- AnalyzeTableStmt:
- "ANALYZE" "TABLE" TableNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{TableNames: $3.([]*ast.TableName), AnalyzeOpts: $4.([]ast.AnalyzeOpt)}
- }
- | "ANALYZE" "TABLE" TableName "INDEX" IndexNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, IndexNames: $5.([]model.CIStr), IndexFlag: true, AnalyzeOpts: $6.([]ast.AnalyzeOpt)}
- }
- | "ANALYZE" "INCREMENTAL" "TABLE" TableName "INDEX" IndexNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$4.(*ast.TableName)}, IndexNames: $6.([]model.CIStr), IndexFlag: true, Incremental: true, AnalyzeOpts: $7.([]ast.AnalyzeOpt)}
- }
- | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{TableNames: []*ast.TableName{$3.(*ast.TableName)}, PartitionNames: $5.([]model.CIStr), AnalyzeOpts: $6.([]ast.AnalyzeOpt)}
- }
- | "ANALYZE" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{
- TableNames: []*ast.TableName{$3.(*ast.TableName)},
- PartitionNames: $5.([]model.CIStr),
- IndexNames: $7.([]model.CIStr),
- IndexFlag: true,
- AnalyzeOpts: $8.([]ast.AnalyzeOpt),
- }
- }
- | "ANALYZE" "INCREMENTAL" "TABLE" TableName "PARTITION" PartitionNameList "INDEX" IndexNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{
- TableNames: []*ast.TableName{$4.(*ast.TableName)},
- PartitionNames: $6.([]model.CIStr),
- IndexNames: $8.([]model.CIStr),
- IndexFlag: true,
- Incremental: true,
- AnalyzeOpts: $9.([]ast.AnalyzeOpt),
- }
- }
- | "ANALYZE" "TABLE" TableName "UPDATE" "HISTOGRAM" "ON" ColumnNameList AnalyzeOptionListOpt
- {
- $$ = &ast.AnalyzeTableStmt{
- TableNames: []*ast.TableName{$3.(*ast.TableName)},
- ColumnNames: $7.([]*ast.ColumnName),
- AnalyzeOpts: $8.([]ast.AnalyzeOpt),
- HistogramOperation: ast.HistogramOperationUpdate,
- }
- }
- | "ANALYZE" "TABLE" TableName "DROP" "HISTOGRAM" "ON" ColumnNameList
- {
- $$ = &ast.AnalyzeTableStmt{
- TableNames: []*ast.TableName{$3.(*ast.TableName)},
- ColumnNames: $7.([]*ast.ColumnName),
- HistogramOperation: ast.HistogramOperationDrop,
- }
- }
- AnalyzeOptionListOpt:
- {
- $$ = []ast.AnalyzeOpt{}
- }
- | "WITH" AnalyzeOptionList
- {
- $$ = $2.([]ast.AnalyzeOpt)
- }
- AnalyzeOptionList:
- AnalyzeOption
- {
- $$ = []ast.AnalyzeOpt{$1.(ast.AnalyzeOpt)}
- }
- | AnalyzeOptionList ',' AnalyzeOption
- {
- $$ = append($1.([]ast.AnalyzeOpt), $3.(ast.AnalyzeOpt))
- }
- AnalyzeOption:
- NUM "BUCKETS"
- {
- $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumBuckets, Value: getUint64FromNUM($1)}
- }
- | NUM "TOPN"
- {
- $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumTopN, Value: getUint64FromNUM($1)}
- }
- | NUM "CMSKETCH" "DEPTH"
- {
- $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptCMSketchDepth, Value: getUint64FromNUM($1)}
- }
- | NUM "CMSKETCH" "WIDTH"
- {
- $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptCMSketchWidth, Value: getUint64FromNUM($1)}
- }
- | NUM "SAMPLES"
- {
- $$ = ast.AnalyzeOpt{Type: ast.AnalyzeOptNumSamples, Value: getUint64FromNUM($1)}
- }
- /*******************************************************************************************/
- Assignment:
- ColumnName eq ExprOrDefault
- {
- $$ = &ast.Assignment{Column: $1.(*ast.ColumnName), Expr: $3}
- }
- AssignmentList:
- Assignment
- {
- $$ = []*ast.Assignment{$1.(*ast.Assignment)}
- }
- | AssignmentList ',' Assignment
- {
- $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment))
- }
- AssignmentListOpt:
- /* EMPTY */
- {
- $$ = []*ast.Assignment{}
- }
- | AssignmentList
- BeginTransactionStmt:
- "BEGIN"
- {
- $$ = &ast.BeginStmt{}
- }
- | "BEGIN" "PESSIMISTIC"
- {
- $$ = &ast.BeginStmt{
- Mode: ast.Pessimistic,
- }
- }
- | "BEGIN" "OPTIMISTIC"
- {
- $$ = &ast.BeginStmt{
- Mode: ast.Optimistic,
- }
- }
- | "START" "TRANSACTION"
- {
- $$ = &ast.BeginStmt{}
- }
- | "START" "TRANSACTION" "READ" "WRITE"
- {
- $$ = &ast.BeginStmt{}
- }
- | "START" "TRANSACTION" "WITH" "CONSISTENT" "SNAPSHOT"
- {
- $$ = &ast.BeginStmt{}
- }
- | "START" "TRANSACTION" "READ" "ONLY"
- {
- $$ = &ast.BeginStmt{
- ReadOnly: true,
- }
- }
- | "START" "TRANSACTION" "READ" "ONLY" "WITH" "TIMESTAMP" "BOUND" TimestampBound
- {
- $$ = &ast.BeginStmt{
- ReadOnly: true,
- Bound: $8.(*ast.TimestampBound),
- }
- }
- | "START" "TRANSACTION" "WITH" "CAUSAL" "CONSISTENCY" "ONLY"
- {
- $$ = &ast.BeginStmt{
- CausalConsistencyOnly: true,
- }
- }
- TimestampBound:
- "STRONG"
- {
- $$ = &ast.TimestampBound{
- Mode: ast.TimestampBoundStrong,
- }
- }
- | "READ" "TIMESTAMP" Expression
- {
- $$ = &ast.TimestampBound{
- Mode: ast.TimestampBoundReadTimestamp,
- Timestamp: $3.(ast.ExprNode),
- }
- }
- | "MIN" "READ" "TIMESTAMP" Expression
- {
- $$ = &ast.TimestampBound{
- Mode: ast.TimestampBoundMinReadTimestamp,
- Timestamp: $4.(ast.ExprNode),
- }
- }
- | "MAX" "STALENESS" Expression
- {
- $$ = &ast.TimestampBound{
- Mode: ast.TimestampBoundMaxStaleness,
- Timestamp: $3.(ast.ExprNode),
- }
- }
- | "EXACT" "STALENESS" Expression
- {
- $$ = &ast.TimestampBound{
- Mode: ast.TimestampBoundExactStaleness,
- Timestamp: $3.(ast.ExprNode),
- }
- }
- BinlogStmt:
- "BINLOG" stringLit
- {
- $$ = &ast.BinlogStmt{Str: $2}
- }
- ColumnDefList:
- ColumnDef
- {
- $$ = []*ast.ColumnDef{$1.(*ast.ColumnDef)}
- }
- | ColumnDefList ',' ColumnDef
- {
- $$ = append($1.([]*ast.ColumnDef), $3.(*ast.ColumnDef))
- }
- ColumnDef:
- ColumnName Type ColumnOptionListOpt
- {
- colDef := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: $2.(*types.FieldType), Options: $3.([]*ast.ColumnOption)}
- if !colDef.Validate() {
- yylex.AppendError(yylex.Errorf("Invalid column definition"))
- return 1
- }
- $$ = colDef
- }
- | ColumnName "SERIAL" ColumnOptionListOpt
- {
- // TODO: check flen 0
- tp := types.NewFieldType(mysql.TypeLonglong)
- options := []*ast.ColumnOption{{Tp: ast.ColumnOptionNotNull}, {Tp: ast.ColumnOptionAutoIncrement}, {Tp: ast.ColumnOptionUniqKey}}
- options = append(options, $3.([]*ast.ColumnOption)...)
- tp.Flag |= mysql.UnsignedFlag
- colDef := &ast.ColumnDef{Name: $1.(*ast.ColumnName), Tp: tp, Options: options}
- if !colDef.Validate() {
- yylex.AppendError(yylex.Errorf("Invalid column definition"))
- return 1
- }
- $$ = colDef
- }
- ColumnName:
- Identifier
- {
- $$ = &ast.ColumnName{Name: model.NewCIStr($1)}
- }
- | Identifier '.' Identifier
- {
- $$ = &ast.ColumnName{Table: model.NewCIStr($1), Name: model.NewCIStr($3)}
- }
- | Identifier '.' Identifier '.' Identifier
- {
- $$ = &ast.ColumnName{Schema: model.NewCIStr($1), Table: model.NewCIStr($3), Name: model.NewCIStr($5)}
- }
- ColumnNameList:
- ColumnName
- {
- $$ = []*ast.ColumnName{$1.(*ast.ColumnName)}
- }
- | ColumnNameList ',' ColumnName
- {
- $$ = append($1.([]*ast.ColumnName), $3.(*ast.ColumnName))
- }
- ColumnNameListOpt:
- /* EMPTY */
- {
- $$ = []*ast.ColumnName{}
- }
- | ColumnNameList
- IdentListWithParenOpt:
- /* EMPTY */
- {
- $$ = []model.CIStr{}
- }
- | '(' IdentList ')'
- {
- $$ = $2
- }
- IdentList:
- Identifier
- {
- $$ = []model.CIStr{model.NewCIStr($1)}
- }
- | IdentList ',' Identifier
- {
- $$ = append($1.([]model.CIStr), model.NewCIStr($3))
- }
- ColumnNameOrUserVarListOpt:
- /* EMPTY */
- {
- $$ = []*ast.ColumnNameOrUserVar{}
- }
- | ColumnNameOrUserVariableList
- ColumnNameOrUserVariableList:
- ColumnNameOrUserVariable
- {
- $$ = []*ast.ColumnNameOrUserVar{$1.(*ast.ColumnNameOrUserVar)}
- }
- | ColumnNameOrUserVariableList ',' ColumnNameOrUserVariable
- {
- $$ = append($1.([]*ast.ColumnNameOrUserVar), $3.(*ast.ColumnNameOrUserVar))
- }
- ColumnNameOrUserVariable:
- ColumnName
- {
- $$ = &ast.ColumnNameOrUserVar{ColumnName: $1.(*ast.ColumnName)}
- }
- | UserVariable
- {
- $$ = &ast.ColumnNameOrUserVar{UserVar: $1.(*ast.VariableExpr)}
- }
- ColumnNameOrUserVarListOptWithBrackets:
- /* EMPTY */
- {
- $$ = []*ast.ColumnNameOrUserVar{}
- }
- | '(' ColumnNameOrUserVarListOpt ')'
- {
- $$ = $2.([]*ast.ColumnNameOrUserVar)
- }
- CommitStmt:
- "COMMIT"
- {
- $$ = &ast.CommitStmt{}
- }
- | "COMMIT" CompletionTypeWithinTransaction
- {
- $$ = &ast.CommitStmt{CompletionType: $2.(ast.CompletionType)}
- }
- PrimaryOpt:
- {}
- | "PRIMARY"
- NotSym:
- not
- | not2
- {
- $$ = "NOT"
- }
- EnforcedOrNot:
- "ENFORCED"
- {
- $$ = true
- }
- | NotSym "ENFORCED"
- {
- $$ = false
- }
- EnforcedOrNotOpt:
- %prec lowerThanNot
- {
- $$ = true
- }
- | EnforcedOrNot
- EnforcedOrNotOrNotNullOpt:
- // This branch is needed to workaround the need of a lookahead of 2 for the grammar:
- //
- // { [NOT] NULL | CHECK(...) [NOT] ENFORCED } ...
- NotSym "NULL"
- {
- $$ = 0
- }
- | EnforcedOrNotOpt
- {
- if $1.(bool) {
- $$ = 1
- } else {
- $$ = 2
- }
- }
- ColumnOption:
- NotSym "NULL"
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNotNull}
- }
- | "NULL"
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionNull}
- }
- | "AUTO_INCREMENT"
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoIncrement}
- }
- | PrimaryOpt "KEY"
- {
- // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY
- // can also be specified as just KEY when given in a column definition.
- // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey}
- }
- | PrimaryOpt "KEY" WithClustered
- {
- // KEY is normally a synonym for INDEX. The key attribute PRIMARY KEY
- // can also be specified as just KEY when given in a column definition.
- // See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionPrimaryKey, PrimaryKeyTp: $3.(model.PrimaryKeyType)}
- }
- | "UNIQUE" %prec lowerThanKey
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey}
- }
- | "UNIQUE" "KEY"
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionUniqKey}
- }
- | "DEFAULT" DefaultValueExpr
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionDefaultValue, Expr: $2}
- }
- | "SERIAL" "DEFAULT" "VALUE"
- {
- $$ = []*ast.ColumnOption{{Tp: ast.ColumnOptionNotNull}, {Tp: ast.ColumnOptionAutoIncrement}, {Tp: ast.ColumnOptionUniqKey}}
- }
- | "ON" "UPDATE" NowSymOptionFraction
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionOnUpdate, Expr: $3}
- }
- | "COMMENT" stringLit
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionComment, Expr: ast.NewValueExpr($2, "", "")}
- }
- | ConstraintKeywordOpt "CHECK" '(' Expression ')' EnforcedOrNotOrNotNullOpt
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/create-table.html
- // The CHECK clause is parsed but ignored by all storage engines.
- // See the branch named `EnforcedOrNotOrNotNullOpt`.
- optionCheck := &ast.ColumnOption{
- Tp: ast.ColumnOptionCheck,
- Expr: $4,
- Enforced: true,
- }
- // Keep the column type check constraint name.
- if $1 != nil {
- optionCheck.ConstraintName = $1.(string)
- }
- switch $6.(int) {
- case 0:
- $$ = []*ast.ColumnOption{optionCheck, {Tp: ast.ColumnOptionNotNull}}
- case 1:
- optionCheck.Enforced = true
- $$ = optionCheck
- case 2:
- optionCheck.Enforced = false
- $$ = optionCheck
- default:
- }
- }
- | GeneratedAlways "AS" '(' Expression ')' VirtualOrStored
- {
- startOffset := parser.startOffset(&yyS[yypt-2])
- endOffset := parser.endOffset(&yyS[yypt-1])
- expr := $4
- expr.SetText(parser.src[startOffset:endOffset])
- $$ = &ast.ColumnOption{
- Tp: ast.ColumnOptionGenerated,
- Expr: expr,
- Stored: $6.(bool),
- }
- }
- | ReferDef
- {
- $$ = &ast.ColumnOption{
- Tp: ast.ColumnOptionReference,
- Refer: $1.(*ast.ReferenceDef),
- }
- }
- | "COLLATE" CollationName
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionCollate, StrValue: $2}
- }
- | "COLUMN_FORMAT" ColumnFormat
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionColumnFormat, StrValue: $2}
- }
- | "STORAGE" StorageMedia
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionStorage, StrValue: $2}
- yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "AUTO_RANDOM" OptFieldLen
- {
- $$ = &ast.ColumnOption{Tp: ast.ColumnOptionAutoRandom, AutoRandomBitLength: $2.(int)}
- }
- StorageMedia:
- "DEFAULT"
- | "DISK"
- | "MEMORY"
- ColumnFormat:
- "DEFAULT"
- {
- $$ = "DEFAULT"
- }
- | "FIXED"
- {
- $$ = "FIXED"
- }
- | "DYNAMIC"
- {
- $$ = "DYNAMIC"
- }
- GeneratedAlways:
- | "GENERATED" "ALWAYS"
- VirtualOrStored:
- {
- $$ = false
- }
- | "VIRTUAL"
- {
- $$ = false
- }
- | "STORED"
- {
- $$ = true
- }
- ColumnOptionList:
- ColumnOption
- {
- if columnOption, ok := $1.(*ast.ColumnOption); ok {
- $$ = []*ast.ColumnOption{columnOption}
- } else {
- $$ = $1
- }
- }
- | ColumnOptionList ColumnOption
- {
- if columnOption, ok := $2.(*ast.ColumnOption); ok {
- $$ = append($1.([]*ast.ColumnOption), columnOption)
- } else {
- $$ = append($1.([]*ast.ColumnOption), $2.([]*ast.ColumnOption)...)
- }
- }
- ColumnOptionListOpt:
- {
- $$ = []*ast.ColumnOption{}
- }
- | ColumnOptionList
- ConstraintElem:
- "PRIMARY" "KEY" IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList
- {
- c := &ast.Constraint{
- Tp: ast.ConstraintPrimaryKey,
- Keys: $5.([]*ast.IndexPartSpecification),
- Name: $3.([]interface{})[0].(*ast.NullString).String,
- IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty,
- }
- if $7 != nil {
- c.Option = $7.(*ast.IndexOption)
- }
- if indexType := $3.([]interface{})[1]; indexType != nil {
- if c.Option == nil {
- c.Option = &ast.IndexOption{}
- }
- c.Option.Tp = indexType.(model.IndexType)
- }
- $$ = c
- }
- | "FULLTEXT" KeyOrIndexOpt IndexName '(' IndexPartSpecificationList ')' IndexOptionList
- {
- c := &ast.Constraint{
- Tp: ast.ConstraintFulltext,
- Keys: $5.([]*ast.IndexPartSpecification),
- Name: $3.(*ast.NullString).String,
- IsEmptyIndex: $3.(*ast.NullString).Empty,
- }
- if $7 != nil {
- c.Option = $7.(*ast.IndexOption)
- }
- $$ = c
- }
- | KeyOrIndex IfNotExists IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList
- {
- c := &ast.Constraint{
- IfNotExists: $2.(bool),
- Tp: ast.ConstraintIndex,
- Keys: $5.([]*ast.IndexPartSpecification),
- Name: $3.([]interface{})[0].(*ast.NullString).String,
- IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty,
- }
- if $7 != nil {
- c.Option = $7.(*ast.IndexOption)
- }
- if indexType := $3.([]interface{})[1]; indexType != nil {
- if c.Option == nil {
- c.Option = &ast.IndexOption{}
- }
- c.Option.Tp = indexType.(model.IndexType)
- }
- $$ = c
- }
- | "UNIQUE" KeyOrIndexOpt IndexNameAndTypeOpt '(' IndexPartSpecificationList ')' IndexOptionList
- {
- c := &ast.Constraint{
- Tp: ast.ConstraintUniq,
- Keys: $5.([]*ast.IndexPartSpecification),
- Name: $3.([]interface{})[0].(*ast.NullString).String,
- IsEmptyIndex: $3.([]interface{})[0].(*ast.NullString).Empty,
- }
- if $7 != nil {
- c.Option = $7.(*ast.IndexOption)
- }
- if indexType := $3.([]interface{})[1]; indexType != nil {
- if c.Option == nil {
- c.Option = &ast.IndexOption{}
- }
- c.Option.Tp = indexType.(model.IndexType)
- }
- $$ = c
- }
- | "FOREIGN" "KEY" IfNotExists IndexName '(' IndexPartSpecificationList ')' ReferDef
- {
- $$ = &ast.Constraint{
- IfNotExists: $3.(bool),
- Tp: ast.ConstraintForeignKey,
- Keys: $6.([]*ast.IndexPartSpecification),
- Name: $4.(*ast.NullString).String,
- Refer: $8.(*ast.ReferenceDef),
- IsEmptyIndex: $4.(*ast.NullString).Empty,
- }
- }
- | "CHECK" '(' Expression ')' EnforcedOrNotOpt
- {
- $$ = &ast.Constraint{
- Tp: ast.ConstraintCheck,
- Expr: $3.(ast.ExprNode),
- Enforced: $5.(bool),
- }
- }
- Match:
- "MATCH" "FULL"
- {
- $$ = ast.MatchFull
- }
- | "MATCH" "PARTIAL"
- {
- $$ = ast.MatchPartial
- }
- | "MATCH" "SIMPLE"
- {
- $$ = ast.MatchSimple
- }
- MatchOpt:
- {
- $$ = ast.MatchNone
- }
- | Match
- {
- $$ = $1
- yylex.AppendError(yylex.Errorf("The MATCH clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- ReferDef:
- "REFERENCES" TableName IndexPartSpecificationListOpt MatchOpt OnDeleteUpdateOpt
- {
- onDeleteUpdate := $5.([2]interface{})
- $$ = &ast.ReferenceDef{
- Table: $2.(*ast.TableName),
- IndexPartSpecifications: $3.([]*ast.IndexPartSpecification),
- OnDelete: onDeleteUpdate[0].(*ast.OnDeleteOpt),
- OnUpdate: onDeleteUpdate[1].(*ast.OnUpdateOpt),
- Match: $4.(ast.MatchType),
- }
- }
- OnDelete:
- "ON" "DELETE" ReferOpt
- {
- $$ = &ast.OnDeleteOpt{ReferOpt: $3.(ast.ReferOptionType)}
- }
- OnUpdate:
- "ON" "UPDATE" ReferOpt
- {
- $$ = &ast.OnUpdateOpt{ReferOpt: $3.(ast.ReferOptionType)}
- }
- OnDeleteUpdateOpt:
- %prec lowerThanOn
- {
- $$ = [2]interface{}{&ast.OnDeleteOpt{}, &ast.OnUpdateOpt{}}
- }
- | OnDelete %prec lowerThanOn
- {
- $$ = [2]interface{}{$1, &ast.OnUpdateOpt{}}
- }
- | OnUpdate %prec lowerThanOn
- {
- $$ = [2]interface{}{&ast.OnDeleteOpt{}, $1}
- }
- | OnDelete OnUpdate
- {
- $$ = [2]interface{}{$1, $2}
- }
- | OnUpdate OnDelete
- {
- $$ = [2]interface{}{$2, $1}
- }
- ReferOpt:
- "RESTRICT"
- {
- $$ = ast.ReferOptionRestrict
- }
- | "CASCADE"
- {
- $$ = ast.ReferOptionCascade
- }
- | "SET" "NULL"
- {
- $$ = ast.ReferOptionSetNull
- }
- | "NO" "ACTION"
- {
- $$ = ast.ReferOptionNoAction
- }
- | "SET" "DEFAULT"
- {
- $$ = ast.ReferOptionSetDefault
- yylex.AppendError(yylex.Errorf("The SET DEFAULT clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- /*
- * The DEFAULT clause specifies a default value for a column.
- * With one exception, the default value must be a constant;
- * it cannot be a function or an expression. This means, for example,
- * that you cannot set the default for a date column to be the value of
- * a function such as NOW() or CURRENT_DATE. The exception is that you
- * can specify CURRENT_TIMESTAMP as the default for a TIMESTAMP or DATETIME column.
- *
- * See http://dev.mysql.com/doc/refman/5.7/en/create-table.html
- * https://github.com/mysql/mysql-server/blob/5.7/sql/sql_yacc.yy#L6832
- */
- DefaultValueExpr:
- NowSymOptionFraction
- | SignedLiteral
- | NextValueForSequence
- NowSymOptionFraction:
- NowSym
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
- }
- | NowSymFunc '(' ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP")}
- }
- | NowSymFunc '(' NUM ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr("CURRENT_TIMESTAMP"), Args: []ast.ExprNode{ast.NewValueExpr($3, parser.charset, parser.collation)}}
- }
- NextValueForSequence:
- "NEXT" "VALUE" forKwd TableName
- {
- objNameExpr := &ast.TableNameExpr{
- Name: $4.(*ast.TableName),
- }
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr(ast.NextVal),
- Args: []ast.ExprNode{objNameExpr},
- }
- }
- | "NEXTVAL" '(' TableName ')'
- {
- objNameExpr := &ast.TableNameExpr{
- Name: $3.(*ast.TableName),
- }
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr(ast.NextVal),
- Args: []ast.ExprNode{objNameExpr},
- }
- }
- /*
- * See https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_localtime
- * TODO: Process other three keywords
- */
- NowSymFunc:
- "CURRENT_TIMESTAMP"
- | "LOCALTIME"
- | "LOCALTIMESTAMP"
- | builtinNow
- NowSym:
- "CURRENT_TIMESTAMP"
- | "LOCALTIME"
- | "LOCALTIMESTAMP"
- SignedLiteral:
- Literal
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | '+' NumLiteral
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: ast.NewValueExpr($2, parser.charset, parser.collation)}
- }
- | '-' NumLiteral
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: ast.NewValueExpr($2, parser.charset, parser.collation)}
- }
- NumLiteral:
- intLit
- | floatLit
- | decLit
- StatsType:
- "CARDINALITY"
- {
- $$ = ast.StatsTypeCardinality
- }
- | "DEPENDENCY"
- {
- $$ = ast.StatsTypeDependency
- }
- | "CORRELATION"
- {
- $$ = ast.StatsTypeCorrelation
- }
- CreateStatisticsStmt:
- "CREATE" "STATISTICS" IfNotExists Identifier '(' StatsType ')' "ON" TableName '(' ColumnNameList ')'
- {
- $$ = &ast.CreateStatisticsStmt{
- IfNotExists: $3.(bool),
- StatsName: $4,
- StatsType: $6.(uint8),
- Table: $9.(*ast.TableName),
- Columns: $11.([]*ast.ColumnName),
- }
- }
- DropStatisticsStmt:
- "DROP" "STATISTICS" Identifier
- {
- $$ = &ast.DropStatisticsStmt{StatsName: $3}
- }
- /**************************************CreateIndexStmt***************************************
- * See https://dev.mysql.com/doc/refman/8.0/en/create-index.html
- *
- * TYPE type_name is recognized as a synonym for USING type_name. However, USING is the preferred form.
- *
- * CREATE [UNIQUE | FULLTEXT | SPATIAL] INDEX index_name
- * [index_type]
- * ON tbl_name (key_part,...)
- * [index_option]
- * [algorithm_option | lock_option] ...
- *
- * key_part: {col_name [(length)] | (expr)} [ASC | DESC]
- *
- * index_option:
- * KEY_BLOCK_SIZE [=] value
- * | index_type
- * | WITH PARSER parser_name
- * | COMMENT 'string'
- * | {VISIBLE | INVISIBLE}
- *
- * index_type:
- * USING {BTREE | HASH}
- *
- * algorithm_option:
- * ALGORITHM [=] {DEFAULT | INPLACE | COPY}
- *
- * lock_option:
- * LOCK [=] {DEFAULT | NONE | SHARED | EXCLUSIVE}
- *******************************************************************************************/
- CreateIndexStmt:
- "CREATE" IndexKeyTypeOpt "INDEX" IfNotExists Identifier IndexTypeOpt "ON" TableName '(' IndexPartSpecificationList ')' IndexOptionList IndexLockAndAlgorithmOpt
- {
- var indexOption *ast.IndexOption
- if $12 != nil {
- indexOption = $12.(*ast.IndexOption)
- if indexOption.Tp == model.IndexTypeInvalid {
- if $6 != nil {
- indexOption.Tp = $6.(model.IndexType)
- }
- }
- } else {
- indexOption = &ast.IndexOption{}
- if $6 != nil {
- indexOption.Tp = $6.(model.IndexType)
- }
- }
- var indexLockAndAlgorithm *ast.IndexLockAndAlgorithm
- if $13 != nil {
- indexLockAndAlgorithm = $13.(*ast.IndexLockAndAlgorithm)
- if indexLockAndAlgorithm.LockTp == ast.LockTypeDefault && indexLockAndAlgorithm.AlgorithmTp == ast.AlgorithmTypeDefault {
- indexLockAndAlgorithm = nil
- }
- }
- $$ = &ast.CreateIndexStmt{
- IfNotExists: $4.(bool),
- IndexName: $5,
- Table: $8.(*ast.TableName),
- IndexPartSpecifications: $10.([]*ast.IndexPartSpecification),
- IndexOption: indexOption,
- KeyType: $2.(ast.IndexKeyType),
- LockAlg: indexLockAndAlgorithm,
- }
- }
- IndexPartSpecificationListOpt:
- {
- $$ = ([]*ast.IndexPartSpecification)(nil)
- }
- | '(' IndexPartSpecificationList ')'
- {
- $$ = $2
- }
- IndexPartSpecificationList:
- IndexPartSpecification
- {
- $$ = []*ast.IndexPartSpecification{$1.(*ast.IndexPartSpecification)}
- }
- | IndexPartSpecificationList ',' IndexPartSpecification
- {
- $$ = append($1.([]*ast.IndexPartSpecification), $3.(*ast.IndexPartSpecification))
- }
- IndexPartSpecification:
- ColumnName OptFieldLen OptOrder
- {
- // Order is parsed but just ignored as MySQL did.
- $$ = &ast.IndexPartSpecification{Column: $1.(*ast.ColumnName), Length: $2.(int)}
- }
- | '(' Expression ')' OptOrder
- {
- $$ = &ast.IndexPartSpecification{Expr: $2}
- }
- IndexLockAndAlgorithmOpt:
- {
- $$ = nil
- }
- | LockClause
- {
- $$ = &ast.IndexLockAndAlgorithm{
- LockTp: $1.(ast.LockType),
- AlgorithmTp: ast.AlgorithmTypeDefault,
- }
- }
- | AlgorithmClause
- {
- $$ = &ast.IndexLockAndAlgorithm{
- LockTp: ast.LockTypeDefault,
- AlgorithmTp: $1.(ast.AlgorithmType),
- }
- }
- | LockClause AlgorithmClause
- {
- $$ = &ast.IndexLockAndAlgorithm{
- LockTp: $1.(ast.LockType),
- AlgorithmTp: $2.(ast.AlgorithmType),
- }
- }
- | AlgorithmClause LockClause
- {
- $$ = &ast.IndexLockAndAlgorithm{
- LockTp: $2.(ast.LockType),
- AlgorithmTp: $1.(ast.AlgorithmType),
- }
- }
- IndexKeyTypeOpt:
- {
- $$ = ast.IndexKeyTypeNone
- }
- | "UNIQUE"
- {
- $$ = ast.IndexKeyTypeUnique
- }
- | "SPATIAL"
- {
- $$ = ast.IndexKeyTypeSpatial
- }
- | "FULLTEXT"
- {
- $$ = ast.IndexKeyTypeFullText
- }
- /**************************************AlterDatabaseStmt***************************************
- * See https://dev.mysql.com/doc/refman/5.7/en/alter-database.html
- * 'ALTER DATABASE ... UPGRADE DATA DIRECTORY NAME' is not supported yet.
- *
- * ALTER {DATABASE | SCHEMA} [db_name]
- * alter_specification ...
- *
- * alter_specification:
- * [DEFAULT] CHARACTER SET [=] charset_name
- * | [DEFAULT] COLLATE [=] collation_name
- * | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'}
- *******************************************************************************************/
- AlterDatabaseStmt:
- "ALTER" DatabaseSym DBName DatabaseOptionList
- {
- $$ = &ast.AlterDatabaseStmt{
- Name: $3,
- AlterDefaultDatabase: false,
- Options: $4.([]*ast.DatabaseOption),
- }
- }
- | "ALTER" DatabaseSym DatabaseOptionList
- {
- $$ = &ast.AlterDatabaseStmt{
- Name: "",
- AlterDefaultDatabase: true,
- Options: $3.([]*ast.DatabaseOption),
- }
- }
- /*******************************************************************
- *
- * Create Database Statement
- * CREATE {DATABASE | SCHEMA} [IF NOT EXISTS] db_name
- * [create_specification] ...
- *
- * create_specification:
- * [DEFAULT] CHARACTER SET [=] charset_name
- * | [DEFAULT] COLLATE [=] collation_name
- * | [DEFAULT] ENCRYPTION [=] {'Y' | 'N'}
- *******************************************************************/
- CreateDatabaseStmt:
- "CREATE" DatabaseSym IfNotExists DBName DatabaseOptionListOpt
- {
- $$ = &ast.CreateDatabaseStmt{
- IfNotExists: $3.(bool),
- Name: $4,
- Options: $5.([]*ast.DatabaseOption),
- }
- }
- DBName:
- Identifier
- DatabaseOption:
- DefaultKwdOpt CharsetKw EqOpt CharsetName
- {
- $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCharset, Value: $4}
- }
- | DefaultKwdOpt "COLLATE" EqOpt CollationName
- {
- $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionCollate, Value: $4}
- }
- | DefaultKwdOpt "ENCRYPTION" EqOpt EncryptionOpt
- {
- $$ = &ast.DatabaseOption{Tp: ast.DatabaseOptionEncryption, Value: $4}
- }
- DatabaseOptionListOpt:
- {
- $$ = []*ast.DatabaseOption{}
- }
- | DatabaseOptionList
- DatabaseOptionList:
- DatabaseOption
- {
- $$ = []*ast.DatabaseOption{$1.(*ast.DatabaseOption)}
- }
- | DatabaseOptionList DatabaseOption
- {
- $$ = append($1.([]*ast.DatabaseOption), $2.(*ast.DatabaseOption))
- }
- /*******************************************************************
- *
- * Create Table Statement
- *
- * Example:
- * CREATE TABLE Persons
- * (
- * P_Id int NOT NULL,
- * LastName varchar(255) NOT NULL,
- * FirstName varchar(255),
- * Address varchar(255),
- * City varchar(255),
- * PRIMARY KEY (P_Id)
- * )
- *******************************************************************/
- CreateTableStmt:
- "CREATE" OptTemporary "TABLE" IfNotExists TableName TableElementListOpt CreateTableOptionListOpt PartitionOpt DuplicateOpt AsOpt CreateTableSelectOpt
- {
- stmt := $6.(*ast.CreateTableStmt)
- stmt.Table = $5.(*ast.TableName)
- stmt.IfNotExists = $4.(bool)
- stmt.IsTemporary = $2.(bool)
- stmt.Options = $7.([]*ast.TableOption)
- if $8 != nil {
- stmt.Partition = $8.(*ast.PartitionOptions)
- }
- stmt.OnDuplicate = $9.(ast.OnDuplicateKeyHandlingType)
- stmt.Select = $11.(*ast.CreateTableStmt).Select
- $$ = stmt
- }
- | "CREATE" OptTemporary "TABLE" IfNotExists TableName LikeTableWithOrWithoutParen
- {
- $$ = &ast.CreateTableStmt{
- Table: $5.(*ast.TableName),
- ReferTable: $6.(*ast.TableName),
- IfNotExists: $4.(bool),
- IsTemporary: $2.(bool),
- }
- }
- DefaultKwdOpt:
- %prec lowerThanCharsetKwd
- {}
- | "DEFAULT"
- PartitionOpt:
- {
- $$ = nil
- }
- | "PARTITION" "BY" PartitionMethod PartitionNumOpt SubPartitionOpt PartitionDefinitionListOpt
- {
- method := $3.(*ast.PartitionMethod)
- method.Num = $4.(uint64)
- sub, _ := $5.(*ast.PartitionMethod)
- defs, _ := $6.([]*ast.PartitionDefinition)
- opt := &ast.PartitionOptions{
- PartitionMethod: *method,
- Sub: sub,
- Definitions: defs,
- }
- if err := opt.Validate(); err != nil {
- yylex.AppendError(err)
- return 1
- }
- $$ = opt
- }
- SubPartitionMethod:
- LinearOpt "KEY" PartitionKeyAlgorithmOpt '(' ColumnNameListOpt ')'
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeKey,
- Linear: len($1) != 0,
- ColumnNames: $5.([]*ast.ColumnName),
- }
- }
- | LinearOpt "HASH" '(' BitExpr ')'
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeHash,
- Linear: len($1) != 0,
- Expr: $4.(ast.ExprNode),
- }
- }
- PartitionKeyAlgorithmOpt:
- /* empty */
- {}
- | "ALGORITHM" '=' NUM
- {}
- PartitionMethod:
- SubPartitionMethod
- | "RANGE" '(' BitExpr ')'
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeRange,
- Expr: $3.(ast.ExprNode),
- }
- }
- | "RANGE" FieldsOrColumns '(' ColumnNameList ')'
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeRange,
- ColumnNames: $4.([]*ast.ColumnName),
- }
- }
- | "LIST" '(' BitExpr ')'
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeList,
- Expr: $3.(ast.ExprNode),
- }
- }
- | "LIST" FieldsOrColumns '(' ColumnNameList ')'
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeList,
- ColumnNames: $4.([]*ast.ColumnName),
- }
- }
- | "SYSTEM_TIME" "INTERVAL" Expression TimeUnit
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeSystemTime,
- Expr: $3.(ast.ExprNode),
- Unit: $4.(ast.TimeUnitType),
- }
- }
- | "SYSTEM_TIME" "LIMIT" LengthNum
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeSystemTime,
- Limit: $3.(uint64),
- }
- }
- | "SYSTEM_TIME"
- {
- $$ = &ast.PartitionMethod{
- Tp: model.PartitionTypeSystemTime,
- }
- }
- LinearOpt:
- {
- $$ = ""
- }
- | "LINEAR"
- SubPartitionOpt:
- {
- $$ = nil
- }
- | "SUBPARTITION" "BY" SubPartitionMethod SubPartitionNumOpt
- {
- method := $3.(*ast.PartitionMethod)
- method.Num = $4.(uint64)
- $$ = method
- }
- SubPartitionNumOpt:
- {
- $$ = uint64(0)
- }
- | "SUBPARTITIONS" LengthNum
- {
- res := $2.(uint64)
- if res == 0 {
- yylex.AppendError(ast.ErrNoParts.GenWithStackByArgs("subpartitions"))
- return 1
- }
- $$ = res
- }
- PartitionNumOpt:
- {
- $$ = uint64(0)
- }
- | "PARTITIONS" LengthNum
- {
- res := $2.(uint64)
- if res == 0 {
- yylex.AppendError(ast.ErrNoParts.GenWithStackByArgs("partitions"))
- return 1
- }
- $$ = res
- }
- PartitionDefinitionListOpt:
- /* empty */ %prec lowerThanCreateTableSelect
- {
- $$ = nil
- }
- | '(' PartitionDefinitionList ')'
- {
- $$ = $2.([]*ast.PartitionDefinition)
- }
- PartitionDefinitionList:
- PartitionDefinition
- {
- $$ = []*ast.PartitionDefinition{$1.(*ast.PartitionDefinition)}
- }
- | PartitionDefinitionList ',' PartitionDefinition
- {
- $$ = append($1.([]*ast.PartitionDefinition), $3.(*ast.PartitionDefinition))
- }
- PartitionDefinition:
- "PARTITION" Identifier PartDefValuesOpt PartDefOptionList SubPartDefinitionListOpt
- {
- $$ = &ast.PartitionDefinition{
- Name: model.NewCIStr($2),
- Clause: $3.(ast.PartitionDefinitionClause),
- Options: $4.([]*ast.TableOption),
- Sub: $5.([]*ast.SubPartitionDefinition),
- }
- }
- SubPartDefinitionListOpt:
- /*empty*/
- {
- $$ = make([]*ast.SubPartitionDefinition, 0)
- }
- | '(' SubPartDefinitionList ')'
- {
- $$ = $2
- }
- SubPartDefinitionList:
- SubPartDefinition
- {
- $$ = []*ast.SubPartitionDefinition{$1.(*ast.SubPartitionDefinition)}
- }
- | SubPartDefinitionList ',' SubPartDefinition
- {
- list := $1.([]*ast.SubPartitionDefinition)
- $$ = append(list, $3.(*ast.SubPartitionDefinition))
- }
- SubPartDefinition:
- "SUBPARTITION" Identifier PartDefOptionList
- {
- $$ = &ast.SubPartitionDefinition{
- Name: model.NewCIStr($2),
- Options: $3.([]*ast.TableOption),
- }
- }
- PartDefOptionList:
- /*empty*/
- {
- $$ = make([]*ast.TableOption, 0)
- }
- | PartDefOptionList PartDefOption
- {
- list := $1.([]*ast.TableOption)
- $$ = append(list, $2.(*ast.TableOption))
- }
- PartDefOption:
- "COMMENT" EqOpt stringLit
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionComment, StrValue: $3}
- }
- | "ENGINE" EqOpt StringName
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionEngine, StrValue: $3}
- }
- | "STORAGE" "ENGINE" EqOpt StringName
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionEngine, StrValue: $4}
- }
- | "INSERT_METHOD" EqOpt StringName
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionInsertMethod, StrValue: $3}
- }
- | "DATA" "DIRECTORY" EqOpt stringLit
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionDataDirectory, StrValue: $4}
- }
- | "INDEX" "DIRECTORY" EqOpt stringLit
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionIndexDirectory, StrValue: $4}
- }
- | "MAX_ROWS" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionMaxRows, UintValue: $3.(uint64)}
- }
- | "MIN_ROWS" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionMinRows, UintValue: $3.(uint64)}
- }
- | "TABLESPACE" EqOpt Identifier
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionTablespace, StrValue: $3}
- }
- | "NODEGROUP" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionNodegroup, UintValue: $3.(uint64)}
- }
- PartDefValuesOpt:
- {
- $$ = &ast.PartitionDefinitionClauseNone{}
- }
- | "VALUES" "LESS" "THAN" "MAXVALUE"
- {
- $$ = &ast.PartitionDefinitionClauseLessThan{
- Exprs: []ast.ExprNode{&ast.MaxValueExpr{}},
- }
- }
- | "VALUES" "LESS" "THAN" '(' MaxValueOrExpressionList ')'
- {
- $$ = &ast.PartitionDefinitionClauseLessThan{
- Exprs: $5.([]ast.ExprNode),
- }
- }
- | "DEFAULT"
- {
- $$ = &ast.PartitionDefinitionClauseIn{}
- }
- | "VALUES" "IN" '(' MaxValueOrExpressionList ')'
- {
- exprs := $4.([]ast.ExprNode)
- values := make([][]ast.ExprNode, 0, len(exprs))
- for _, expr := range exprs {
- if row, ok := expr.(*ast.RowExpr); ok {
- values = append(values, row.Values)
- } else {
- values = append(values, []ast.ExprNode{expr})
- }
- }
- $$ = &ast.PartitionDefinitionClauseIn{Values: values}
- }
- | "HISTORY"
- {
- $$ = &ast.PartitionDefinitionClauseHistory{Current: false}
- }
- | "CURRENT"
- {
- $$ = &ast.PartitionDefinitionClauseHistory{Current: true}
- }
- DuplicateOpt:
- {
- $$ = ast.OnDuplicateKeyHandlingError
- }
- | "IGNORE"
- {
- $$ = ast.OnDuplicateKeyHandlingIgnore
- }
- | "REPLACE"
- {
- $$ = ast.OnDuplicateKeyHandlingReplace
- }
- AsOpt:
- {}
- | "AS"
- {}
- CreateTableSelectOpt:
- /* empty */
- {
- $$ = &ast.CreateTableStmt{}
- }
- | SetOprStmt1
- {
- $$ = &ast.CreateTableStmt{Select: $1}
- }
- CreateViewSelectOpt:
- SetOprStmt1
- | '(' SetOprStmt1 ')'
- {
- $$ = $2
- }
- LikeTableWithOrWithoutParen:
- "LIKE" TableName
- {
- $$ = $2
- }
- | '(' "LIKE" TableName ')'
- {
- $$ = $3
- }
- /*******************************************************************
- *
- * Create View Statement
- *
- * Example:
- * CREATE VIEW OR REPLACE ALGORITHM = MERGE DEFINER="root@localhost" SQL SECURITY = definer view_name (col1,col2)
- * as select Col1,Col2 from table WITH LOCAL CHECK OPTION
- *******************************************************************/
- CreateViewStmt:
- "CREATE" OrReplace ViewAlgorithm ViewDefiner ViewSQLSecurity "VIEW" ViewName ViewFieldList "AS" CreateViewSelectOpt ViewCheckOption
- {
- startOffset := parser.startOffset(&yyS[yypt-1])
- selStmt := $10.(ast.StmtNode)
- selStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
- x := &ast.CreateViewStmt{
- OrReplace: $2.(bool),
- ViewName: $7.(*ast.TableName),
- Select: selStmt,
- Algorithm: $3.(model.ViewAlgorithm),
- Definer: $4.(*auth.UserIdentity),
- Security: $5.(model.ViewSecurity),
- }
- if $8 != nil {
- x.Cols = $8.([]model.CIStr)
- }
- if $11 != nil {
- x.CheckOption = $11.(model.ViewCheckOption)
- endOffset := parser.startOffset(&yyS[yypt])
- selStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset]))
- } else {
- x.CheckOption = model.CheckOptionCascaded
- }
- $$ = x
- }
- OrReplace:
- /* EMPTY */
- {
- $$ = false
- }
- | "OR" "REPLACE"
- {
- $$ = true
- }
- ViewAlgorithm:
- /* EMPTY */
- {
- $$ = model.AlgorithmUndefined
- }
- | "ALGORITHM" "=" "UNDEFINED"
- {
- $$ = model.AlgorithmUndefined
- }
- | "ALGORITHM" "=" "MERGE"
- {
- $$ = model.AlgorithmMerge
- }
- | "ALGORITHM" "=" "TEMPTABLE"
- {
- $$ = model.AlgorithmTemptable
- }
- ViewDefiner:
- /* EMPTY */
- {
- $$ = &auth.UserIdentity{CurrentUser: true}
- }
- | "DEFINER" "=" Username
- {
- $$ = $3
- }
- ViewSQLSecurity:
- /* EMPTY */
- {
- $$ = model.SecurityDefiner
- }
- | "SQL" "SECURITY" "DEFINER"
- {
- $$ = model.SecurityDefiner
- }
- | "SQL" "SECURITY" "INVOKER"
- {
- $$ = model.SecurityInvoker
- }
- ViewName:
- TableName
- ViewFieldList:
- /* Empty */
- {
- $$ = nil
- }
- | '(' ColumnList ')'
- {
- $$ = $2.([]model.CIStr)
- }
- ColumnList:
- Identifier
- {
- $$ = []model.CIStr{model.NewCIStr($1)}
- }
- | ColumnList ',' Identifier
- {
- $$ = append($1.([]model.CIStr), model.NewCIStr($3))
- }
- ViewCheckOption:
- /* EMPTY */
- {
- $$ = nil
- }
- | "WITH" "CASCADED" "CHECK" "OPTION"
- {
- $$ = model.CheckOptionCascaded
- }
- | "WITH" "LOCAL" "CHECK" "OPTION"
- {
- $$ = model.CheckOptionLocal
- }
- /******************************************************************
- * Do statement
- * See https://dev.mysql.com/doc/refman/5.7/en/do.html
- ******************************************************************/
- DoStmt:
- "DO" ExpressionList
- {
- $$ = &ast.DoStmt{
- Exprs: $2.([]ast.ExprNode),
- }
- }
- /*******************************************************************
- *
- * Delete Statement
- *
- *******************************************************************/
- DeleteWithoutUsingStmt:
- "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional "FROM" TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt WhereClauseOptional OrderByOptional LimitClause
- {
- // Single Table
- tn := $7.(*ast.TableName)
- tn.IndexHints = $10.([]*ast.IndexHint)
- tn.PartitionNames = $8.([]model.CIStr)
- join := &ast.Join{Left: &ast.TableSource{Source: tn, AsName: $9.(model.CIStr)}, Right: nil}
- x := &ast.DeleteStmt{
- TableRefs: &ast.TableRefsClause{TableRefs: join},
- Priority: $3.(mysql.PriorityEnum),
- Quick: $4.(bool),
- IgnoreErr: $5.(bool),
- }
- if $2 != nil {
- x.TableHints = $2.([]*ast.TableOptimizerHint)
- }
- if $11 != nil {
- x.Where = $11.(ast.ExprNode)
- }
- if $12 != nil {
- x.Order = $12.(*ast.OrderByClause)
- }
- if $13 != nil {
- x.Limit = $13.(*ast.Limit)
- }
- $$ = x
- }
- | "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional TableAliasRefList "FROM" TableRefs WhereClauseOptional
- {
- // Multiple Table
- x := &ast.DeleteStmt{
- Priority: $3.(mysql.PriorityEnum),
- Quick: $4.(bool),
- IgnoreErr: $5.(bool),
- IsMultiTable: true,
- BeforeFrom: true,
- Tables: &ast.DeleteTableList{Tables: $6.([]*ast.TableName)},
- TableRefs: &ast.TableRefsClause{TableRefs: $8.(*ast.Join)},
- }
- if $2 != nil {
- x.TableHints = $2.([]*ast.TableOptimizerHint)
- }
- if $9 != nil {
- x.Where = $9.(ast.ExprNode)
- }
- $$ = x
- }
- DeleteWithUsingStmt:
- "DELETE" TableOptimizerHintsOpt PriorityOpt QuickOptional IgnoreOptional "FROM" TableAliasRefList "USING" TableRefs WhereClauseOptional
- {
- // Multiple Table
- x := &ast.DeleteStmt{
- Priority: $3.(mysql.PriorityEnum),
- Quick: $4.(bool),
- IgnoreErr: $5.(bool),
- IsMultiTable: true,
- Tables: &ast.DeleteTableList{Tables: $7.([]*ast.TableName)},
- TableRefs: &ast.TableRefsClause{TableRefs: $9.(*ast.Join)},
- }
- if $2 != nil {
- x.TableHints = $2.([]*ast.TableOptimizerHint)
- }
- if $10 != nil {
- x.Where = $10.(ast.ExprNode)
- }
- $$ = x
- }
- DeleteFromStmt:
- DeleteWithoutUsingStmt
- | DeleteWithUsingStmt
- | WithClause DeleteWithoutUsingStmt
- {
- d := $2.(*ast.DeleteStmt)
- d.With = $1.(*ast.WithClause)
- $$ = d
- }
- | WithClause DeleteWithUsingStmt
- {
- d := $2.(*ast.DeleteStmt)
- d.With = $1.(*ast.WithClause)
- $$ = d
- }
- DatabaseSym:
- "DATABASE"
- DropDatabaseStmt:
- "DROP" DatabaseSym IfExists DBName
- {
- $$ = &ast.DropDatabaseStmt{IfExists: $3.(bool), Name: $4}
- }
- /******************************************************************
- * Drop Index Statement
- * See https://dev.mysql.com/doc/refman/8.0/en/drop-index.html
- *
- * DROP INDEX index_name ON tbl_name
- * [algorithm_option | lock_option] ...
- *
- * algorithm_option:
- * ALGORITHM [=] {DEFAULT|INPLACE|COPY}
- *
- * lock_option:
- * LOCK [=] {DEFAULT|NONE|SHARED|EXCLUSIVE}
- ******************************************************************/
- DropIndexStmt:
- "DROP" "INDEX" IfExists Identifier "ON" TableName IndexLockAndAlgorithmOpt
- {
- var indexLockAndAlgorithm *ast.IndexLockAndAlgorithm
- if $7 != nil {
- indexLockAndAlgorithm = $7.(*ast.IndexLockAndAlgorithm)
- if indexLockAndAlgorithm.LockTp == ast.LockTypeDefault && indexLockAndAlgorithm.AlgorithmTp == ast.AlgorithmTypeDefault {
- indexLockAndAlgorithm = nil
- }
- }
- $$ = &ast.DropIndexStmt{IfExists: $3.(bool), IndexName: $4, Table: $6.(*ast.TableName), LockAlg: indexLockAndAlgorithm}
- }
- DropTableStmt:
- "DROP" OptTemporary TableOrTables IfExists TableNameList RestrictOrCascadeOpt
- {
- $$ = &ast.DropTableStmt{IfExists: $4.(bool), Tables: $5.([]*ast.TableName), IsView: false, IsTemporary: $2.(bool)}
- }
- OptTemporary:
- /* empty */
- {
- $$ = false
- }
- | "TEMPORARY"
- {
- $$ = true
- yylex.AppendError(yylex.Errorf("TiDB doesn't support TEMPORARY TABLE, TEMPORARY will be parsed but ignored."))
- parser.lastErrorAsWarn()
- }
- DropViewStmt:
- "DROP" "VIEW" TableNameList RestrictOrCascadeOpt
- {
- $$ = &ast.DropTableStmt{Tables: $3.([]*ast.TableName), IsView: true}
- }
- | "DROP" "VIEW" "IF" "EXISTS" TableNameList RestrictOrCascadeOpt
- {
- $$ = &ast.DropTableStmt{IfExists: true, Tables: $5.([]*ast.TableName), IsView: true}
- }
- DropUserStmt:
- "DROP" "USER" UsernameList
- {
- $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: false, UserList: $3.([]*auth.UserIdentity)}
- }
- | "DROP" "USER" "IF" "EXISTS" UsernameList
- {
- $$ = &ast.DropUserStmt{IsDropRole: false, IfExists: true, UserList: $5.([]*auth.UserIdentity)}
- }
- DropRoleStmt:
- "DROP" "ROLE" RolenameList
- {
- tmp := make([]*auth.UserIdentity, 0, 10)
- roleList := $3.([]*auth.RoleIdentity)
- for _, r := range roleList {
- tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname})
- }
- $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: false, UserList: tmp}
- }
- | "DROP" "ROLE" "IF" "EXISTS" RolenameList
- {
- tmp := make([]*auth.UserIdentity, 0, 10)
- roleList := $5.([]*auth.RoleIdentity)
- for _, r := range roleList {
- tmp = append(tmp, &auth.UserIdentity{Username: r.Username, Hostname: r.Hostname})
- }
- $$ = &ast.DropUserStmt{IsDropRole: true, IfExists: true, UserList: tmp}
- }
- DropStatsStmt:
- "DROP" "STATS" TableName
- {
- $$ = &ast.DropStatsStmt{Table: $3.(*ast.TableName)}
- }
- | "DROP" "STATS" TableName "PARTITION" PartitionNameList
- {
- $$ = &ast.DropStatsStmt{
- Table: $3.(*ast.TableName),
- PartitionNames: $5.([]model.CIStr),
- }
- }
- | "DROP" "STATS" TableName "GLOBAL"
- {
- $$ = &ast.DropStatsStmt{
- Table: $3.(*ast.TableName),
- IsGlobalStats: true,
- }
- }
- RestrictOrCascadeOpt:
- {}
- | "RESTRICT"
- | "CASCADE"
- TableOrTables:
- "TABLE"
- | "TABLES"
- EqOpt:
- {}
- | eq
- EmptyStmt:
- /* EMPTY */
- {
- $$ = nil
- }
- TraceStmt:
- "TRACE" TraceableStmt
- {
- $$ = &ast.TraceStmt{
- Stmt: $2,
- Format: "row",
- }
- startOffset := parser.startOffset(&yyS[yypt])
- $2.SetText(string(parser.src[startOffset:]))
- }
- | "TRACE" "FORMAT" "=" stringLit TraceableStmt
- {
- $$ = &ast.TraceStmt{
- Stmt: $5,
- Format: $4,
- }
- startOffset := parser.startOffset(&yyS[yypt])
- $5.SetText(string(parser.src[startOffset:]))
- }
- ExplainSym:
- "EXPLAIN"
- | "DESCRIBE"
- | "DESC"
- ExplainStmt:
- ExplainSym TableName
- {
- $$ = &ast.ExplainStmt{
- Stmt: &ast.ShowStmt{
- Tp: ast.ShowColumns,
- Table: $2.(*ast.TableName),
- },
- }
- }
- | ExplainSym TableName ColumnName
- {
- $$ = &ast.ExplainStmt{
- Stmt: &ast.ShowStmt{
- Tp: ast.ShowColumns,
- Table: $2.(*ast.TableName),
- Column: $3.(*ast.ColumnName),
- },
- }
- }
- | ExplainSym ExplainableStmt
- {
- $$ = &ast.ExplainStmt{
- Stmt: $2,
- Format: "row",
- }
- }
- | ExplainSym "FOR" "CONNECTION" NUM
- {
- $$ = &ast.ExplainForStmt{
- Format: "row",
- ConnectionID: getUint64FromNUM($4),
- }
- }
- | ExplainSym "FORMAT" "=" stringLit "FOR" "CONNECTION" NUM
- {
- $$ = &ast.ExplainForStmt{
- Format: $4,
- ConnectionID: getUint64FromNUM($7),
- }
- }
- | ExplainSym "FORMAT" "=" stringLit ExplainableStmt
- {
- $$ = &ast.ExplainStmt{
- Stmt: $5,
- Format: $4,
- }
- }
- | ExplainSym "FORMAT" "=" ExplainFormatType "FOR" "CONNECTION" NUM
- {
- $$ = &ast.ExplainForStmt{
- Format: $4,
- ConnectionID: getUint64FromNUM($7),
- }
- }
- | ExplainSym "FORMAT" "=" ExplainFormatType ExplainableStmt
- {
- $$ = &ast.ExplainStmt{
- Stmt: $5,
- Format: $4,
- }
- }
- | ExplainSym "ANALYZE" ExplainableStmt
- {
- $$ = &ast.ExplainStmt{
- Stmt: $3,
- Format: "row",
- Analyze: true,
- }
- }
- ExplainFormatType:
- "TRADITIONAL"
- {
- $$ = "row"
- }
- | "JSON"
- {
- $$ = "json"
- }
- /*******************************************************************
- * Backup / restore / import statements
- *
- * BACKUP DATABASE [ * | db1, db2, db3 ] TO 'scheme://location' [ options... ]
- * BACKUP TABLE [ db1.tbl1, db2.tbl2 ] TO 'scheme://location' [ options... ]
- * RESTORE DATABASE [ * | db1, db2, db3 ] FROM 'scheme://location' [ options... ]
- * RESTORE TABLE [ db1.tbl1, db2.tbl2 ] FROM 'scheme://location' [ options... ]
- */
- BRIEStmt:
- "BACKUP" BRIETables "TO" stringLit BRIEOptions
- {
- stmt := $2.(*ast.BRIEStmt)
- stmt.Kind = ast.BRIEKindBackup
- stmt.Storage = $4
- stmt.Options = $5.([]*ast.BRIEOption)
- $$ = stmt
- }
- | "RESTORE" BRIETables "FROM" stringLit BRIEOptions
- {
- stmt := $2.(*ast.BRIEStmt)
- stmt.Kind = ast.BRIEKindRestore
- stmt.Storage = $4
- stmt.Options = $5.([]*ast.BRIEOption)
- $$ = stmt
- }
- BRIETables:
- DatabaseSym '*'
- {
- $$ = &ast.BRIEStmt{}
- }
- | DatabaseSym DBNameList
- {
- $$ = &ast.BRIEStmt{Schemas: $2.([]string)}
- }
- | "TABLE" TableNameList
- {
- $$ = &ast.BRIEStmt{Tables: $2.([]*ast.TableName)}
- }
- DBNameList:
- DBName
- {
- $$ = []string{$1}
- }
- | DBNameList ',' DBName
- {
- $$ = append($1.([]string), $3)
- }
- BRIEOptions:
- %prec empty
- {
- $$ = []*ast.BRIEOption{}
- }
- | BRIEOptions BRIEOption
- {
- $$ = append($1.([]*ast.BRIEOption), $2.(*ast.BRIEOption))
- }
- BRIEIntegerOptionName:
- "CONCURRENCY"
- {
- $$ = ast.BRIEOptionConcurrency
- }
- | "RESUME"
- {
- $$ = ast.BRIEOptionResume
- }
- BRIEBooleanOptionName:
- "SEND_CREDENTIALS_TO_TIKV"
- {
- $$ = ast.BRIEOptionSendCreds
- }
- | "ONLINE"
- {
- $$ = ast.BRIEOptionOnline
- }
- | "CHECKPOINT"
- {
- $$ = ast.BRIEOptionCheckpoint
- }
- | "SKIP_SCHEMA_FILES"
- {
- $$ = ast.BRIEOptionSkipSchemaFiles
- }
- | "STRICT_FORMAT"
- {
- $$ = ast.BRIEOptionStrictFormat
- }
- | "CSV_NOT_NULL"
- {
- $$ = ast.BRIEOptionCSVNotNull
- }
- | "CSV_BACKSLASH_ESCAPE"
- {
- $$ = ast.BRIEOptionCSVBackslashEscape
- }
- | "CSV_TRIM_LAST_SEPARATORS"
- {
- $$ = ast.BRIEOptionCSVTrimLastSeparators
- }
- BRIEStringOptionName:
- "TIKV_IMPORTER"
- {
- $$ = ast.BRIEOptionTiKVImporter
- }
- | "CSV_SEPARATOR"
- {
- $$ = ast.BRIEOptionCSVSeparator
- }
- | "CSV_DELIMITER"
- {
- $$ = ast.BRIEOptionCSVDelimiter
- }
- | "CSV_NULL"
- {
- $$ = ast.BRIEOptionCSVNull
- }
- BRIEKeywordOptionName:
- "BACKEND"
- {
- $$ = ast.BRIEOptionBackend
- }
- | "ON_DUPLICATE"
- {
- $$ = ast.BRIEOptionOnDuplicate
- }
- | "ON" "DUPLICATE"
- {
- $$ = ast.BRIEOptionOnDuplicate
- }
- BRIEOption:
- BRIEIntegerOptionName EqOpt LengthNum
- {
- $$ = &ast.BRIEOption{
- Tp: $1.(ast.BRIEOptionType),
- UintValue: $3.(uint64),
- }
- }
- | BRIEBooleanOptionName EqOpt Boolean
- {
- value := uint64(0)
- if $3.(bool) {
- value = 1
- }
- $$ = &ast.BRIEOption{
- Tp: $1.(ast.BRIEOptionType),
- UintValue: value,
- }
- }
- | BRIEStringOptionName EqOpt stringLit
- {
- $$ = &ast.BRIEOption{
- Tp: $1.(ast.BRIEOptionType),
- StrValue: $3,
- }
- }
- | BRIEKeywordOptionName EqOpt StringNameOrBRIEOptionKeyword
- {
- $$ = &ast.BRIEOption{
- Tp: $1.(ast.BRIEOptionType),
- StrValue: strings.ToLower($3),
- }
- }
- | "SNAPSHOT" EqOpt LengthNum TimestampUnit "AGO"
- {
- unit, err := $4.(ast.TimeUnitType).Duration()
- if err != nil {
- yylex.AppendError(err)
- return 1
- }
- // TODO: check overflow?
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionBackupTimeAgo,
- UintValue: $3.(uint64) * uint64(unit),
- }
- }
- | "SNAPSHOT" EqOpt stringLit
- // not including this into BRIEStringOptionName to avoid shift/reduce conflict
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionBackupTS,
- StrValue: $3,
- }
- }
- | "SNAPSHOT" EqOpt LengthNum
- // not including this into BRIEIntegerOptionName to avoid shift/reduce conflict
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionBackupTSO,
- UintValue: $3.(uint64),
- }
- }
- | "LAST_BACKUP" EqOpt stringLit
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionLastBackupTS,
- StrValue: $3,
- }
- }
- | "LAST_BACKUP" EqOpt LengthNum
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionLastBackupTSO,
- UintValue: $3.(uint64),
- }
- }
- | "RATE_LIMIT" EqOpt LengthNum "MB" '/' "SECOND"
- {
- // TODO: check overflow?
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionRateLimit,
- UintValue: $3.(uint64) * 1048576,
- }
- }
- | "CSV_HEADER" EqOpt FieldsOrColumns
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionCSVHeader,
- UintValue: ast.BRIECSVHeaderIsColumns,
- }
- }
- | "CSV_HEADER" EqOpt LengthNum
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionCSVHeader,
- UintValue: $3.(uint64),
- }
- }
- | "CHECKSUM" EqOpt Boolean
- {
- value := uint64(0)
- if $3.(bool) {
- value = 1
- }
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionChecksum,
- UintValue: value,
- }
- }
- | "CHECKSUM" EqOpt OptionLevel
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionChecksum,
- UintValue: uint64($3.(ast.BRIEOptionLevel)),
- }
- }
- | "ANALYZE" EqOpt Boolean
- {
- value := uint64(0)
- if $3.(bool) {
- value = 1
- }
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionAnalyze,
- UintValue: value,
- }
- }
- | "ANALYZE" EqOpt OptionLevel
- {
- $$ = &ast.BRIEOption{
- Tp: ast.BRIEOptionAnalyze,
- UintValue: uint64($3.(ast.BRIEOptionLevel)),
- }
- }
- LengthNum:
- NUM
- {
- $$ = getUint64FromNUM($1)
- }
- Int64Num:
- NUM
- {
- v, rangeErrMsg := getInt64FromNUM($1)
- if len(rangeErrMsg) != 0 {
- yylex.AppendError(yylex.Errorf(rangeErrMsg))
- return 1
- }
- $$ = v
- }
- NUM:
- intLit
- Boolean:
- NUM
- {
- $$ = $1.(int64) != 0
- }
- | "FALSE"
- {
- $$ = false
- }
- | "TRUE"
- {
- $$ = true
- }
- OptionLevel:
- "OFF"
- {
- $$ = ast.BRIEOptionLevelOff
- }
- | "OPTIONAL"
- {
- $$ = ast.BRIEOptionLevelOptional
- }
- | "REQUIRED"
- {
- $$ = ast.BRIEOptionLevelRequired
- }
- PurgeImportStmt:
- "PURGE" "IMPORT" NUM
- {
- $$ = &ast.PurgeImportStmt{TaskID: getUint64FromNUM($3)}
- }
- /*******************************************************************
- * import statements
- *
- * CREATE IMPORT [IF NOT EXISTS] import_name
- * FROM data_location [REPLACE | SKIP {ALL | CONSTRAINT | DUPLICATE | STRICT}]
- * [options_list]
- * STOP IMPORT [IF RUNNING] import_name
- * RESUME IMPORT [IF NOT RUNNING] import_name
- * ALTER IMPORT import_name
- * [REPLACE | SKIP {ALL | CONSTRAINT | DUPLICATE | STRICT}]
- * [options_list]
- * [TRUNCATE
- * {ALL | ERRORS} [TABLE table_name [, table_name] ...]
- * ]
- * DROP IMPORT [IF EXISTS] import_name
- * SHOW IMPORT import_name [ERRORS] [TABLE table_name [, table_name] ...]
- */
- CreateImportStmt:
- "CREATE" "IMPORT" IfNotExists Identifier "FROM" stringLit ErrorHandling BRIEOptions
- {
- $$ = &ast.CreateImportStmt{
- IfNotExists: $3.(bool),
- Name: $4,
- Storage: $6,
- ErrorHandling: $7.(ast.ErrorHandlingOption),
- Options: $8.([]*ast.BRIEOption),
- }
- }
- StopImportStmt:
- "STOP" "IMPORT" IfRunning Identifier
- {
- $$ = &ast.StopImportStmt{
- IfRunning: $3.(bool),
- Name: $4,
- }
- }
- ResumeImportStmt:
- "RESUME" "IMPORT" IfNotRunning Identifier
- {
- $$ = &ast.ResumeImportStmt{
- IfNotRunning: $3.(bool),
- Name: $4,
- }
- }
- AlterImportStmt:
- "ALTER" "IMPORT" Identifier ErrorHandling BRIEOptions ImportTruncate
- {
- s := &ast.AlterImportStmt{
- Name: $3,
- ErrorHandling: $4.(ast.ErrorHandlingOption),
- Options: $5.([]*ast.BRIEOption),
- }
- if $6 != nil {
- s.Truncate = $6.(*ast.ImportTruncate)
- }
- $$ = s
- }
- DropImportStmt:
- "DROP" "IMPORT" IfExists Identifier
- {
- $$ = &ast.DropImportStmt{
- IfExists: $3.(bool),
- Name: $4,
- }
- }
- ShowImportStmt:
- "SHOW" "IMPORT" Identifier OptErrors TableNameListOpt2
- {
- $$ = &ast.ShowImportStmt{
- Name: $3,
- ErrorsOnly: $4.(bool),
- TableNames: $5.([]*ast.TableName),
- }
- }
- IfRunning:
- {
- $$ = false
- }
- | "IF" "RUNNING"
- {
- $$ = true
- }
- IfNotRunning:
- {
- $$ = false
- }
- | "IF" NotSym "RUNNING"
- {
- $$ = true
- }
- OptErrors:
- {
- $$ = false
- }
- | "ERRORS"
- {
- $$ = true
- }
- ErrorHandling:
- {
- $$ = ast.ErrorHandleError
- }
- | "REPLACE"
- {
- $$ = ast.ErrorHandleReplace
- }
- | "SKIP" "ALL"
- {
- $$ = ast.ErrorHandleSkipAll
- }
- | "SKIP" "CONSTRAINT"
- {
- $$ = ast.ErrorHandleSkipConstraint
- }
- | "SKIP" "DUPLICATE"
- {
- $$ = ast.ErrorHandleSkipDuplicate
- }
- | "SKIP" "STRICT"
- {
- $$ = ast.ErrorHandleSkipStrict
- }
- ImportTruncate:
- {
- $$ = nil
- }
- | "TRUNCATE" "ALL" TableNameListOpt2
- {
- $$ = &ast.ImportTruncate{
- IsErrorsOnly: false,
- TableNames: $3.([]*ast.TableName),
- }
- }
- | "TRUNCATE" "ERRORS" TableNameListOpt2
- {
- $$ = &ast.ImportTruncate{
- IsErrorsOnly: true,
- TableNames: $3.([]*ast.TableName),
- }
- }
- Expression:
- singleAtIdentifier assignmentEq Expression %prec assignmentEq
- {
- v := $1
- v = strings.TrimPrefix(v, "@")
- $$ = &ast.VariableExpr{
- Name: v,
- IsGlobal: false,
- IsSystem: false,
- Value: $3,
- }
- }
- | Expression logOr Expression %prec pipes
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.LogicOr, L: $1, R: $3}
- }
- | Expression "XOR" Expression %prec xor
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.LogicXor, L: $1, R: $3}
- }
- | Expression logAnd Expression %prec andand
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.LogicAnd, L: $1, R: $3}
- }
- | "NOT" Expression %prec not
- {
- expr, ok := $2.(*ast.ExistsSubqueryExpr)
- if ok {
- expr.Not = true
- $$ = $2
- } else {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Not, V: $2}
- }
- }
- | "MATCH" '(' ColumnNameList ')' "AGAINST" '(' BitExpr FulltextSearchModifierOpt ')'
- {
- $$ = &ast.MatchAgainst{
- ColumnNames: $3.([]*ast.ColumnName),
- Against: $7,
- Modifier: ast.FulltextSearchModifier($8.(int)),
- }
- }
- | BoolPri IsOrNotOp trueKwd %prec is
- {
- $$ = &ast.IsTruthExpr{Expr: $1, Not: !$2.(bool), True: int64(1)}
- }
- | BoolPri IsOrNotOp falseKwd %prec is
- {
- $$ = &ast.IsTruthExpr{Expr: $1, Not: !$2.(bool), True: int64(0)}
- }
- | BoolPri IsOrNotOp "UNKNOWN" %prec is
- {
- /* https://dev.mysql.com/doc/refman/5.7/en/comparison-operators.html#operator_is */
- $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)}
- }
- | BoolPri
- MaxValueOrExpression:
- "MAXVALUE"
- {
- $$ = &ast.MaxValueExpr{}
- }
- | BitExpr
- FulltextSearchModifierOpt:
- /* empty */
- {
- $$ = ast.FulltextSearchModifierNaturalLanguageMode
- }
- | "IN" "NATURAL" "LANGUAGE" "MODE"
- {
- $$ = ast.FulltextSearchModifierNaturalLanguageMode
- }
- | "IN" "NATURAL" "LANGUAGE" "MODE" "WITH" "QUERY" "EXPANSION"
- {
- $$ = ast.FulltextSearchModifierNaturalLanguageMode | ast.FulltextSearchModifierWithQueryExpansion
- }
- | "IN" "BOOLEAN" "MODE"
- {
- $$ = ast.FulltextSearchModifierBooleanMode
- }
- | "WITH" "QUERY" "EXPANSION"
- {
- $$ = ast.FulltextSearchModifierWithQueryExpansion
- }
- logOr:
- pipesAsOr
- | "OR"
- logAnd:
- "&&"
- | "AND"
- ExpressionList:
- Expression
- {
- $$ = []ast.ExprNode{$1}
- }
- | ExpressionList ',' Expression
- {
- $$ = append($1.([]ast.ExprNode), $3)
- }
- MaxValueOrExpressionList:
- MaxValueOrExpression
- {
- $$ = []ast.ExprNode{$1}
- }
- | MaxValueOrExpressionList ',' MaxValueOrExpression
- {
- $$ = append($1.([]ast.ExprNode), $3)
- }
- ExpressionListOpt:
- {
- $$ = []ast.ExprNode{}
- }
- | ExpressionList
- FuncDatetimePrecListOpt:
- {
- $$ = []ast.ExprNode{}
- }
- | FuncDatetimePrecList
- FuncDatetimePrecList:
- intLit
- {
- expr := ast.NewValueExpr($1, parser.charset, parser.collation)
- $$ = []ast.ExprNode{expr}
- }
- BoolPri:
- BoolPri IsOrNotOp "NULL" %prec is
- {
- $$ = &ast.IsNullExpr{Expr: $1, Not: !$2.(bool)}
- }
- | BoolPri CompareOp PredicateExpr %prec eq
- {
- $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: $3}
- }
- | BoolPri CompareOp AnyOrAll SubSelect %prec eq
- {
- sq := $4.(*ast.SubqueryExpr)
- sq.MultiRows = true
- $$ = &ast.CompareSubqueryExpr{Op: $2.(opcode.Op), L: $1, R: sq, All: $3.(bool)}
- }
- | BoolPri CompareOp singleAtIdentifier assignmentEq PredicateExpr %prec assignmentEq
- {
- v := $3
- v = strings.TrimPrefix(v, "@")
- variable := &ast.VariableExpr{
- Name: v,
- IsGlobal: false,
- IsSystem: false,
- Value: $5,
- }
- $$ = &ast.BinaryOperationExpr{Op: $2.(opcode.Op), L: $1, R: variable}
- }
- | PredicateExpr
- CompareOp:
- ">="
- {
- $$ = opcode.GE
- }
- | '>'
- {
- $$ = opcode.GT
- }
- | "<="
- {
- $$ = opcode.LE
- }
- | '<'
- {
- $$ = opcode.LT
- }
- | "!="
- {
- $$ = opcode.NE
- }
- | "<>"
- {
- $$ = opcode.NE
- }
- | "="
- {
- $$ = opcode.EQ
- }
- | "<=>"
- {
- $$ = opcode.NullEQ
- }
- BetweenOrNotOp:
- "BETWEEN"
- {
- $$ = true
- }
- | NotSym "BETWEEN"
- {
- $$ = false
- }
- IsOrNotOp:
- "IS"
- {
- $$ = true
- }
- | "IS" NotSym
- {
- $$ = false
- }
- InOrNotOp:
- "IN"
- {
- $$ = true
- }
- | NotSym "IN"
- {
- $$ = false
- }
- LikeOrNotOp:
- "LIKE"
- {
- $$ = true
- }
- | NotSym "LIKE"
- {
- $$ = false
- }
- RegexpOrNotOp:
- RegexpSym
- {
- $$ = true
- }
- | NotSym RegexpSym
- {
- $$ = false
- }
- AnyOrAll:
- "ANY"
- {
- $$ = false
- }
- | "SOME"
- {
- $$ = false
- }
- | "ALL"
- {
- $$ = true
- }
- PredicateExpr:
- BitExpr InOrNotOp '(' ExpressionList ')'
- {
- $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), List: $4.([]ast.ExprNode)}
- }
- | BitExpr InOrNotOp SubSelect
- {
- sq := $3.(*ast.SubqueryExpr)
- sq.MultiRows = true
- $$ = &ast.PatternInExpr{Expr: $1, Not: !$2.(bool), Sel: sq}
- }
- | BitExpr BetweenOrNotOp BitExpr "AND" PredicateExpr
- {
- $$ = &ast.BetweenExpr{
- Expr: $1,
- Left: $3,
- Right: $5,
- Not: !$2.(bool),
- }
- }
- | BitExpr LikeOrNotOp SimpleExpr LikeEscapeOpt
- {
- escape := $4
- if len(escape) > 1 {
- yylex.AppendError(ErrWrongArguments.GenWithStackByArgs("ESCAPE"))
- return 1
- } else if len(escape) == 0 {
- escape = "\\"
- }
- $$ = &ast.PatternLikeExpr{
- Expr: $1,
- Pattern: $3,
- Not: !$2.(bool),
- Escape: escape[0],
- }
- }
- | BitExpr RegexpOrNotOp SimpleExpr
- {
- $$ = &ast.PatternRegexpExpr{Expr: $1, Pattern: $3, Not: !$2.(bool)}
- }
- | BitExpr
- RegexpSym:
- "REGEXP"
- | "RLIKE"
- LikeEscapeOpt:
- %prec empty
- {
- $$ = "\\"
- }
- | "ESCAPE" stringLit
- {
- $$ = $2
- }
- Field:
- '*'
- {
- $$ = &ast.SelectField{WildCard: &ast.WildCardField{}}
- }
- | Identifier '.' '*'
- {
- wildCard := &ast.WildCardField{Table: model.NewCIStr($1)}
- $$ = &ast.SelectField{WildCard: wildCard}
- }
- | Identifier '.' Identifier '.' '*'
- {
- wildCard := &ast.WildCardField{Schema: model.NewCIStr($1), Table: model.NewCIStr($3)}
- $$ = &ast.SelectField{WildCard: wildCard}
- }
- | Expression FieldAsNameOpt
- {
- expr := $1
- asName := $2
- $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)}
- }
- | '{' Identifier Expression '}' FieldAsNameOpt
- {
- /*
- * ODBC escape syntax.
- * See https://dev.mysql.com/doc/refman/5.7/en/expressions.html
- */
- expr := $3
- asName := $5
- $$ = &ast.SelectField{Expr: expr, AsName: model.NewCIStr(asName)}
- }
- FieldAsNameOpt:
- /* EMPTY */
- {
- $$ = ""
- }
- | FieldAsName
- FieldAsName:
- Identifier
- | "AS" Identifier
- {
- $$ = $2
- }
- | stringLit
- | "AS" stringLit
- {
- $$ = $2
- }
- FieldList:
- Field
- {
- field := $1.(*ast.SelectField)
- field.Offset = parser.startOffset(&yyS[yypt])
- $$ = []*ast.SelectField{field}
- }
- | FieldList ',' Field
- {
- fl := $1.([]*ast.SelectField)
- last := fl[len(fl)-1]
- if last.Expr != nil && last.AsName.O == "" {
- lastEnd := parser.endOffset(&yyS[yypt-1])
- last.SetText(parser.src[last.Offset:lastEnd])
- }
- newField := $3.(*ast.SelectField)
- newField.Offset = parser.startOffset(&yyS[yypt])
- $$ = append(fl, newField)
- }
- GroupByClause:
- "GROUP" "BY" ByList
- {
- $$ = &ast.GroupByClause{Items: $3.([]*ast.ByItem)}
- }
- HavingClause:
- {
- $$ = nil
- }
- | "HAVING" Expression
- {
- $$ = &ast.HavingClause{Expr: $2}
- }
- IfExists:
- {
- $$ = false
- }
- | "IF" "EXISTS"
- {
- $$ = true
- }
- IfNotExists:
- {
- $$ = false
- }
- | "IF" NotSym "EXISTS"
- {
- $$ = true
- }
- IgnoreOptional:
- {
- $$ = false
- }
- | "IGNORE"
- {
- $$ = true
- }
- IndexName:
- {
- $$ = &ast.NullString{
- String: "",
- Empty: false,
- }
- }
- | Identifier
- {
- $$ = &ast.NullString{
- String: $1,
- Empty: len($1) == 0,
- }
- }
- IndexOptionList:
- {
- $$ = nil
- }
- | IndexOptionList IndexOption
- {
- // Merge the options
- if $1 == nil {
- $$ = $2
- } else {
- opt1 := $1.(*ast.IndexOption)
- opt2 := $2.(*ast.IndexOption)
- if len(opt2.Comment) > 0 {
- opt1.Comment = opt2.Comment
- } else if opt2.Tp != 0 {
- opt1.Tp = opt2.Tp
- } else if opt2.KeyBlockSize > 0 {
- opt1.KeyBlockSize = opt2.KeyBlockSize
- } else if len(opt2.ParserName.O) > 0 {
- opt1.ParserName = opt2.ParserName
- } else if opt2.Visibility != ast.IndexVisibilityDefault {
- opt1.Visibility = opt2.Visibility
- } else if opt2.PrimaryKeyTp != model.PrimaryKeyTypeDefault {
- opt1.PrimaryKeyTp = opt2.PrimaryKeyTp
- }
- $$ = opt1
- }
- }
- IndexOption:
- "KEY_BLOCK_SIZE" EqOpt LengthNum
- {
- $$ = &ast.IndexOption{
- KeyBlockSize: $3.(uint64),
- }
- }
- | IndexType
- {
- $$ = &ast.IndexOption{
- Tp: $1.(model.IndexType),
- }
- }
- | "WITH" "PARSER" Identifier
- {
- $$ = &ast.IndexOption{
- ParserName: model.NewCIStr($3),
- }
- yylex.AppendError(yylex.Errorf("The WITH PARASER clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "COMMENT" stringLit
- {
- $$ = &ast.IndexOption{
- Comment: $2,
- }
- }
- | IndexInvisible
- {
- $$ = &ast.IndexOption{
- Visibility: $1.(ast.IndexVisibility),
- }
- }
- | WithClustered
- {
- $$ = &ast.IndexOption{
- PrimaryKeyTp: $1.(model.PrimaryKeyType),
- }
- }
- /*
- See: https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L7179
- The syntax for defining an index is:
- ... INDEX [index_name] [USING|TYPE] <index_type> ...
- The problem is that whereas USING is a reserved word, TYPE is not. We can
- still handle it if an index name is supplied, i.e.:
- ... INDEX type TYPE <index_type> ...
- here the index's name is unmbiguously 'type', but for this:
- ... INDEX TYPE <index_type> ...
- it's impossible to know what this actually mean - is 'type' the name or the
- type? For this reason we accept the TYPE syntax only if a name is supplied.
- */
- IndexNameAndTypeOpt:
- IndexName
- {
- $$ = []interface{}{$1, nil}
- }
- | IndexName "USING" IndexTypeName
- {
- $$ = []interface{}{$1, $3}
- }
- | Identifier "TYPE" IndexTypeName
- {
- $$ = []interface{}{&ast.NullString{String: $1, Empty: len($1) == 0}, $3}
- }
- IndexTypeOpt:
- {
- $$ = nil
- }
- | IndexType
- IndexType:
- "USING" IndexTypeName
- {
- $$ = $2
- }
- | "TYPE" IndexTypeName
- {
- $$ = $2
- }
- IndexTypeName:
- "BTREE"
- {
- $$ = model.IndexTypeBtree
- }
- | "HASH"
- {
- $$ = model.IndexTypeHash
- }
- | "RTREE"
- {
- $$ = model.IndexTypeRtree
- }
- IndexInvisible:
- "VISIBLE"
- {
- $$ = ast.IndexVisibilityVisible
- }
- | "INVISIBLE"
- {
- $$ = ast.IndexVisibilityInvisible
- }
- /**********************************Identifier********************************************/
- Identifier:
- identifier
- | UnReservedKeyword
- | NotKeywordToken
- | TiDBKeyword
- UnReservedKeyword:
- "ACTION"
- | "ADVISE"
- | "ASCII"
- | "AUTO_ID_CACHE"
- | "AUTO_INCREMENT"
- | "AFTER"
- | "ALWAYS"
- | "AVG"
- | "BEGIN"
- | "BIT"
- | "BOOL"
- | "BOOLEAN"
- | "BTREE"
- | "BYTE"
- | "CAPTURE"
- | "CAUSAL"
- | "CLEANUP"
- | "CHAIN"
- | "CHARSET"
- | "COLUMNS"
- | "CONFIG"
- | "SAN"
- | "COMMIT"
- | "COMPACT"
- | "COMPRESSED"
- | "CONSISTENCY"
- | "CONSISTENT"
- | "CURRENT"
- | "DATA"
- | "DATE" %prec lowerThanStringLitToken
- | "DATETIME"
- | "DAY"
- | "DEALLOCATE"
- | "DO"
- | "DUPLICATE"
- | "DYNAMIC"
- | "ENCRYPTION"
- | "END"
- | "ENFORCED"
- | "ENGINE"
- | "ENGINES"
- | "ENUM"
- | "ERROR"
- | "ERRORS"
- | "ESCAPE"
- | "EVOLVE"
- | "EXECUTE"
- | "EXTENDED"
- | "FIELDS"
- | "FILE"
- | "FIRST"
- | "FIXED"
- | "FLUSH"
- | "FOLLOWING"
- | "FORMAT"
- | "FULL"
- | "GENERAL"
- | "GLOBAL"
- | "HASH"
- | "HOUR"
- | "INSERT_METHOD"
- | "LESS"
- | "LOCAL"
- | "LAST"
- | "NAMES"
- | "NVARCHAR"
- | "OFFSET"
- | "PACK_KEYS"
- | "PARSER"
- | "PASSWORD" %prec lowerThanEq
- | "PREPARE"
- | "PRE_SPLIT_REGIONS"
- | "PROXY"
- | "QUICK"
- | "REBUILD"
- | "REDUNDANT"
- | "REORGANIZE"
- | "RESTART"
- | "ROLE"
- | "ROLLBACK"
- | "SESSION"
- | "SIGNED"
- | "SHARD_ROW_ID_BITS"
- | "SHUTDOWN"
- | "SNAPSHOT"
- | "START"
- | "STATUS"
- | "OPEN"
- | "SUBPARTITIONS"
- | "SUBPARTITION"
- | "TABLES"
- | "TABLESPACE"
- | "TEXT"
- | "THAN"
- | "TIME" %prec lowerThanStringLitToken
- | "TIMESTAMP" %prec lowerThanStringLitToken
- | "TRACE"
- | "TRANSACTION"
- | "TRUNCATE"
- | "UNBOUNDED"
- | "UNKNOWN"
- | "VALUE" %prec lowerThanValueKeyword
- | "WARNINGS"
- | "YEAR"
- | "MODE"
- | "WEEK"
- | "WEIGHT_STRING"
- | "ANY"
- | "SOME"
- | "USER"
- | "IDENTIFIED"
- | "COLLATION"
- | "COMMENT"
- | "AVG_ROW_LENGTH"
- | "CONNECTION"
- | "CHECKSUM"
- | "COMPRESSION"
- | "KEY_BLOCK_SIZE"
- | "MASTER"
- | "MAX_ROWS"
- | "MIN_ROWS"
- | "NATIONAL"
- | "NCHAR"
- | "ROW_FORMAT"
- | "QUARTER"
- | "GRANTS"
- | "TRIGGERS"
- | "DELAY_KEY_WRITE"
- | "ISOLATION"
- | "JSON"
- | "REPEATABLE"
- | "RESPECT"
- | "COMMITTED"
- | "UNCOMMITTED"
- | "ONLY"
- | "SERIAL"
- | "SERIALIZABLE"
- | "LEVEL"
- | "VARIABLES"
- | "SQL_CACHE"
- | "INDEXES"
- | "PROCESSLIST"
- | "SQL_NO_CACHE"
- | "DISABLE"
- | "ENABLE"
- | "REVERSE"
- | "PRIVILEGES"
- | "NO"
- | "BINLOG"
- | "FUNCTION"
- | "VIEW"
- | "BINDING"
- | "BINDINGS"
- | "MODIFY"
- | "EVENTS"
- | "PARTITIONS"
- | "NONE"
- | "NULLS"
- | "SUPER"
- | "EXCLUSIVE"
- | "STATS_PERSISTENT"
- | "STATS_AUTO_RECALC"
- | "ROW_COUNT"
- | "COALESCE"
- | "MONTH"
- | "PROCESS"
- | "PROFILE"
- | "PROFILES"
- | "MICROSECOND"
- | "MINUTE"
- | "PLUGINS"
- | "PRECEDING"
- | "QUERY"
- | "QUERIES"
- | "SECOND"
- | "SEPARATOR"
- | "SHARE"
- | "SHARED"
- | "SLOW"
- | "MAX_CONNECTIONS_PER_HOUR"
- | "MAX_QUERIES_PER_HOUR"
- | "MAX_UPDATES_PER_HOUR"
- | "MAX_USER_CONNECTIONS"
- | "REPLICATION"
- | "CLIENT"
- | "SLAVE"
- | "RELOAD"
- | "TEMPORARY"
- | "ROUTINE"
- | "EVENT"
- | "ALGORITHM"
- | "DEFINER"
- | "INVOKER"
- | "MERGE"
- | "TEMPTABLE"
- | "UNDEFINED"
- | "SECURITY"
- | "CASCADED"
- | "RECOVER"
- | "CIPHER"
- | "SUBJECT"
- | "ISSUER"
- | "X509"
- | "NEVER"
- | "EXPIRE"
- | "ACCOUNT"
- | "INCREMENTAL"
- | "CPU"
- | "MEMORY"
- | "BLOCK"
- | "IO"
- | "CONTEXT"
- | "SWITCHES"
- | "PAGE"
- | "FAULTS"
- | "IPC"
- | "SWAPS"
- | "SOURCE"
- | "TRADITIONAL"
- | "SQL_BUFFER_RESULT"
- | "DIRECTORY"
- | "HISTOGRAM"
- | "HISTORY"
- | "LIST"
- | "NODEGROUP"
- | "SYSTEM_TIME"
- | "PARTIAL"
- | "SIMPLE"
- | "REMOVE"
- | "PARTITIONING"
- | "STORAGE"
- | "DISK"
- | "STATS_SAMPLE_PAGES"
- | "SECONDARY_ENGINE"
- | "SECONDARY_LOAD"
- | "SECONDARY_UNLOAD"
- | "VALIDATION"
- | "WITHOUT"
- | "RTREE"
- | "EXCHANGE"
- | "COLUMN_FORMAT"
- | "REPAIR"
- | "IMPORT"
- | "IMPORTS"
- | "DISCARD"
- | "TABLE_CHECKSUM"
- | "UNICODE"
- | "AUTO_RANDOM"
- | "AUTO_RANDOM_BASE"
- | "SQL_TSI_DAY"
- | "SQL_TSI_HOUR"
- | "SQL_TSI_MINUTE"
- | "SQL_TSI_MONTH"
- | "SQL_TSI_QUARTER"
- | "SQL_TSI_SECOND"
- | "LANGUAGE"
- | "SQL_TSI_WEEK"
- | "SQL_TSI_YEAR"
- | "INVISIBLE"
- | "VISIBLE"
- | "TYPE"
- | "NOWAIT"
- | "INSTANCE"
- | "REPLICA"
- | "LOCATION"
- | "LABELS"
- | "LOGS"
- | "HOSTS"
- | "AGAINST"
- | "EXPANSION"
- | "INCREMENT"
- | "MINVALUE"
- | "NOMAXVALUE"
- | "NOMINVALUE"
- | "NOCACHE"
- | "CACHE"
- | "CYCLE"
- | "NOCYCLE"
- | "SEQUENCE"
- | "MAX_MINUTES"
- | "MAX_IDXNUM"
- | "PER_TABLE"
- | "PER_DB"
- | "NEXT"
- | "NEXTVAL"
- | "LASTVAL"
- | "SETVAL"
- | "AGO"
- | "BACKUP"
- | "BACKUPS"
- | "CONCURRENCY"
- | "MB"
- | "ONLINE"
- | "RATE_LIMIT"
- | "RESTORE"
- | "RESTORES"
- | "SEND_CREDENTIALS_TO_TIKV"
- | "LAST_BACKUP"
- | "CHECKPOINT"
- | "SKIP_SCHEMA_FILES"
- | "STRICT_FORMAT"
- | "BACKEND"
- | "CSV_BACKSLASH_ESCAPE"
- | "CSV_NOT_NULL"
- | "CSV_TRIM_LAST_SEPARATORS"
- | "CSV_DELIMITER"
- | "CSV_HEADER"
- | "CSV_NULL"
- | "CSV_SEPARATOR"
- | "ON_DUPLICATE"
- | "TIKV_IMPORTER"
- | "CONSTRAINTS"
- | "REPLICAS"
- | "POLICY"
- | "WAIT"
- | "CLIENT_ERRORS_SUMMARY"
- | "BERNOULLI"
- | "SYSTEM"
- | "PERCENT"
- | "RESUME"
- | "OFF"
- | "OPTIONAL"
- | "REQUIRED"
- | "PURGE"
- | "SKIP"
- | "LOCKED"
- | "CLUSTERED"
- | "NONCLUSTERED"
- TiDBKeyword:
- "ADMIN"
- | "BUCKETS"
- | "BUILTINS"
- | "CANCEL"
- | "CARDINALITY"
- | "CMSKETCH"
- | "CORRELATION"
- | "DDL"
- | "DEPENDENCY"
- | "DEPTH"
- | "DRAINER"
- | "JOBS"
- | "JOB"
- | "NODE_ID"
- | "NODE_STATE"
- | "PUMP"
- | "SAMPLES"
- | "STATISTICS"
- | "STATS"
- | "STATS_META"
- | "STATS_HISTOGRAMS"
- | "STATS_TOPN"
- | "STATS_BUCKETS"
- | "STATS_HEALTHY"
- | "TELEMETRY"
- | "TELEMETRY_ID"
- | "TIDB"
- | "TIFLASH"
- | "TOPN"
- | "SPLIT"
- | "OPTIMISTIC"
- | "PESSIMISTIC"
- | "WIDTH"
- | "REGIONS"
- | "REGION"
- | "RESET"
- NotKeywordToken:
- "ADDDATE"
- | "APPROX_COUNT_DISTINCT"
- | "APPROX_PERCENTILE"
- | "BIT_AND"
- | "BIT_OR"
- | "BIT_XOR"
- | "CAST"
- | "COPY"
- | "CURTIME"
- | "DATE_ADD"
- | "DATE_SUB"
- | "EXTRACT"
- | "GET_FORMAT"
- | "GROUP_CONCAT"
- | "INPLACE"
- | "INSTANT"
- | "INTERNAL"
- | "MIN"
- | "MAX"
- | "NOW"
- | "RECENT"
- | "RUNNING"
- | "POSITION"
- | "S3"
- | "STRICT"
- | "SUBDATE"
- | "SUBSTRING"
- | "SUM"
- | "STD"
- | "STDDEV"
- | "STDDEV_POP"
- | "STDDEV_SAMP"
- | "STOP"
- | "VARIANCE"
- | "VAR_POP"
- | "VAR_SAMP"
- | "TIMESTAMPADD"
- | "TIMESTAMPDIFF"
- | "TOKUDB_DEFAULT"
- | "TOKUDB_FAST"
- | "TOKUDB_LZMA"
- | "TOKUDB_QUICKLZ"
- | "TOKUDB_SNAPPY"
- | "TOKUDB_SMALL"
- | "TOKUDB_UNCOMPRESSED"
- | "TOKUDB_ZLIB"
- | "TOP"
- | "TRIM"
- | "NEXT_ROW_ID"
- | "EXPR_PUSHDOWN_BLACKLIST"
- | "OPT_RULE_BLACKLIST"
- | "BOUND"
- | "EXACT"
- | "STALENESS"
- | "STRONG"
- | "FLASHBACK"
- | "JSON_OBJECTAGG"
- | "JSON_ARRAYAGG"
- | "TLS"
- | "FOLLOWER"
- | "LEADER"
- | "LEARNER"
- | "VOTER"
- /************************************************************************************
- *
- * Call Statements
- *
- **********************************************************************************/
- CallStmt:
- "CALL" ProcedureCall
- {
- $$ = &ast.CallStmt{
- Procedure: $2.(*ast.FuncCallExpr),
- }
- }
- ProcedureCall:
- identifier
- {
- $$ = &ast.FuncCallExpr{
- Tp: ast.FuncCallExprTypeGeneric,
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{},
- }
- }
- | Identifier '.' Identifier
- {
- $$ = &ast.FuncCallExpr{
- Tp: ast.FuncCallExprTypeGeneric,
- Schema: model.NewCIStr($1),
- FnName: model.NewCIStr($3),
- Args: []ast.ExprNode{},
- }
- }
- | identifier '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{
- Tp: ast.FuncCallExprTypeGeneric,
- FnName: model.NewCIStr($1),
- Args: $3.([]ast.ExprNode),
- }
- }
- | Identifier '.' Identifier '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{
- Tp: ast.FuncCallExprTypeGeneric,
- Schema: model.NewCIStr($1),
- FnName: model.NewCIStr($3),
- Args: $5.([]ast.ExprNode),
- }
- }
- /************************************************************************************
- *
- * Insert Statements
- *
- * TODO: support PARTITION
- **********************************************************************************/
- InsertIntoStmt:
- "INSERT" TableOptimizerHintsOpt PriorityOpt IgnoreOptional IntoOpt TableName PartitionNameListOpt InsertValues OnDuplicateKeyUpdate
- {
- x := $8.(*ast.InsertStmt)
- x.Priority = $3.(mysql.PriorityEnum)
- x.IgnoreErr = $4.(bool)
- // Wraps many layers here so that it can be processed the same way as select statement.
- ts := &ast.TableSource{Source: $6.(*ast.TableName)}
- x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}}
- if $9 != nil {
- x.OnDuplicate = $9.([]*ast.Assignment)
- }
- if $2 != nil {
- x.TableHints = $2.([]*ast.TableOptimizerHint)
- }
- x.PartitionNames = $7.([]model.CIStr)
- $$ = x
- }
- IntoOpt:
- {}
- | "INTO"
- InsertValues:
- '(' ColumnNameListOpt ')' ValueSym ValuesList
- {
- $$ = &ast.InsertStmt{
- Columns: $2.([]*ast.ColumnName),
- Lists: $5.([][]ast.ExprNode),
- }
- }
- | '(' ColumnNameListOpt ')' SetOprStmt1
- {
- $$ = &ast.InsertStmt{Columns: $2.([]*ast.ColumnName), Select: $4.(ast.ResultSetNode)}
- }
- | ValueSym ValuesList %prec insertValues
- {
- $$ = &ast.InsertStmt{Lists: $2.([][]ast.ExprNode)}
- }
- | SetOprStmt1
- {
- $$ = &ast.InsertStmt{Select: $1.(ast.ResultSetNode)}
- }
- | "SET" ColumnSetValueList
- {
- $$ = &ast.InsertStmt{Setlist: $2.([]*ast.Assignment)}
- }
- ValueSym:
- "VALUE"
- | "VALUES"
- ValuesList:
- RowValue
- {
- $$ = [][]ast.ExprNode{$1.([]ast.ExprNode)}
- }
- | ValuesList ',' RowValue
- {
- $$ = append($1.([][]ast.ExprNode), $3.([]ast.ExprNode))
- }
- RowValue:
- '(' ValuesOpt ')'
- {
- $$ = $2
- }
- ValuesOpt:
- {
- $$ = []ast.ExprNode{}
- }
- | Values
- Values:
- Values ',' ExprOrDefault
- {
- $$ = append($1.([]ast.ExprNode), $3)
- }
- | ExprOrDefault
- {
- $$ = []ast.ExprNode{$1}
- }
- ExprOrDefault:
- Expression
- | "DEFAULT"
- {
- $$ = &ast.DefaultExpr{}
- }
- ColumnSetValue:
- ColumnName eq ExprOrDefault
- {
- $$ = &ast.Assignment{
- Column: $1.(*ast.ColumnName),
- Expr: $3,
- }
- }
- ColumnSetValueList:
- {
- $$ = []*ast.Assignment{}
- }
- | ColumnSetValue
- {
- $$ = []*ast.Assignment{$1.(*ast.Assignment)}
- }
- | ColumnSetValueList ',' ColumnSetValue
- {
- $$ = append($1.([]*ast.Assignment), $3.(*ast.Assignment))
- }
- /*
- * ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ...
- * See https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html
- */
- OnDuplicateKeyUpdate:
- {
- $$ = nil
- }
- | "ON" "DUPLICATE" "KEY" "UPDATE" AssignmentList
- {
- $$ = $5
- }
- /************************************************************************************
- * Replace Statements
- * See https://dev.mysql.com/doc/refman/5.7/en/replace.html
- *
- * TODO: support PARTITION
- **********************************************************************************/
- ReplaceIntoStmt:
- "REPLACE" PriorityOpt IntoOpt TableName PartitionNameListOpt InsertValues
- {
- x := $6.(*ast.InsertStmt)
- x.IsReplace = true
- x.Priority = $2.(mysql.PriorityEnum)
- ts := &ast.TableSource{Source: $4.(*ast.TableName)}
- x.Table = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}}
- x.PartitionNames = $5.([]model.CIStr)
- $$ = x
- }
- ODBCDateTimeType:
- "d"
- {
- $$ = ast.DateLiteral
- }
- | "t"
- {
- $$ = ast.TimeLiteral
- }
- | "ts"
- {
- $$ = ast.TimestampLiteral
- }
- Literal:
- "FALSE"
- {
- $$ = ast.NewValueExpr(false, parser.charset, parser.collation)
- }
- | "NULL"
- {
- $$ = ast.NewValueExpr(nil, parser.charset, parser.collation)
- }
- | "TRUE"
- {
- $$ = ast.NewValueExpr(true, parser.charset, parser.collation)
- }
- | floatLit
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | decLit
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | intLit
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | StringLiteral %prec lowerThanStringLitToken
- | "UNDERSCORE_CHARSET" stringLit
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/charset-literal.html
- co, err := charset.GetDefaultCollation($1)
- if err != nil {
- yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", $1))
- return 1
- }
- expr := ast.NewValueExpr($2, parser.charset, parser.collation)
- tp := expr.GetType()
- tp.Charset = $1
- tp.Collate = co
- if tp.Collate == charset.CollationBin {
- tp.Flag |= mysql.BinaryFlag
- }
- $$ = expr
- }
- | hexLit
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | bitLit
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | "UNDERSCORE_CHARSET" hexLit
- {
- co, err := charset.GetDefaultCollation($1)
- if err != nil {
- yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", $1))
- return 1
- }
- expr := ast.NewValueExpr($2, parser.charset, parser.collation)
- tp := expr.GetType()
- tp.Charset = $1
- tp.Collate = co
- if tp.Collate == charset.CollationBin {
- tp.Flag |= mysql.BinaryFlag
- }
- $$ = expr
- }
- | "UNDERSCORE_CHARSET" bitLit
- {
- co, err := charset.GetDefaultCollation($1)
- if err != nil {
- yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", $1))
- return 1
- }
- expr := ast.NewValueExpr($2, parser.charset, parser.collation)
- tp := expr.GetType()
- tp.Charset = $1
- tp.Collate = co
- if tp.Collate == charset.CollationBin {
- tp.Flag |= mysql.BinaryFlag
- }
- $$ = expr
- }
- StringLiteral:
- stringLit
- {
- expr := ast.NewValueExpr($1, parser.charset, parser.collation)
- $$ = expr
- }
- | StringLiteral stringLit
- {
- valExpr := $1.(ast.ValueExpr)
- strLit := valExpr.GetString()
- expr := ast.NewValueExpr(strLit+$2, parser.charset, parser.collation)
- // Fix #4239, use first string literal as projection name.
- if valExpr.GetProjectionOffset() >= 0 {
- expr.SetProjectionOffset(valExpr.GetProjectionOffset())
- } else {
- expr.SetProjectionOffset(len(strLit))
- }
- $$ = expr
- }
- AlterOrderList:
- AlterOrderItem
- {
- $$ = []*ast.AlterOrderItem{$1.(*ast.AlterOrderItem)}
- }
- | AlterOrderList ',' AlterOrderItem
- {
- $$ = append($1.([]*ast.AlterOrderItem), $3.(*ast.AlterOrderItem))
- }
- AlterOrderItem:
- ColumnName OptOrder
- {
- $$ = &ast.AlterOrderItem{Column: $1.(*ast.ColumnName), Desc: $2.(bool)}
- }
- OrderBy:
- "ORDER" "BY" ByList
- {
- $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)}
- }
- ByList:
- ByItem
- {
- $$ = []*ast.ByItem{$1.(*ast.ByItem)}
- }
- | ByList ',' ByItem
- {
- $$ = append($1.([]*ast.ByItem), $3.(*ast.ByItem))
- }
- ByItem:
- Expression
- {
- expr := $1
- valueExpr, ok := expr.(ast.ValueExpr)
- if ok {
- position, isPosition := valueExpr.GetValue().(int64)
- if isPosition {
- expr = &ast.PositionExpr{N: int(position)}
- }
- }
- $$ = &ast.ByItem{Expr: expr, NullOrder: true}
- }
- | Expression Order
- {
- expr := $1
- valueExpr, ok := expr.(ast.ValueExpr)
- if ok {
- position, isPosition := valueExpr.GetValue().(int64)
- if isPosition {
- expr = &ast.PositionExpr{N: int(position)}
- }
- }
- $$ = &ast.ByItem{Expr: expr, Desc: $2.(bool)}
- }
- Order:
- "ASC"
- {
- $$ = false
- }
- | "DESC"
- {
- $$ = true
- }
- OptOrder:
- /* EMPTY */
- {
- $$ = false // ASC by default
- }
- | "ASC"
- {
- $$ = false
- }
- | "DESC"
- {
- $$ = true
- }
- OrderByOptional:
- {
- $$ = nil
- }
- | OrderBy
- BitExpr:
- BitExpr '|' BitExpr %prec '|'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Or, L: $1, R: $3}
- }
- | BitExpr '&' BitExpr %prec '&'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.And, L: $1, R: $3}
- }
- | BitExpr "<<" BitExpr %prec lsh
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.LeftShift, L: $1, R: $3}
- }
- | BitExpr ">>" BitExpr %prec rsh
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.RightShift, L: $1, R: $3}
- }
- | BitExpr '+' BitExpr %prec '+'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Plus, L: $1, R: $3}
- }
- | BitExpr '-' BitExpr %prec '-'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Minus, L: $1, R: $3}
- }
- | BitExpr '+' "INTERVAL" Expression TimeUnit %prec '+'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr("DATE_ADD"),
- Args: []ast.ExprNode{
- $1,
- $4,
- &ast.TimeUnitExpr{Unit: $5.(ast.TimeUnitType)},
- },
- }
- }
- | BitExpr '-' "INTERVAL" Expression TimeUnit %prec '+'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr("DATE_SUB"),
- Args: []ast.ExprNode{
- $1,
- $4,
- &ast.TimeUnitExpr{Unit: $5.(ast.TimeUnitType)},
- },
- }
- }
- | BitExpr '*' BitExpr %prec '*'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Mul, L: $1, R: $3}
- }
- | BitExpr '/' BitExpr %prec '/'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Div, L: $1, R: $3}
- }
- | BitExpr '%' BitExpr %prec '%'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3}
- }
- | BitExpr "DIV" BitExpr %prec div
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.IntDiv, L: $1, R: $3}
- }
- | BitExpr "MOD" BitExpr %prec mod
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $1, R: $3}
- }
- | BitExpr '^' BitExpr
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Xor, L: $1, R: $3}
- }
- | SimpleExpr
- SimpleIdent:
- Identifier
- {
- $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{
- Name: model.NewCIStr($1),
- }}
- }
- | Identifier '.' Identifier
- {
- $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{
- Table: model.NewCIStr($1),
- Name: model.NewCIStr($3),
- }}
- }
- | Identifier '.' Identifier '.' Identifier
- {
- $$ = &ast.ColumnNameExpr{Name: &ast.ColumnName{
- Schema: model.NewCIStr($1),
- Table: model.NewCIStr($3),
- Name: model.NewCIStr($5),
- }}
- }
- SimpleExpr:
- SimpleIdent
- | FunctionCallKeyword
- | FunctionCallNonKeyword
- | FunctionCallGeneric
- | SimpleExpr "COLLATE" CollationName
- {
- $$ = &ast.SetCollationExpr{Expr: $1, Collate: $3}
- }
- | WindowFuncCall
- | Literal
- | paramMarker
- {
- $$ = ast.NewParamMarkerExpr(yyS[yypt].offset)
- }
- | Variable
- | SumExpr
- | '!' SimpleExpr %prec neg
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Not2, V: $2}
- }
- | '~' SimpleExpr %prec neg
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.BitNeg, V: $2}
- }
- | '-' SimpleExpr %prec neg
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Minus, V: $2}
- }
- | '+' SimpleExpr %prec neg
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Plus, V: $2}
- }
- | SimpleExpr pipes SimpleExpr
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.Concat), Args: []ast.ExprNode{$1, $3}}
- }
- | not2 SimpleExpr %prec neg
- {
- $$ = &ast.UnaryOperationExpr{Op: opcode.Not2, V: $2}
- }
- | SubSelect2
- | '(' Expression ')'
- {
- startOffset := parser.startOffset(&yyS[yypt-1])
- endOffset := parser.endOffset(&yyS[yypt])
- expr := $2
- expr.SetText(parser.src[startOffset:endOffset])
- $$ = &ast.ParenthesesExpr{Expr: expr}
- }
- | '(' ExpressionList ',' Expression ')'
- {
- values := append($2.([]ast.ExprNode), $4)
- $$ = &ast.RowExpr{Values: values}
- }
- | "ROW" '(' ExpressionList ',' Expression ')'
- {
- values := append($3.([]ast.ExprNode), $5)
- $$ = &ast.RowExpr{Values: values}
- }
- | "EXISTS" SubSelect
- {
- sq := $2.(*ast.SubqueryExpr)
- sq.Exists = true
- $$ = &ast.ExistsSubqueryExpr{Sel: sq}
- }
- | "BINARY" SimpleExpr %prec neg
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#operator_binary
- x := types.NewFieldType(mysql.TypeString)
- x.Charset = charset.CharsetBin
- x.Collate = charset.CharsetBin
- x.Flag |= mysql.BinaryFlag
- $$ = &ast.FuncCastExpr{
- Expr: $2,
- Tp: x,
- FunctionType: ast.CastBinaryOperator,
- }
- }
- | builtinCast '(' Expression "AS" CastType ')'
- {
- /* See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast */
- tp := $5.(*types.FieldType)
- defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.Tp)
- if tp.Flen == types.UnspecifiedLength {
- tp.Flen = defaultFlen
- }
- if tp.Decimal == types.UnspecifiedLength {
- tp.Decimal = defaultDecimal
- }
- explicitCharset := parser.explicitCharset
- parser.explicitCharset = false
- $$ = &ast.FuncCastExpr{
- Expr: $3,
- Tp: tp,
- FunctionType: ast.CastFunction,
- ExplicitCharSet: explicitCharset,
- }
- }
- | "CASE" ExpressionOpt WhenClauseList ElseOpt "END"
- {
- x := &ast.CaseExpr{WhenClauses: $3.([]*ast.WhenClause)}
- if $2 != nil {
- x.Value = $2
- }
- if $4 != nil {
- x.ElseClause = $4.(ast.ExprNode)
- }
- $$ = x
- }
- | "CONVERT" '(' Expression ',' CastType ')'
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
- tp := $5.(*types.FieldType)
- defaultFlen, defaultDecimal := mysql.GetDefaultFieldLengthAndDecimalForCast(tp.Tp)
- if tp.Flen == types.UnspecifiedLength {
- tp.Flen = defaultFlen
- }
- if tp.Decimal == types.UnspecifiedLength {
- tp.Decimal = defaultDecimal
- }
- explicitCharset := parser.explicitCharset
- parser.explicitCharset = false
- $$ = &ast.FuncCastExpr{
- Expr: $3,
- Tp: tp,
- FunctionType: ast.CastConvertFunction,
- ExplicitCharSet: explicitCharset,
- }
- }
- | "CONVERT" '(' Expression "USING" CharsetName ')'
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_convert
- charset1 := ast.NewValueExpr($5, "", "")
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, charset1},
- }
- }
- | "DEFAULT" '(' SimpleIdent ')'
- {
- $$ = &ast.DefaultExpr{Name: $3.(*ast.ColumnNameExpr).Name}
- }
- | "VALUES" '(' SimpleIdent ')' %prec lowerThanInsertValues
- {
- $$ = &ast.ValuesExpr{Column: $3.(*ast.ColumnNameExpr)}
- }
- | SimpleIdent jss stringLit
- {
- expr := ast.NewValueExpr($3, parser.charset, parser.collation)
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}}
- }
- | SimpleIdent juss stringLit
- {
- expr := ast.NewValueExpr($3, parser.charset, parser.collation)
- extract := &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONExtract), Args: []ast.ExprNode{$1, expr}}
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.JSONUnquote), Args: []ast.ExprNode{extract}}
- }
- DistinctKwd:
- "DISTINCT"
- | "DISTINCTROW"
- DistinctOpt:
- "ALL"
- {
- $$ = false
- }
- | DistinctKwd
- {
- $$ = true
- }
- DefaultFalseDistinctOpt:
- {
- $$ = false
- }
- | DistinctOpt
- DefaultTrueDistinctOpt:
- {
- $$ = true
- }
- | DistinctOpt
- BuggyDefaultFalseDistinctOpt:
- DefaultFalseDistinctOpt
- | DistinctKwd "ALL"
- {
- $$ = true
- }
- FunctionNameConflict:
- "ASCII"
- | "CHARSET"
- | "COALESCE"
- | "COLLATION"
- | "DATE"
- | "DATABASE"
- | "DAY"
- | "HOUR"
- | "IF"
- | "INTERVAL" %prec lowerThanIntervalKeyword
- | "FORMAT"
- | "LEFT"
- | "MICROSECOND"
- | "MINUTE"
- | "MONTH"
- | builtinNow
- | "QUARTER"
- | "REPEAT"
- | "REPLACE"
- | "REVERSE"
- | "RIGHT"
- | "ROW_COUNT"
- | "SECOND"
- | "TIME"
- | "TIMESTAMP"
- | "TRUNCATE"
- | "USER"
- | "WEEK"
- | "YEAR"
- OptionalBraces:
- {}
- | '(' ')'
- {}
- FunctionNameOptionalBraces:
- "CURRENT_USER"
- | "CURRENT_DATE"
- | "CURRENT_ROLE"
- | "UTC_DATE"
- FunctionNameDatetimePrecision:
- "CURRENT_TIME"
- | "CURRENT_TIMESTAMP"
- | "LOCALTIME"
- | "LOCALTIMESTAMP"
- | "UTC_TIME"
- | "UTC_TIMESTAMP"
- FunctionCallKeyword:
- FunctionNameConflict '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
- }
- | builtinUser '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
- }
- | FunctionNameOptionalBraces OptionalBraces
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)}
- }
- | builtinCurDate '(' ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1)}
- }
- | FunctionNameDatetimePrecision FuncDatetimePrec
- {
- args := []ast.ExprNode{}
- if $2 != nil {
- args = append(args, $2.(ast.ExprNode))
- }
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: args}
- }
- | "CHAR" '(' ExpressionList ')'
- {
- nilVal := ast.NewValueExpr(nil, parser.charset, parser.collation)
- args := $3.([]ast.ExprNode)
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr(ast.CharFunc),
- Args: append(args, nilVal),
- }
- }
- | "CHAR" '(' ExpressionList "USING" CharsetName ')'
- {
- charset1 := ast.NewValueExpr($5, "", "")
- args := $3.([]ast.ExprNode)
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr(ast.CharFunc),
- Args: append(args, charset1),
- }
- }
- | "DATE" stringLit
- {
- expr := ast.NewValueExpr($2, "", "")
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.DateLiteral), Args: []ast.ExprNode{expr}}
- }
- | "TIME" stringLit
- {
- expr := ast.NewValueExpr($2, "", "")
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimeLiteral), Args: []ast.ExprNode{expr}}
- }
- | "TIMESTAMP" stringLit
- {
- expr := ast.NewValueExpr($2, "", "")
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.TimestampLiteral), Args: []ast.ExprNode{expr}}
- }
- | "INSERT" '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.InsertFunc), Args: $3.([]ast.ExprNode)}
- }
- | "MOD" '(' BitExpr ',' BitExpr ')'
- {
- $$ = &ast.BinaryOperationExpr{Op: opcode.Mod, L: $3, R: $5}
- }
- | "PASSWORD" '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr(ast.PasswordFunc), Args: $3.([]ast.ExprNode)}
- }
- | '{' ODBCDateTimeType stringLit '}'
- {
- // This is ODBC syntax for date and time literals.
- // See: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-literals.html
- expr := ast.NewValueExpr($3, parser.charset, parser.collation)
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($2), Args: []ast.ExprNode{expr}}
- }
- FunctionCallNonKeyword:
- builtinCurTime '(' FuncDatetimePrecListOpt ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
- }
- | builtinSysDate '(' FuncDatetimePrecListOpt ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: $3.([]ast.ExprNode)}
- }
- | FunctionNameDateArithMultiForms '(' Expression ',' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{
- $3,
- $5,
- &ast.TimeUnitExpr{Unit: ast.TimeUnitDay},
- },
- }
- }
- | FunctionNameDateArithMultiForms '(' Expression ',' "INTERVAL" Expression TimeUnit ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{
- $3,
- $6,
- &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)},
- },
- }
- }
- | FunctionNameDateArith '(' Expression ',' "INTERVAL" Expression TimeUnit ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{
- $3,
- $6,
- &ast.TimeUnitExpr{Unit: $7.(ast.TimeUnitType)},
- },
- }
- }
- | builtinExtract '(' TimeUnit "FROM" Expression ')'
- {
- timeUnit := &ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{timeUnit, $5},
- }
- }
- | "GET_FORMAT" '(' GetFormatSelector ',' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{
- &ast.GetFormatSelectorExpr{Selector: $3.(ast.GetFormatSelectorType)},
- $5,
- },
- }
- }
- | builtinPosition '(' BitExpr "IN" Expression ')'
- {
- $$ = &ast.FuncCallExpr{FnName: model.NewCIStr($1), Args: []ast.ExprNode{$3, $5}}
- }
- | builtinSubstring '(' Expression ',' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, $5},
- }
- }
- | builtinSubstring '(' Expression "FROM" Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, $5},
- }
- }
- | builtinSubstring '(' Expression ',' Expression ',' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, $5, $7},
- }
- }
- | builtinSubstring '(' Expression "FROM" Expression "FOR" Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, $5, $7},
- }
- }
- | "TIMESTAMPADD" '(' TimestampUnit ',' Expression ',' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{&ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, $5, $7},
- }
- }
- | "TIMESTAMPDIFF" '(' TimestampUnit ',' Expression ',' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{&ast.TimeUnitExpr{Unit: $3.(ast.TimeUnitType)}, $5, $7},
- }
- }
- | builtinTrim '(' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3},
- }
- }
- | builtinTrim '(' Expression "FROM" Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$5, $3},
- }
- }
- | builtinTrim '(' TrimDirection "FROM" Expression ')'
- {
- nilVal := ast.NewValueExpr(nil, parser.charset, parser.collation)
- direction := &ast.TrimDirectionExpr{Direction: $3.(ast.TrimDirectionType)}
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$5, nilVal, direction},
- }
- }
- | builtinTrim '(' TrimDirection Expression "FROM" Expression ')'
- {
- direction := &ast.TrimDirectionExpr{Direction: $3.(ast.TrimDirectionType)}
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$6, $4, direction},
- }
- }
- | weightString '(' Expression ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3},
- }
- }
- | weightString '(' Expression "AS" Char FieldLen ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, ast.NewValueExpr("CHAR", parser.charset, parser.collation), ast.NewValueExpr($6, parser.charset, parser.collation)},
- }
- }
- | weightString '(' Expression "AS" "BINARY" FieldLen ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: []ast.ExprNode{$3, ast.NewValueExpr("BINARY", parser.charset, parser.collation), ast.NewValueExpr($6, parser.charset, parser.collation)},
- }
- }
- | FunctionNameSequence
- GetFormatSelector:
- "DATE"
- {
- $$ = ast.GetFormatSelectorDate
- }
- | "DATETIME"
- {
- $$ = ast.GetFormatSelectorDatetime
- }
- | "TIME"
- {
- $$ = ast.GetFormatSelectorTime
- }
- | "TIMESTAMP"
- {
- $$ = ast.GetFormatSelectorDatetime
- }
- FunctionNameDateArith:
- builtinDateAdd
- | builtinDateSub
- FunctionNameDateArithMultiForms:
- builtinAddDate
- | builtinSubDate
- TrimDirection:
- "BOTH"
- {
- $$ = ast.TrimBoth
- }
- | "LEADING"
- {
- $$ = ast.TrimLeading
- }
- | "TRAILING"
- {
- $$ = ast.TrimTrailing
- }
- FunctionNameSequence:
- "LASTVAL" '(' TableName ')'
- {
- objNameExpr := &ast.TableNameExpr{
- Name: $3.(*ast.TableName),
- }
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr(ast.LastVal),
- Args: []ast.ExprNode{objNameExpr},
- }
- }
- | "SETVAL" '(' TableName ',' SignedNum ')'
- {
- objNameExpr := &ast.TableNameExpr{
- Name: $3.(*ast.TableName),
- }
- valueExpr := ast.NewValueExpr($5, parser.charset, parser.collation)
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr(ast.SetVal),
- Args: []ast.ExprNode{objNameExpr, valueExpr},
- }
- }
- | NextValueForSequence
- SumExpr:
- "AVG" '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinApproxCountDistinct '(' ExpressionList ')'
- {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: $3.([]ast.ExprNode), Distinct: false}
- }
- | builtinApproxPercentile '(' ExpressionList ')'
- {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: $3.([]ast.ExprNode)}
- }
- | builtinBitAnd '(' Expression ')' OptWindowingClause
- {
- if $5 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
- }
- }
- | builtinBitAnd '(' "ALL" Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
- }
- }
- | builtinBitOr '(' Expression ')' OptWindowingClause
- {
- if $5 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
- }
- }
- | builtinBitOr '(' "ALL" Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
- }
- }
- | builtinBitXor '(' Expression ')' OptWindowingClause
- {
- if $5 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
- }
- }
- | builtinBitXor '(' "ALL" Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
- }
- }
- | builtinCount '(' DistinctKwd ExpressionList ')'
- {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: $4.([]ast.ExprNode), Distinct: true}
- }
- | builtinCount '(' "ALL" Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
- }
- }
- | builtinCount '(' Expression ')' OptWindowingClause
- {
- if $5 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
- }
- }
- | builtinCount '(' '*' ')' OptWindowingClause
- {
- args := []ast.ExprNode{ast.NewValueExpr(1, parser.charset, parser.collation)}
- if $5 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: args, Spec: *($5.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: args}
- }
- }
- | builtinGroupConcat '(' BuggyDefaultFalseDistinctOpt ExpressionList OrderByOptional OptGConcatSeparator ')' OptWindowingClause
- {
- args := $4.([]ast.ExprNode)
- args = append(args, $6.(ast.ExprNode))
- if $8 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: args, Distinct: $3.(bool), Spec: *($8.(*ast.WindowSpec))}
- } else {
- agg := &ast.AggregateFuncExpr{F: $1, Args: args, Distinct: $3.(bool)}
- if $5 != nil {
- agg.Order = $5.(*ast.OrderByClause)
- }
- $$ = agg
- }
- }
- | builtinMax '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinMin '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinSum '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinStddevPop '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: ast.AggFuncStddevPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: ast.AggFuncStddevPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinStddevSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinVarPop '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: ast.AggFuncVarPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool), Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: ast.AggFuncVarPop, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- }
- | builtinVarSamp '(' BuggyDefaultFalseDistinctOpt Expression ')' OptWindowingClause
- {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Distinct: $3.(bool)}
- }
- | "JSON_ARRAYAGG" '(' Expression ')' OptWindowingClause
- {
- if $5 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: *($5.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3}}
- }
- }
- | "JSON_ARRAYAGG" '(' "ALL" Expression ')' OptWindowingClause
- {
- if $6 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4}, Spec: *($6.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4}}
- }
- }
- | "JSON_OBJECTAGG" '(' Expression ',' Expression ')' OptWindowingClause
- {
- if $7 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}, Spec: *($7.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}}
- }
- }
- | "JSON_OBJECTAGG" '(' "ALL" Expression ',' Expression ')' OptWindowingClause
- {
- if $8 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4, $6}, Spec: *($8.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4, $6}}
- }
- }
- | "JSON_OBJECTAGG" '(' Expression ',' "ALL" Expression ')' OptWindowingClause
- {
- if $8 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3, $6}, Spec: *($8.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$3, $6}}
- }
- }
- | "JSON_OBJECTAGG" '(' "ALL" Expression ',' "ALL" Expression ')' OptWindowingClause
- {
- if $9 != nil {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$4, $7}, Spec: *($9.(*ast.WindowSpec))}
- } else {
- $$ = &ast.AggregateFuncExpr{F: $1, Args: []ast.ExprNode{$4, $7}}
- }
- }
- OptGConcatSeparator:
- {
- $$ = ast.NewValueExpr(",", "", "")
- }
- | "SEPARATOR" stringLit
- {
- $$ = ast.NewValueExpr($2, "", "")
- }
- FunctionCallGeneric:
- identifier '(' ExpressionListOpt ')'
- {
- $$ = &ast.FuncCallExpr{
- FnName: model.NewCIStr($1),
- Args: $3.([]ast.ExprNode),
- }
- }
- | Identifier '.' Identifier '(' ExpressionListOpt ')'
- {
- var tp ast.FuncCallExprType
- if isInTokenMap($3) {
- tp = ast.FuncCallExprTypeKeyword
- } else {
- tp = ast.FuncCallExprTypeGeneric
- }
- $$ = &ast.FuncCallExpr{
- Tp: tp,
- Schema: model.NewCIStr($1),
- FnName: model.NewCIStr($3),
- Args: $5.([]ast.ExprNode),
- }
- }
- FuncDatetimePrec:
- {
- $$ = nil
- }
- | '(' ')'
- {
- $$ = nil
- }
- | '(' intLit ')'
- {
- expr := ast.NewValueExpr($2, parser.charset, parser.collation)
- $$ = expr
- }
- TimeUnit:
- TimestampUnit
- | "SECOND_MICROSECOND"
- {
- $$ = ast.TimeUnitSecondMicrosecond
- }
- | "MINUTE_MICROSECOND"
- {
- $$ = ast.TimeUnitMinuteMicrosecond
- }
- | "MINUTE_SECOND"
- {
- $$ = ast.TimeUnitMinuteSecond
- }
- | "HOUR_MICROSECOND"
- {
- $$ = ast.TimeUnitHourMicrosecond
- }
- | "HOUR_SECOND"
- {
- $$ = ast.TimeUnitHourSecond
- }
- | "HOUR_MINUTE"
- {
- $$ = ast.TimeUnitHourMinute
- }
- | "DAY_MICROSECOND"
- {
- $$ = ast.TimeUnitDayMicrosecond
- }
- | "DAY_SECOND"
- {
- $$ = ast.TimeUnitDaySecond
- }
- | "DAY_MINUTE"
- {
- $$ = ast.TimeUnitDayMinute
- }
- | "DAY_HOUR"
- {
- $$ = ast.TimeUnitDayHour
- }
- | "YEAR_MONTH"
- {
- $$ = ast.TimeUnitYearMonth
- }
- TimestampUnit:
- "MICROSECOND"
- {
- $$ = ast.TimeUnitMicrosecond
- }
- | "SECOND"
- {
- $$ = ast.TimeUnitSecond
- }
- | "MINUTE"
- {
- $$ = ast.TimeUnitMinute
- }
- | "HOUR"
- {
- $$ = ast.TimeUnitHour
- }
- | "DAY"
- {
- $$ = ast.TimeUnitDay
- }
- | "WEEK"
- {
- $$ = ast.TimeUnitWeek
- }
- | "MONTH"
- {
- $$ = ast.TimeUnitMonth
- }
- | "QUARTER"
- {
- $$ = ast.TimeUnitQuarter
- }
- | "YEAR"
- {
- $$ = ast.TimeUnitYear
- }
- | "SQL_TSI_SECOND"
- {
- $$ = ast.TimeUnitSecond
- }
- | "SQL_TSI_MINUTE"
- {
- $$ = ast.TimeUnitMinute
- }
- | "SQL_TSI_HOUR"
- {
- $$ = ast.TimeUnitHour
- }
- | "SQL_TSI_DAY"
- {
- $$ = ast.TimeUnitDay
- }
- | "SQL_TSI_WEEK"
- {
- $$ = ast.TimeUnitWeek
- }
- | "SQL_TSI_MONTH"
- {
- $$ = ast.TimeUnitMonth
- }
- | "SQL_TSI_QUARTER"
- {
- $$ = ast.TimeUnitQuarter
- }
- | "SQL_TSI_YEAR"
- {
- $$ = ast.TimeUnitYear
- }
- ExpressionOpt:
- {
- $$ = nil
- }
- | Expression
- WhenClauseList:
- WhenClause
- {
- $$ = []*ast.WhenClause{$1.(*ast.WhenClause)}
- }
- | WhenClauseList WhenClause
- {
- $$ = append($1.([]*ast.WhenClause), $2.(*ast.WhenClause))
- }
- WhenClause:
- "WHEN" Expression "THEN" Expression
- {
- $$ = &ast.WhenClause{
- Expr: $2,
- Result: $4,
- }
- }
- ElseOpt:
- /* empty */
- {
- $$ = nil
- }
- | "ELSE" Expression
- {
- $$ = $2
- }
- CastType:
- "BINARY" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeVarString)
- x.Flen = $2.(int) // TODO: Flen should be the flen of expression
- if x.Flen != types.UnspecifiedLength {
- x.Tp = mysql.TypeString
- }
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | Char OptFieldLen OptBinary
- {
- x := types.NewFieldType(mysql.TypeVarString)
- x.Flen = $2.(int) // TODO: Flen should be the flen of expression
- x.Charset = $3.(*ast.OptBinary).Charset
- if $3.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- } else if x.Charset != "" {
- co, err := charset.GetDefaultCollation(x.Charset)
- if err != nil {
- yylex.AppendError(yylex.Errorf("Get collation error for charset: %s", x.Charset))
- return 1
- }
- x.Collate = co
- parser.explicitCharset = true
- } else {
- x.Charset = parser.charset
- x.Collate = parser.collation
- }
- $$ = x
- }
- | "DATE"
- {
- x := types.NewFieldType(mysql.TypeDate)
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | "DATETIME" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeDatetime)
- x.Flen, _ = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDatetime)
- x.Decimal = $2.(int)
- if x.Decimal > 0 {
- x.Flen = x.Flen + 1 + x.Decimal
- }
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | "DECIMAL" FloatOpt
- {
- fopt := $2.(*ast.FloatOpt)
- x := types.NewFieldType(mysql.TypeNewDecimal)
- x.Flen = fopt.Flen
- x.Decimal = fopt.Decimal
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | "TIME" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeDuration)
- x.Flen, _ = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDuration)
- x.Decimal = $2.(int)
- if x.Decimal > 0 {
- x.Flen = x.Flen + 1 + x.Decimal
- }
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | "SIGNED" OptInteger
- {
- x := types.NewFieldType(mysql.TypeLonglong)
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | "UNSIGNED" OptInteger
- {
- x := types.NewFieldType(mysql.TypeLonglong)
- x.Flag |= mysql.UnsignedFlag | mysql.BinaryFlag
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- $$ = x
- }
- | "JSON"
- {
- x := types.NewFieldType(mysql.TypeJSON)
- x.Flag |= mysql.BinaryFlag | (mysql.ParseToJSONFlag)
- x.Charset = mysql.DefaultCharset
- x.Collate = mysql.DefaultCollationName
- $$ = x
- }
- | "DOUBLE"
- {
- x := types.NewFieldType(mysql.TypeDouble)
- x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(mysql.TypeDouble)
- x.Flag |= mysql.BinaryFlag
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- $$ = x
- }
- | "FLOAT" FloatOpt
- {
- x := types.NewFieldType(mysql.TypeFloat)
- fopt := $2.(*ast.FloatOpt)
- if fopt.Flen >= 54 {
- yylex.AppendError(ErrTooBigPrecision.GenWithStackByArgs(fopt.Flen, "CAST", 53))
- } else if fopt.Flen >= 25 {
- x = types.NewFieldType(mysql.TypeDouble)
- }
- x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(x.Tp)
- x.Flag |= mysql.BinaryFlag
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- $$ = x
- }
- | "REAL"
- {
- var x *types.FieldType
- if parser.lexer.GetSQLMode().HasRealAsFloatMode() {
- x = types.NewFieldType(mysql.TypeFloat)
- } else {
- x = types.NewFieldType(mysql.TypeDouble)
- }
- x.Flen, x.Decimal = mysql.GetDefaultFieldLengthAndDecimalForCast(x.Tp)
- x.Flag |= mysql.BinaryFlag
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- $$ = x
- }
- Priority:
- "LOW_PRIORITY"
- {
- $$ = mysql.LowPriority
- }
- | "HIGH_PRIORITY"
- {
- $$ = mysql.HighPriority
- }
- | "DELAYED"
- {
- $$ = mysql.DelayedPriority
- }
- PriorityOpt:
- {
- $$ = mysql.NoPriority
- }
- | Priority
- TableName:
- Identifier
- {
- $$ = &ast.TableName{Name: model.NewCIStr($1)}
- }
- | Identifier '.' Identifier
- {
- $$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)}
- }
- TableNameList:
- TableName
- {
- tbl := []*ast.TableName{$1.(*ast.TableName)}
- $$ = tbl
- }
- | TableNameList ',' TableName
- {
- $$ = append($1.([]*ast.TableName), $3.(*ast.TableName))
- }
- TableNameOptWild:
- Identifier OptWild
- {
- $$ = &ast.TableName{Name: model.NewCIStr($1)}
- }
- | Identifier '.' Identifier OptWild
- {
- $$ = &ast.TableName{Schema: model.NewCIStr($1), Name: model.NewCIStr($3)}
- }
- TableAliasRefList:
- TableNameOptWild
- {
- tbl := []*ast.TableName{$1.(*ast.TableName)}
- $$ = tbl
- }
- | TableAliasRefList ',' TableNameOptWild
- {
- $$ = append($1.([]*ast.TableName), $3.(*ast.TableName))
- }
- OptWild:
- %prec empty
- {}
- | '.' '*'
- {}
- QuickOptional:
- %prec empty
- {
- $$ = false
- }
- | "QUICK"
- {
- $$ = true
- }
- /***************************Prepared Statement Start******************************
- * See https://dev.mysql.com/doc/refman/5.7/en/prepare.html
- * Example:
- * PREPARE stmt_name FROM 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
- * OR
- * SET @s = 'SELECT SQRT(POW(?,2) + POW(?,2)) AS hypotenuse';
- * PREPARE stmt_name FROM @s;
- */
- PreparedStmt:
- "PREPARE" Identifier "FROM" PrepareSQL
- {
- var sqlText string
- var sqlVar *ast.VariableExpr
- switch x := $4.(type) {
- case string:
- sqlText = x
- case *ast.VariableExpr:
- sqlVar = x
- }
- $$ = &ast.PrepareStmt{
- Name: $2,
- SQLText: sqlText,
- SQLVar: sqlVar,
- }
- }
- PrepareSQL:
- stringLit
- {
- $$ = $1
- }
- | UserVariable
- {
- $$ = $1
- }
- /*
- * See https://dev.mysql.com/doc/refman/5.7/en/execute.html
- * Example:
- * EXECUTE stmt1 USING @a, @b;
- * OR
- * EXECUTE stmt1;
- */
- ExecuteStmt:
- "EXECUTE" Identifier
- {
- $$ = &ast.ExecuteStmt{Name: $2}
- }
- | "EXECUTE" Identifier "USING" UserVariableList
- {
- $$ = &ast.ExecuteStmt{
- Name: $2,
- UsingVars: $4.([]ast.ExprNode),
- }
- }
- UserVariableList:
- UserVariable
- {
- $$ = []ast.ExprNode{$1}
- }
- | UserVariableList ',' UserVariable
- {
- $$ = append($1.([]ast.ExprNode), $3)
- }
- DeallocateStmt:
- DeallocateSym "PREPARE" Identifier
- {
- $$ = &ast.DeallocateStmt{Name: $3}
- }
- DeallocateSym:
- "DEALLOCATE"
- | "DROP"
- RollbackStmt:
- "ROLLBACK"
- {
- $$ = &ast.RollbackStmt{}
- }
- | "ROLLBACK" CompletionTypeWithinTransaction
- {
- $$ = &ast.RollbackStmt{CompletionType: $2.(ast.CompletionType)}
- }
- CompletionTypeWithinTransaction:
- "AND" "CHAIN" "NO" "RELEASE"
- {
- $$ = ast.CompletionTypeChain
- }
- | "AND" "NO" "CHAIN" "RELEASE"
- {
- $$ = ast.CompletionTypeRelease
- }
- | "AND" "NO" "CHAIN" "NO" "RELEASE"
- {
- $$ = ast.CompletionTypeDefault
- }
- | "AND" "CHAIN"
- {
- $$ = ast.CompletionTypeChain
- }
- | "AND" "NO" "CHAIN"
- {
- $$ = ast.CompletionTypeDefault
- }
- | "RELEASE"
- {
- $$ = ast.CompletionTypeRelease
- }
- | "NO" "RELEASE"
- {
- $$ = ast.CompletionTypeDefault
- }
- ShutdownStmt:
- "SHUTDOWN"
- {
- $$ = &ast.ShutdownStmt{}
- }
- SelectStmtBasic:
- "SELECT" SelectStmtOpts SelectStmtFieldList
- {
- st := &ast.SelectStmt{
- SelectStmtOpts: $2.(*ast.SelectStmtOpts),
- Distinct: $2.(*ast.SelectStmtOpts).Distinct,
- Fields: $3.(*ast.FieldList),
- Kind: ast.SelectStmtKindSelect,
- }
- if st.SelectStmtOpts.TableHints != nil {
- st.TableHints = st.SelectStmtOpts.TableHints
- }
- $$ = st
- }
- SelectStmtFromDualTable:
- SelectStmtBasic FromDual WhereClauseOptional
- {
- st := $1.(*ast.SelectStmt)
- lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
- if lastField.Expr != nil && lastField.AsName.O == "" {
- lastEnd := yyS[yypt-1].offset - 1
- lastField.SetText(parser.src[lastField.Offset:lastEnd])
- }
- if $3 != nil {
- st.Where = $3.(ast.ExprNode)
- }
- }
- SelectStmtFromTable:
- SelectStmtBasic "FROM" TableRefsClause WhereClauseOptional SelectStmtGroup HavingClause WindowClauseOptional
- {
- st := $1.(*ast.SelectStmt)
- st.From = $3.(*ast.TableRefsClause)
- lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
- if lastField.Expr != nil && lastField.AsName.O == "" {
- lastEnd := parser.endOffset(&yyS[yypt-5])
- lastField.SetText(parser.src[lastField.Offset:lastEnd])
- }
- if $4 != nil {
- st.Where = $4.(ast.ExprNode)
- }
- if $5 != nil {
- st.GroupBy = $5.(*ast.GroupByClause)
- }
- if $6 != nil {
- st.Having = $6.(*ast.HavingClause)
- }
- if $7 != nil {
- st.WindowSpecs = ($7.([]ast.WindowSpec))
- }
- $$ = st
- }
- TableSampleOpt:
- %prec empty
- {
- $$ = nil
- }
- | "TABLESAMPLE" TableSampleMethodOpt '(' Expression TableSampleUnitOpt ')' RepeatableOpt
- {
- var repSeed ast.ExprNode
- if $7 != nil {
- repSeed = ast.NewValueExpr($7, parser.charset, parser.collation)
- }
- $$ = &ast.TableSample{
- SampleMethod: $2.(ast.SampleMethodType),
- Expr: ast.NewValueExpr($4, parser.charset, parser.collation),
- SampleClauseUnit: $5.(ast.SampleClauseUnitType),
- RepeatableSeed: repSeed,
- }
- }
- | "TABLESAMPLE" TableSampleMethodOpt '(' ')' RepeatableOpt
- {
- var repSeed ast.ExprNode
- if $5 != nil {
- repSeed = ast.NewValueExpr($5, parser.charset, parser.collation)
- }
- $$ = &ast.TableSample{
- SampleMethod: $2.(ast.SampleMethodType),
- RepeatableSeed: repSeed,
- }
- }
- TableSampleMethodOpt:
- %prec empty
- {
- $$ = ast.SampleMethodTypeNone
- }
- | "SYSTEM"
- {
- $$ = ast.SampleMethodTypeSystem
- }
- | "BERNOULLI"
- {
- $$ = ast.SampleMethodTypeBernoulli
- }
- | "REGIONS"
- {
- $$ = ast.SampleMethodTypeTiDBRegion
- }
- TableSampleUnitOpt:
- %prec empty
- {
- $$ = ast.SampleClauseUnitTypeDefault
- }
- | "ROWS"
- {
- $$ = ast.SampleClauseUnitTypeRow
- }
- | "PERCENT"
- {
- $$ = ast.SampleClauseUnitTypePercent
- }
- RepeatableOpt:
- %prec empty
- {
- $$ = nil
- }
- | "REPEATABLE" '(' Expression ')'
- {
- $$ = $3
- }
- SelectStmt:
- SelectStmtNoWith
- | WithClause SelectStmtNoWith
- {
- st := $2.(*ast.SelectStmt)
- st.With = $1.(*ast.WithClause)
- $$ = st
- }
- SelectStmtNoWith:
- SelectStmtBasic WhereClauseOptional OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
- {
- st := $1.(*ast.SelectStmt)
- if $5 != nil {
- st.LockInfo = $5.(*ast.SelectLockInfo)
- }
- lastField := st.Fields.Fields[len(st.Fields.Fields)-1]
- if lastField.Expr != nil && lastField.AsName.O == "" {
- src := parser.src
- var lastEnd int
- if $2 != nil {
- lastEnd = yyS[yypt-4].offset - 1
- } else if $3 != nil {
- lastEnd = yyS[yypt-3].offset - 1
- } else if $4 != nil {
- lastEnd = yyS[yypt-2].offset - 1
- } else if st.LockInfo != nil && st.LockInfo.LockType != ast.SelectLockNone {
- lastEnd = yyS[yypt-1].offset - 1
- } else if $6 != nil {
- lastEnd = yyS[yypt].offset - 1
- } else {
- lastEnd = len(src)
- if src[lastEnd-1] == ';' {
- lastEnd--
- }
- }
- lastField.SetText(src[lastField.Offset:lastEnd])
- }
- if $2 != nil {
- st.Where = $2.(ast.ExprNode)
- }
- if $3 != nil {
- st.OrderBy = $3.(*ast.OrderByClause)
- }
- if $4 != nil {
- st.Limit = $4.(*ast.Limit)
- }
- if $6 != nil {
- st.SelectIntoOpt = $6.(*ast.SelectIntoOption)
- }
- $$ = st
- }
- | SelectStmtFromDualTable OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
- {
- st := $1.(*ast.SelectStmt)
- if $2 != nil {
- st.OrderBy = $2.(*ast.OrderByClause)
- }
- if $3 != nil {
- st.Limit = $3.(*ast.Limit)
- }
- if $4 != nil {
- st.LockInfo = $4.(*ast.SelectLockInfo)
- }
- if $5 != nil {
- st.SelectIntoOpt = $5.(*ast.SelectIntoOption)
- }
- $$ = st
- }
- | SelectStmtFromTable OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
- {
- st := $1.(*ast.SelectStmt)
- if $4 != nil {
- st.LockInfo = $4.(*ast.SelectLockInfo)
- }
- if $2 != nil {
- st.OrderBy = $2.(*ast.OrderByClause)
- }
- if $3 != nil {
- st.Limit = $3.(*ast.Limit)
- }
- if $5 != nil {
- st.SelectIntoOpt = $5.(*ast.SelectIntoOption)
- }
- $$ = st
- }
- | "TABLE" TableName OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
- {
- st := &ast.SelectStmt{
- Kind: ast.SelectStmtKindTable,
- Fields: &ast.FieldList{Fields: []*ast.SelectField{{WildCard: &ast.WildCardField{}}}},
- }
- ts := &ast.TableSource{Source: $2.(*ast.TableName)}
- st.From = &ast.TableRefsClause{TableRefs: &ast.Join{Left: ts}}
- if $3 != nil {
- st.OrderBy = $3.(*ast.OrderByClause)
- }
- if $4 != nil {
- st.Limit = $4.(*ast.Limit)
- }
- if $5 != nil {
- st.LockInfo = $5.(*ast.SelectLockInfo)
- }
- if $6 != nil {
- st.SelectIntoOpt = $6.(*ast.SelectIntoOption)
- }
- $$ = st
- }
- | "VALUES" ValuesStmtList OrderByOptional SelectStmtLimitOpt SelectLockOpt SelectStmtIntoOption
- {
- st := &ast.SelectStmt{
- Kind: ast.SelectStmtKindValues,
- Fields: &ast.FieldList{Fields: []*ast.SelectField{{WildCard: &ast.WildCardField{}}}},
- Lists: $2.([]*ast.RowExpr),
- }
- if $3 != nil {
- st.OrderBy = $3.(*ast.OrderByClause)
- }
- if $4 != nil {
- st.Limit = $4.(*ast.Limit)
- }
- if $5 != nil {
- st.LockInfo = $5.(*ast.SelectLockInfo)
- }
- if $6 != nil {
- st.SelectIntoOpt = $6.(*ast.SelectIntoOption)
- }
- $$ = st
- }
- WithClause:
- "WITH" WithList
- {
- $$ = $2
- }
- | "WITH" recursive WithList
- {
- ws := $3.(*ast.WithClause)
- ws.IsRecursive = true
- $$ = ws
- }
- WithList:
- WithList ',' CommonTableExpr
- {
- ws := $1.(*ast.WithClause)
- ws.CTEs = append(ws.CTEs, $3.(*ast.CommonTableExpression))
- $$ = ws
- }
- | CommonTableExpr
- {
- ws := &ast.WithClause{}
- ws.CTEs = make([]*ast.CommonTableExpression, 0, 4)
- ws.CTEs = append(ws.CTEs, $1.(*ast.CommonTableExpression))
- $$ = ws
- }
- CommonTableExpr:
- Identifier IdentListWithParenOpt "AS" SubSelect
- {
- cte := &ast.CommonTableExpression{}
- cte.Name = model.NewCIStr($1)
- cte.ColNameList = $2.([]model.CIStr)
- cte.Query = $4.(*ast.SubqueryExpr)
- $$ = cte
- }
- FromDual:
- "FROM" "DUAL"
- WindowClauseOptional:
- {
- $$ = nil
- }
- | "WINDOW" WindowDefinitionList
- {
- $$ = $2.([]ast.WindowSpec)
- }
- WindowDefinitionList:
- WindowDefinition
- {
- $$ = []ast.WindowSpec{$1.(ast.WindowSpec)}
- }
- | WindowDefinitionList ',' WindowDefinition
- {
- $$ = append($1.([]ast.WindowSpec), $3.(ast.WindowSpec))
- }
- WindowDefinition:
- WindowName "AS" WindowSpec
- {
- var spec = $3.(ast.WindowSpec)
- spec.Name = $1.(model.CIStr)
- $$ = spec
- }
- WindowName:
- Identifier
- {
- $$ = model.NewCIStr($1)
- }
- WindowSpec:
- '(' WindowSpecDetails ')'
- {
- $$ = $2.(ast.WindowSpec)
- }
- WindowSpecDetails:
- OptExistingWindowName OptPartitionClause OptWindowOrderByClause OptWindowFrameClause
- {
- spec := ast.WindowSpec{Ref: $1.(model.CIStr)}
- if $2 != nil {
- spec.PartitionBy = $2.(*ast.PartitionByClause)
- }
- if $3 != nil {
- spec.OrderBy = $3.(*ast.OrderByClause)
- }
- if $4 != nil {
- spec.Frame = $4.(*ast.FrameClause)
- }
- $$ = spec
- }
- OptExistingWindowName:
- {
- $$ = model.CIStr{}
- }
- | WindowName
- OptPartitionClause:
- {
- $$ = nil
- }
- | "PARTITION" "BY" ByList
- {
- $$ = &ast.PartitionByClause{Items: $3.([]*ast.ByItem)}
- }
- OptWindowOrderByClause:
- {
- $$ = nil
- }
- | "ORDER" "BY" ByList
- {
- $$ = &ast.OrderByClause{Items: $3.([]*ast.ByItem)}
- }
- OptWindowFrameClause:
- {
- $$ = nil
- }
- | WindowFrameUnits WindowFrameExtent
- {
- $$ = &ast.FrameClause{
- Type: $1.(ast.FrameType),
- Extent: $2.(ast.FrameExtent),
- }
- }
- WindowFrameUnits:
- "ROWS"
- {
- $$ = ast.FrameType(ast.Rows)
- }
- | "RANGE"
- {
- $$ = ast.FrameType(ast.Ranges)
- }
- | "GROUPS"
- {
- $$ = ast.FrameType(ast.Groups)
- }
- WindowFrameExtent:
- WindowFrameStart
- {
- $$ = ast.FrameExtent{
- Start: $1.(ast.FrameBound),
- End: ast.FrameBound{Type: ast.CurrentRow},
- }
- }
- | WindowFrameBetween
- WindowFrameStart:
- "UNBOUNDED" "PRECEDING"
- {
- $$ = ast.FrameBound{Type: ast.Preceding, UnBounded: true}
- }
- | NumLiteral "PRECEDING"
- {
- $$ = ast.FrameBound{Type: ast.Preceding, Expr: ast.NewValueExpr($1, parser.charset, parser.collation)}
- }
- | paramMarker "PRECEDING"
- {
- $$ = ast.FrameBound{Type: ast.Preceding, Expr: ast.NewParamMarkerExpr(yyS[yypt].offset)}
- }
- | "INTERVAL" Expression TimeUnit "PRECEDING"
- {
- $$ = ast.FrameBound{Type: ast.Preceding, Expr: $2, Unit: $3.(ast.TimeUnitType)}
- }
- | "CURRENT" "ROW"
- {
- $$ = ast.FrameBound{Type: ast.CurrentRow}
- }
- WindowFrameBetween:
- "BETWEEN" WindowFrameBound "AND" WindowFrameBound
- {
- $$ = ast.FrameExtent{Start: $2.(ast.FrameBound), End: $4.(ast.FrameBound)}
- }
- WindowFrameBound:
- WindowFrameStart
- | "UNBOUNDED" "FOLLOWING"
- {
- $$ = ast.FrameBound{Type: ast.Following, UnBounded: true}
- }
- | NumLiteral "FOLLOWING"
- {
- $$ = ast.FrameBound{Type: ast.Following, Expr: ast.NewValueExpr($1, parser.charset, parser.collation)}
- }
- | paramMarker "FOLLOWING"
- {
- $$ = ast.FrameBound{Type: ast.Following, Expr: ast.NewParamMarkerExpr(yyS[yypt].offset)}
- }
- | "INTERVAL" Expression TimeUnit "FOLLOWING"
- {
- $$ = ast.FrameBound{Type: ast.Following, Expr: $2, Unit: $3.(ast.TimeUnitType)}
- }
- OptWindowingClause:
- {
- $$ = nil
- }
- | WindowingClause
- {
- spec := $1.(ast.WindowSpec)
- $$ = &spec
- }
- WindowingClause:
- "OVER" WindowNameOrSpec
- {
- $$ = $2.(ast.WindowSpec)
- }
- WindowNameOrSpec:
- WindowName
- {
- $$ = ast.WindowSpec{Name: $1.(model.CIStr), OnlyAlias: true}
- }
- | WindowSpec
- WindowFuncCall:
- "ROW_NUMBER" '(' ')' WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
- }
- | "RANK" '(' ')' WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
- }
- | "DENSE_RANK" '(' ')' WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
- }
- | "CUME_DIST" '(' ')' WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
- }
- | "PERCENT_RANK" '(' ')' WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Spec: $4.(ast.WindowSpec)}
- }
- | "NTILE" '(' SimpleExpr ')' WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, Spec: $5.(ast.WindowSpec)}
- }
- | "LEAD" '(' Expression OptLeadLagInfo ')' OptNullTreatment WindowingClause
- {
- args := []ast.ExprNode{$3}
- if $4 != nil {
- args = append(args, $4.([]ast.ExprNode)...)
- }
- $$ = &ast.WindowFuncExpr{F: $1, Args: args, IgnoreNull: $6.(bool), Spec: $7.(ast.WindowSpec)}
- }
- | "LAG" '(' Expression OptLeadLagInfo ')' OptNullTreatment WindowingClause
- {
- args := []ast.ExprNode{$3}
- if $4 != nil {
- args = append(args, $4.([]ast.ExprNode)...)
- }
- $$ = &ast.WindowFuncExpr{F: $1, Args: args, IgnoreNull: $6.(bool), Spec: $7.(ast.WindowSpec)}
- }
- | "FIRST_VALUE" '(' Expression ')' OptNullTreatment WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, IgnoreNull: $5.(bool), Spec: $6.(ast.WindowSpec)}
- }
- | "LAST_VALUE" '(' Expression ')' OptNullTreatment WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3}, IgnoreNull: $5.(bool), Spec: $6.(ast.WindowSpec)}
- }
- | "NTH_VALUE" '(' Expression ',' SimpleExpr ')' OptFromFirstLast OptNullTreatment WindowingClause
- {
- $$ = &ast.WindowFuncExpr{F: $1, Args: []ast.ExprNode{$3, $5}, FromLast: $7.(bool), IgnoreNull: $8.(bool), Spec: $9.(ast.WindowSpec)}
- }
- OptLeadLagInfo:
- {
- $$ = nil
- }
- | ',' NumLiteral OptLLDefault
- {
- args := []ast.ExprNode{ast.NewValueExpr($2, parser.charset, parser.collation)}
- if $3 != nil {
- args = append(args, $3.(ast.ExprNode))
- }
- $$ = args
- }
- | ',' paramMarker OptLLDefault
- {
- args := []ast.ExprNode{ast.NewValueExpr($2, parser.charset, parser.collation)}
- if $3 != nil {
- args = append(args, $3.(ast.ExprNode))
- }
- $$ = args
- }
- OptLLDefault:
- {
- $$ = nil
- }
- | ',' Expression
- {
- $$ = $2
- }
- OptNullTreatment:
- {
- $$ = false
- }
- | "RESPECT" "NULLS"
- {
- $$ = false
- }
- | "IGNORE" "NULLS"
- {
- $$ = true
- }
- OptFromFirstLast:
- {
- $$ = false
- }
- | "FROM" "FIRST"
- {
- $$ = false
- }
- | "FROM" "LAST"
- {
- $$ = true
- }
- TableRefsClause:
- TableRefs
- {
- $$ = &ast.TableRefsClause{TableRefs: $1.(*ast.Join)}
- }
- TableRefs:
- EscapedTableRef
- {
- if j, ok := $1.(*ast.Join); ok {
- // if $1 is Join, use it directly
- $$ = j
- } else {
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: nil}
- }
- }
- | TableRefs ',' EscapedTableRef
- {
- /* from a, b is default cross join */
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin}
- }
- EscapedTableRef:
- TableRef %prec lowerThanSetKeyword
- | '{' Identifier TableRef '}'
- {
- /*
- * ODBC escape syntax for outer join is { OJ join_table }
- * Use an Identifier for OJ
- */
- $$ = $3
- }
- TableRef:
- TableFactor
- | JoinTable
- TableFactor:
- TableName PartitionNameListOpt TableAsNameOpt IndexHintListOpt TableSampleOpt
- {
- tn := $1.(*ast.TableName)
- tn.PartitionNames = $2.([]model.CIStr)
- tn.IndexHints = $4.([]*ast.IndexHint)
- if $5 != nil {
- tn.TableSample = $5.(*ast.TableSample)
- }
- $$ = &ast.TableSource{Source: tn, AsName: $3.(model.CIStr)}
- }
- | '(' SetOprStmt1 ')' TableAsNameOpt
- {
- if st, isSel := $2.(*ast.SelectStmt); isSel {
- endOffset := parser.endOffset(&yyS[yypt-1])
- parser.setLastSelectFieldText(st, endOffset)
- }
- $$ = &ast.TableSource{Source: $2.(ast.ResultSetNode), AsName: $4.(model.CIStr)}
- }
- | '(' TableRefs ')'
- {
- j := $2.(*ast.Join)
- j.ExplicitParens = true
- $$ = $2
- }
- PartitionNameListOpt:
- /* empty */
- {
- $$ = []model.CIStr{}
- }
- | "PARTITION" '(' PartitionNameList ')'
- {
- $$ = $3
- }
- TableAsNameOpt:
- {
- $$ = model.CIStr{}
- }
- | TableAsName
- TableAsName:
- Identifier
- {
- $$ = model.NewCIStr($1)
- }
- | "AS" Identifier
- {
- $$ = model.NewCIStr($2)
- }
- IndexHintType:
- "USE" KeyOrIndex
- {
- $$ = ast.HintUse
- }
- | "IGNORE" KeyOrIndex
- {
- $$ = ast.HintIgnore
- }
- | "FORCE" KeyOrIndex
- {
- $$ = ast.HintForce
- }
- IndexHintScope:
- {
- $$ = ast.HintForScan
- }
- | "FOR" "JOIN"
- {
- $$ = ast.HintForJoin
- }
- | "FOR" "ORDER" "BY"
- {
- $$ = ast.HintForOrderBy
- }
- | "FOR" "GROUP" "BY"
- {
- $$ = ast.HintForGroupBy
- }
- IndexHint:
- IndexHintType IndexHintScope '(' IndexNameList ')'
- {
- $$ = &ast.IndexHint{
- IndexNames: $4.([]model.CIStr),
- HintType: $1.(ast.IndexHintType),
- HintScope: $2.(ast.IndexHintScope),
- }
- }
- IndexNameList:
- {
- var nameList []model.CIStr
- $$ = nameList
- }
- | Identifier
- {
- $$ = []model.CIStr{model.NewCIStr($1)}
- }
- | IndexNameList ',' Identifier
- {
- $$ = append($1.([]model.CIStr), model.NewCIStr($3))
- }
- | "PRIMARY"
- {
- $$ = []model.CIStr{model.NewCIStr($1)}
- }
- | IndexNameList ',' "PRIMARY"
- {
- $$ = append($1.([]model.CIStr), model.NewCIStr($3))
- }
- IndexHintList:
- IndexHint
- {
- $$ = []*ast.IndexHint{$1.(*ast.IndexHint)}
- }
- | IndexHintList IndexHint
- {
- $$ = append($1.([]*ast.IndexHint), $2.(*ast.IndexHint))
- }
- IndexHintListOpt:
- {
- $$ = []*ast.IndexHint{}
- }
- | IndexHintList
- JoinTable:
- /* Use %prec to evaluate production TableRef before cross join */
- TableRef CrossOpt TableRef %prec tableRefPriority
- {
- $$ = ast.NewCrossJoin($1.(ast.ResultSetNode), $3.(ast.ResultSetNode))
- }
- | TableRef CrossOpt TableRef "ON" Expression
- {
- on := &ast.OnCondition{Expr: $5}
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, On: on}
- }
- | TableRef CrossOpt TableRef "USING" '(' ColumnNameList ')'
- {
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), Tp: ast.CrossJoin, Using: $6.([]*ast.ColumnName)}
- }
- | TableRef JoinType OuterOpt "JOIN" TableRef "ON" Expression
- {
- on := &ast.OnCondition{Expr: $7}
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), On: on}
- }
- | TableRef JoinType OuterOpt "JOIN" TableRef "USING" '(' ColumnNameList ')'
- {
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $5.(ast.ResultSetNode), Tp: $2.(ast.JoinType), Using: $8.([]*ast.ColumnName)}
- }
- | TableRef "NATURAL" "JOIN" TableRef
- {
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $4.(ast.ResultSetNode), NaturalJoin: true}
- }
- | TableRef "NATURAL" JoinType OuterOpt "JOIN" TableRef
- {
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $6.(ast.ResultSetNode), Tp: $3.(ast.JoinType), NaturalJoin: true}
- }
- | TableRef "STRAIGHT_JOIN" TableRef
- {
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true}
- }
- | TableRef "STRAIGHT_JOIN" TableRef "ON" Expression
- {
- on := &ast.OnCondition{Expr: $5}
- $$ = &ast.Join{Left: $1.(ast.ResultSetNode), Right: $3.(ast.ResultSetNode), StraightJoin: true, On: on}
- }
- JoinType:
- "LEFT"
- {
- $$ = ast.LeftJoin
- }
- | "RIGHT"
- {
- $$ = ast.RightJoin
- }
- OuterOpt:
- {}
- | "OUTER"
- CrossOpt:
- "JOIN"
- | "CROSS" "JOIN"
- | "INNER" "JOIN"
- LimitClause:
- {
- $$ = nil
- }
- | "LIMIT" LimitOption
- {
- $$ = &ast.Limit{Count: $2.(ast.ValueExpr)}
- }
- LimitOption:
- LengthNum
- {
- $$ = ast.NewValueExpr($1, parser.charset, parser.collation)
- }
- | paramMarker
- {
- $$ = ast.NewParamMarkerExpr(yyS[yypt].offset)
- }
- RowOrRows:
- "ROW"
- | "ROWS"
- FirstOrNext:
- "FIRST"
- | "NEXT"
- FetchFirstOpt:
- {
- $$ = ast.NewValueExpr(uint64(1), parser.charset, parser.collation)
- }
- | LimitOption
- SelectStmtLimit:
- "LIMIT" LimitOption
- {
- $$ = &ast.Limit{Count: $2.(ast.ExprNode)}
- }
- | "LIMIT" LimitOption ',' LimitOption
- {
- $$ = &ast.Limit{Offset: $2.(ast.ExprNode), Count: $4.(ast.ExprNode)}
- }
- | "LIMIT" LimitOption "OFFSET" LimitOption
- {
- $$ = &ast.Limit{Offset: $4.(ast.ExprNode), Count: $2.(ast.ExprNode)}
- }
- | "FETCH" FirstOrNext FetchFirstOpt RowOrRows "ONLY"
- {
- $$ = &ast.Limit{Count: $3.(ast.ExprNode)}
- }
- SelectStmtLimitOpt:
- {
- $$ = nil
- }
- | SelectStmtLimit
- SelectStmtOpt:
- TableOptimizerHints
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.TableHints = $1.([]*ast.TableOptimizerHint)
- $$ = opt
- }
- | DistinctOpt
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- if $1.(bool) {
- opt.Distinct = true
- } else {
- opt.Distinct = false
- opt.ExplicitAll = true
- }
- $$ = opt
- }
- | Priority
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.Priority = $1.(mysql.PriorityEnum)
- $$ = opt
- }
- | "SQL_SMALL_RESULT"
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.SQLSmallResult = true
- $$ = opt
- }
- | "SQL_BIG_RESULT"
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.SQLBigResult = true
- $$ = opt
- }
- | "SQL_BUFFER_RESULT"
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.SQLBufferResult = true
- $$ = opt
- }
- | SelectStmtSQLCache
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = $1.(bool)
- $$ = opt
- }
- | "SQL_CALC_FOUND_ROWS"
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.CalcFoundRows = true
- $$ = opt
- }
- | "STRAIGHT_JOIN"
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- opt.StraightJoin = true
- $$ = opt
- }
- SelectStmtOpts:
- %prec empty
- {
- opt := &ast.SelectStmtOpts{}
- opt.SQLCache = true
- $$ = opt
- }
- | SelectStmtOptsList %prec lowerThanSelectOpt
- SelectStmtOptsList:
- SelectStmtOptsList SelectStmtOpt
- {
- opts := $1.(*ast.SelectStmtOpts)
- opt := $2.(*ast.SelectStmtOpts)
- // Merge options.
- // Always use the first hint.
- if opt.TableHints != nil && opts.TableHints == nil {
- opts.TableHints = opt.TableHints
- }
- if opt.Distinct {
- opts.Distinct = true
- }
- if opt.Priority != mysql.NoPriority {
- opts.Priority = opt.Priority
- }
- if opt.SQLSmallResult {
- opts.SQLSmallResult = true
- }
- if opt.SQLBigResult {
- opts.SQLBigResult = true
- }
- if opt.SQLBufferResult {
- opts.SQLBufferResult = true
- }
- if !opt.SQLCache {
- opts.SQLCache = false
- }
- if opt.CalcFoundRows {
- opts.CalcFoundRows = true
- }
- if opt.StraightJoin {
- opts.StraightJoin = true
- }
- if opt.ExplicitAll {
- opts.ExplicitAll = true
- }
- if opts.Distinct && opts.ExplicitAll {
- yylex.AppendError(ErrWrongUsage.GenWithStackByArgs("ALL", "DISTINCT"))
- return 1
- }
- $$ = opts
- }
- | SelectStmtOpt
- TableOptimizerHints:
- hintComment
- {
- hints, warns := parser.parseHint($1)
- for _, w := range warns {
- yylex.AppendError(w)
- parser.lastErrorAsWarn()
- }
- $$ = hints
- }
- TableOptimizerHintsOpt:
- /* empty */
- {
- $$ = nil
- }
- | TableOptimizerHints
- SelectStmtSQLCache:
- "SQL_CACHE"
- {
- $$ = true
- }
- | "SQL_NO_CACHE"
- {
- $$ = false
- }
- SelectStmtFieldList:
- FieldList
- {
- $$ = &ast.FieldList{Fields: $1.([]*ast.SelectField)}
- }
- SelectStmtGroup:
- /* EMPTY */
- {
- $$ = nil
- }
- | GroupByClause
- SelectStmtIntoOption:
- {
- $$ = nil
- }
- | "INTO" "OUTFILE" stringLit Fields Lines
- {
- x := &ast.SelectIntoOption{
- Tp: ast.SelectIntoOutfile,
- FileName: $3,
- }
- if $4 != nil {
- x.FieldsInfo = $4.(*ast.FieldsClause)
- }
- if $5 != nil {
- x.LinesInfo = $5.(*ast.LinesClause)
- }
- $$ = x
- }
- // See https://dev.mysql.com/doc/refman/5.7/en/subqueries.html
- SubSelect:
- '(' SetOprStmt1 ')'
- {
- if s, isSel := $2.(*ast.SelectStmt); isSel {
- endOffset := parser.endOffset(&yyS[yypt])
- parser.setLastSelectFieldText(s, endOffset)
- }
- rs := $2.(ast.ResultSetNode)
- src := parser.src
- // See the implementation of yyParse function
- rs.SetText(src[yyS[yypt-1].offset:yyS[yypt].offset])
- $$ = &ast.SubqueryExpr{Query: rs}
- }
- SubSelect2:
- '(' SetOprStmt2 ')'
- {
- if s, isSel := $2.(*ast.SelectStmt); isSel {
- endOffset := parser.endOffset(&yyS[yypt])
- parser.setLastSelectFieldText(s, endOffset)
- }
- rs := $2.(ast.ResultSetNode)
- src := parser.src
- // See the implementation of yyParse function
- rs.SetText(src[yyS[yypt-1].offset:yyS[yypt].offset])
- $$ = &ast.SubqueryExpr{Query: rs}
- }
- // See https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html
- SelectLockOpt:
- /* empty */
- {
- $$ = nil
- }
- | "FOR" "UPDATE"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForUpdate}
- }
- | "FOR" "SHARE"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShare}
- }
- | "FOR" "UPDATE" "NOWAIT"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForUpdateNoWait}
- }
- | "FOR" "UPDATE" "WAIT" NUM
- {
- $$ = &ast.SelectLockInfo{
- LockType: ast.SelectLockForUpdateWaitN,
- WaitSec: getUint64FromNUM($4),
- }
- }
- | "FOR" "SHARE" "NOWAIT"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShareNoWait}
- }
- | "FOR" "UPDATE" "SKIP" "LOCKED"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForUpdateSkipLocked}
- }
- | "FOR" "SHARE" "SKIP" "LOCKED"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShareSkipLocked}
- }
- | "LOCK" "IN" "SHARE" "MODE"
- {
- $$ = &ast.SelectLockInfo{LockType: ast.SelectLockForShare}
- }
- SetOprStmt1:
- SetOprClauseList %prec lowerThanParenthese
- {
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: $1.([]ast.Node)}}
- lastSelect := setOpr.SelectList.Selects[len(setOpr.SelectList.Selects)-1]
- if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && len(setOpr.SelectList.Selects) == 1 {
- $$ = sel
- } else {
- if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && !sel.IsInBraces {
- setOpr.OrderBy = sel.OrderBy
- setOpr.Limit = sel.Limit
- sel.OrderBy = nil
- sel.Limit = nil
- }
- $$ = setOpr
- }
- }
- | SetOprStmt
- SetOprStmt2:
- SetOprClauseList %prec higherThanParenthese
- {
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: $1.([]ast.Node)}}
- lastSelect := setOpr.SelectList.Selects[len(setOpr.SelectList.Selects)-1]
- if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && len(setOpr.SelectList.Selects) == 1 {
- $$ = sel
- } else {
- if sel, isSelect := lastSelect.(*ast.SelectStmt); isSelect && !sel.IsInBraces {
- setOpr.OrderBy = sel.OrderBy
- setOpr.Limit = sel.Limit
- sel.OrderBy = nil
- sel.Limit = nil
- }
- $$ = setOpr
- }
- }
- | SetOprStmt
- // See https://dev.mysql.com/doc/refman/5.7/en/union.html
- // See https://mariadb.com/kb/en/intersect/
- // See https://mariadb.com/kb/en/except/
- SetOprStmt:
- SetOprClauseList SetOpr '(' SetOprClauseList ')' OrderBy
- {
- setOprList1 := $1.([]ast.Node)
- setOprList2 := $4.([]ast.Node)
- if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
- endOffset := parser.endOffset(&yyS[yypt-4])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2}
- nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType)
- setOprList := append(setOprList1, nextSetOprList)
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}}
- setOpr.OrderBy = $6.(*ast.OrderByClause)
- $$ = setOpr
- }
- | SetOprClauseList SetOpr '(' SetOprClauseList ')' SelectStmtLimit
- {
- setOprList1 := $1.([]ast.Node)
- setOprList2 := $4.([]ast.Node)
- if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
- endOffset := parser.endOffset(&yyS[yypt-4])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2}
- nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType)
- setOprList := append(setOprList1, nextSetOprList)
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}}
- setOpr.Limit = $6.(*ast.Limit)
- $$ = setOpr
- }
- | SetOprClauseList SetOpr '(' SetOprClauseList ')' OrderBy SelectStmtLimit
- {
- setOprList1 := $1.([]ast.Node)
- setOprList2 := $4.([]ast.Node)
- if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
- endOffset := parser.endOffset(&yyS[yypt-5])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- nextSetOprList := &ast.SetOprSelectList{Selects: setOprList2}
- nextSetOprList.AfterSetOperator = $2.(*ast.SetOprType)
- setOprList := append(setOprList1, nextSetOprList)
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: setOprList}}
- setOpr.OrderBy = $6.(*ast.OrderByClause)
- setOpr.Limit = $7.(*ast.Limit)
- $$ = setOpr
- }
- | '(' SetOprClauseList ')' OrderBy
- {
- setOprList := $2.([]ast.Node)
- if sel, isSelect := setOprList[0].(*ast.SelectStmt); isSelect && !sel.IsInBraces && len(setOprList) == 1 {
- endOffset := parser.endOffset(&yyS[yypt-1])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: []ast.Node{&ast.SetOprSelectList{Selects: $2.([]ast.Node)}}}}
- setOpr.OrderBy = $4.(*ast.OrderByClause)
- $$ = setOpr
- }
- | '(' SetOprClauseList ')' SelectStmtLimit
- {
- setOprList := $2.([]ast.Node)
- if sel, isSelect := setOprList[0].(*ast.SelectStmt); isSelect && !sel.IsInBraces && len(setOprList) == 1 {
- endOffset := parser.endOffset(&yyS[yypt-1])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: []ast.Node{&ast.SetOprSelectList{Selects: setOprList}}}}
- setOpr.Limit = $4.(*ast.Limit)
- $$ = setOpr
- }
- | '(' SetOprClauseList ')' OrderBy SelectStmtLimit
- {
- setOprList := $2.([]ast.Node)
- if sel, isSelect := setOprList[0].(*ast.SelectStmt); isSelect && !sel.IsInBraces && len(setOprList) == 1 {
- endOffset := parser.endOffset(&yyS[yypt-2])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- setOpr := &ast.SetOprStmt{SelectList: &ast.SetOprSelectList{Selects: []ast.Node{&ast.SetOprSelectList{Selects: setOprList}}}}
- setOpr.OrderBy = $4.(*ast.OrderByClause)
- setOpr.Limit = $5.(*ast.Limit)
- $$ = setOpr
- }
- SetOprClauseList:
- SetOprClause
- | SetOprClauseList SetOpr SetOprClause
- {
- setOprList1 := $1.([]ast.Node)
- setOprList2 := $3.([]ast.Node)
- if sel, isSelect := setOprList1[len(setOprList1)-1].(*ast.SelectStmt); isSelect && !sel.IsInBraces {
- endOffset := parser.endOffset(&yyS[yypt-1])
- parser.setLastSelectFieldText(sel, endOffset)
- }
- switch x := setOprList2[0].(type) {
- case *ast.SelectStmt:
- x.AfterSetOperator = $2.(*ast.SetOprType)
- case *ast.SetOprSelectList:
- x.AfterSetOperator = $2.(*ast.SetOprType)
- }
- $$ = append(setOprList1, setOprList2...)
- }
- SetOprClause:
- SelectStmt
- {
- $$ = []ast.Node{$1.(*ast.SelectStmt)}
- }
- | '(' SetOprClauseList ')'
- {
- setList := $2.([]ast.Node)
- if sel, isSelect := setList[0].(*ast.SelectStmt); isSelect && len(setList) == 1 {
- endOffset := parser.endOffset(&yyS[yypt])
- parser.setLastSelectFieldText(sel, endOffset)
- sel.IsInBraces = true
- } else {
- setList = []ast.Node{&ast.SetOprSelectList{Selects: $2.([]ast.Node)}}
- }
- $$ = setList
- }
- SetOpr:
- "UNION" SetOprOpt
- {
- var tp ast.SetOprType
- tp = ast.Union
- if $2 == false {
- tp = ast.UnionAll
- }
- $$ = &tp
- }
- | "EXCEPT" SetOprOpt
- {
- var tp ast.SetOprType
- tp = ast.Except
- if $2 == false {
- tp = ast.ExceptAll
- }
- $$ = &tp
- }
- | "INTERSECT" SetOprOpt
- {
- var tp ast.SetOprType
- tp = ast.Intersect
- if $2 == false {
- tp = ast.IntersectAll
- }
- $$ = &tp
- }
- SetOprOpt:
- DefaultTrueDistinctOpt
- /********************Change Statement*******************************/
- ChangeStmt:
- "CHANGE" "PUMP" "TO" "NODE_STATE" eq stringLit forKwd "NODE_ID" stringLit
- {
- $$ = &ast.ChangeStmt{
- NodeType: ast.PumpType,
- State: $6,
- NodeID: $9,
- }
- }
- | "CHANGE" "DRAINER" "TO" "NODE_STATE" eq stringLit forKwd "NODE_ID" stringLit
- {
- $$ = &ast.ChangeStmt{
- NodeType: ast.DrainerType,
- State: $6,
- NodeID: $9,
- }
- }
- /********************Set Statement*******************************/
- SetStmt:
- "SET" VariableAssignmentList
- {
- $$ = &ast.SetStmt{Variables: $2.([]*ast.VariableAssignment)}
- }
- | "SET" "PASSWORD" eq PasswordOpt
- {
- $$ = &ast.SetPwdStmt{Password: $4}
- }
- | "SET" "PASSWORD" "FOR" Username eq PasswordOpt
- {
- $$ = &ast.SetPwdStmt{User: $4.(*auth.UserIdentity), Password: $6}
- }
- | "SET" "GLOBAL" "TRANSACTION" TransactionChars
- {
- vars := $4.([]*ast.VariableAssignment)
- for _, v := range vars {
- v.IsGlobal = true
- }
- $$ = &ast.SetStmt{Variables: vars}
- }
- | "SET" "SESSION" "TRANSACTION" TransactionChars
- {
- $$ = &ast.SetStmt{Variables: $4.([]*ast.VariableAssignment)}
- }
- | "SET" "TRANSACTION" TransactionChars
- {
- assigns := $3.([]*ast.VariableAssignment)
- for i := 0; i < len(assigns); i++ {
- if assigns[i].Name == "tx_isolation" {
- // A special session variable that make setting tx_isolation take effect one time.
- assigns[i].Name = "tx_isolation_one_shot"
- }
- }
- $$ = &ast.SetStmt{Variables: assigns}
- }
- | "SET" "CONFIG" Identifier ConfigItemName EqOrAssignmentEq SetExpr
- {
- $$ = &ast.SetConfigStmt{Type: strings.ToLower($3), Name: $4, Value: $6}
- }
- | "SET" "CONFIG" stringLit ConfigItemName EqOrAssignmentEq SetExpr
- {
- $$ = &ast.SetConfigStmt{Instance: $3, Name: $4, Value: $6}
- }
- SetRoleStmt:
- "SET" "ROLE" SetRoleOpt
- {
- $$ = $3.(*ast.SetRoleStmt)
- }
- SetDefaultRoleStmt:
- "SET" "DEFAULT" "ROLE" SetDefaultRoleOpt "TO" UsernameList
- {
- tmp := $4.(*ast.SetRoleStmt)
- $$ = &ast.SetDefaultRoleStmt{
- SetRoleOpt: tmp.SetRoleOpt,
- RoleList: tmp.RoleList,
- UserList: $6.([]*auth.UserIdentity),
- }
- }
- SetDefaultRoleOpt:
- "NONE"
- {
- $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleNone, RoleList: nil}
- }
- | "ALL"
- {
- $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleAll, RoleList: nil}
- }
- | RolenameList
- {
- $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleRegular, RoleList: $1.([]*auth.RoleIdentity)}
- }
- SetRoleOpt:
- "ALL" "EXCEPT" RolenameList
- {
- $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleAllExcept, RoleList: $3.([]*auth.RoleIdentity)}
- }
- | SetDefaultRoleOpt
- | "DEFAULT"
- {
- $$ = &ast.SetRoleStmt{SetRoleOpt: ast.SetRoleDefault, RoleList: nil}
- }
- TransactionChars:
- TransactionChar
- {
- if $1 != nil {
- $$ = $1
- } else {
- $$ = []*ast.VariableAssignment{}
- }
- }
- | TransactionChars ',' TransactionChar
- {
- if $3 != nil {
- varAssigns := $3.([]*ast.VariableAssignment)
- $$ = append($1.([]*ast.VariableAssignment), varAssigns...)
- } else {
- $$ = $1
- }
- }
- TransactionChar:
- "ISOLATION" "LEVEL" IsolationLevel
- {
- varAssigns := []*ast.VariableAssignment{}
- expr := ast.NewValueExpr($3, parser.charset, parser.collation)
- varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_isolation", Value: expr, IsSystem: true})
- $$ = varAssigns
- }
- | "READ" "WRITE"
- {
- varAssigns := []*ast.VariableAssignment{}
- expr := ast.NewValueExpr("0", parser.charset, parser.collation)
- varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_only", Value: expr, IsSystem: true})
- $$ = varAssigns
- }
- | "READ" "ONLY"
- {
- varAssigns := []*ast.VariableAssignment{}
- expr := ast.NewValueExpr("1", parser.charset, parser.collation)
- varAssigns = append(varAssigns, &ast.VariableAssignment{Name: "tx_read_only", Value: expr, IsSystem: true})
- $$ = varAssigns
- }
- IsolationLevel:
- "REPEATABLE" "READ"
- {
- $$ = ast.RepeatableRead
- }
- | "READ" "COMMITTED"
- {
- $$ = ast.ReadCommitted
- }
- | "READ" "UNCOMMITTED"
- {
- $$ = ast.ReadUncommitted
- }
- | "SERIALIZABLE"
- {
- $$ = ast.Serializable
- }
- SetExpr:
- "ON"
- {
- $$ = ast.NewValueExpr("ON", parser.charset, parser.collation)
- }
- | ExprOrDefault
- EqOrAssignmentEq:
- eq
- | assignmentEq
- VariableName:
- Identifier
- | Identifier '.' Identifier
- {
- $$ = $1 + "." + $3
- }
- ConfigItemName:
- Identifier
- | Identifier '.' ConfigItemName
- {
- $$ = $1 + "." + $3
- }
- | Identifier '-' ConfigItemName
- {
- $$ = $1 + "-" + $3
- }
- VariableAssignment:
- VariableName EqOrAssignmentEq SetExpr
- {
- $$ = &ast.VariableAssignment{Name: $1, Value: $3, IsSystem: true}
- }
- | "GLOBAL" VariableName EqOrAssignmentEq SetExpr
- {
- $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsGlobal: true, IsSystem: true}
- }
- | "SESSION" VariableName EqOrAssignmentEq SetExpr
- {
- $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsSystem: true}
- }
- | "LOCAL" VariableName EqOrAssignmentEq Expression
- {
- $$ = &ast.VariableAssignment{Name: $2, Value: $4, IsSystem: true}
- }
- | doubleAtIdentifier EqOrAssignmentEq SetExpr
- {
- v := strings.ToLower($1)
- var isGlobal bool
- if strings.HasPrefix(v, "@@global.") {
- isGlobal = true
- v = strings.TrimPrefix(v, "@@global.")
- } else if strings.HasPrefix(v, "@@session.") {
- v = strings.TrimPrefix(v, "@@session.")
- } else if strings.HasPrefix(v, "@@local.") {
- v = strings.TrimPrefix(v, "@@local.")
- } else if strings.HasPrefix(v, "@@") {
- v = strings.TrimPrefix(v, "@@")
- }
- $$ = &ast.VariableAssignment{Name: v, Value: $3, IsGlobal: isGlobal, IsSystem: true}
- }
- | singleAtIdentifier EqOrAssignmentEq Expression
- {
- v := $1
- v = strings.TrimPrefix(v, "@")
- $$ = &ast.VariableAssignment{Name: v, Value: $3}
- }
- | "NAMES" CharsetName
- {
- $$ = &ast.VariableAssignment{
- Name: ast.SetNames,
- Value: ast.NewValueExpr($2, "", ""),
- }
- }
- | "NAMES" CharsetName "COLLATE" "DEFAULT"
- {
- $$ = &ast.VariableAssignment{
- Name: ast.SetNames,
- Value: ast.NewValueExpr($2, "", ""),
- }
- }
- | "NAMES" CharsetName "COLLATE" StringName
- {
- $$ = &ast.VariableAssignment{
- Name: ast.SetNames,
- Value: ast.NewValueExpr($2, "", ""),
- ExtendValue: ast.NewValueExpr($4, "", ""),
- }
- }
- | "NAMES" "DEFAULT"
- {
- v := &ast.DefaultExpr{}
- $$ = &ast.VariableAssignment{Name: ast.SetNames, Value: v}
- }
- | CharsetKw CharsetNameOrDefault
- {
- $$ = &ast.VariableAssignment{Name: ast.SetCharset, Value: $2}
- }
- CharsetNameOrDefault:
- CharsetName
- {
- $$ = ast.NewValueExpr($1, "", "")
- }
- | "DEFAULT"
- {
- $$ = &ast.DefaultExpr{}
- }
- CharsetName:
- StringName
- {
- // Validate input charset name to keep the same behavior as parser of MySQL.
- name, _, err := charset.GetCharsetInfo($1)
- if err != nil {
- yylex.AppendError(ErrUnknownCharacterSet.GenWithStackByArgs($1))
- return 1
- }
- // Use charset name returned from charset.GetCharsetInfo(),
- // to keep lower case of input for generated column restore.
- $$ = name
- }
- | binaryType
- {
- $$ = charset.CharsetBin
- }
- CollationName:
- StringName
- {
- info, err := charset.GetCollationByName($1)
- if err != nil {
- yylex.AppendError(err)
- return 1
- }
- $$ = info.Name
- }
- | binaryType
- {
- $$ = charset.CollationBin
- }
- VariableAssignmentList:
- VariableAssignment
- {
- $$ = []*ast.VariableAssignment{$1.(*ast.VariableAssignment)}
- }
- | VariableAssignmentList ',' VariableAssignment
- {
- $$ = append($1.([]*ast.VariableAssignment), $3.(*ast.VariableAssignment))
- }
- Variable:
- SystemVariable
- | UserVariable
- SystemVariable:
- doubleAtIdentifier
- {
- v := strings.ToLower($1)
- var isGlobal bool
- explicitScope := true
- if strings.HasPrefix(v, "@@global.") {
- isGlobal = true
- v = strings.TrimPrefix(v, "@@global.")
- } else if strings.HasPrefix(v, "@@session.") {
- v = strings.TrimPrefix(v, "@@session.")
- } else if strings.HasPrefix(v, "@@local.") {
- v = strings.TrimPrefix(v, "@@local.")
- } else if strings.HasPrefix(v, "@@") {
- v, explicitScope = strings.TrimPrefix(v, "@@"), false
- }
- $$ = &ast.VariableExpr{Name: v, IsGlobal: isGlobal, IsSystem: true, ExplicitScope: explicitScope}
- }
- UserVariable:
- singleAtIdentifier
- {
- v := $1
- v = strings.TrimPrefix(v, "@")
- $$ = &ast.VariableExpr{Name: v, IsGlobal: false, IsSystem: false}
- }
- Username:
- StringName
- {
- $$ = &auth.UserIdentity{Username: $1, Hostname: "%"}
- }
- | StringName '@' StringName
- {
- $$ = &auth.UserIdentity{Username: $1, Hostname: $3}
- }
- | StringName singleAtIdentifier
- {
- $$ = &auth.UserIdentity{Username: $1, Hostname: strings.TrimPrefix($2, "@")}
- }
- | "CURRENT_USER" OptionalBraces
- {
- $$ = &auth.UserIdentity{CurrentUser: true}
- }
- UsernameList:
- Username
- {
- $$ = []*auth.UserIdentity{$1.(*auth.UserIdentity)}
- }
- | UsernameList ',' Username
- {
- $$ = append($1.([]*auth.UserIdentity), $3.(*auth.UserIdentity))
- }
- PasswordOpt:
- stringLit
- | "PASSWORD" '(' AuthString ')'
- {
- $$ = $3
- }
- AuthString:
- stringLit
- RoleNameString:
- stringLit
- | identifier
- RolenameComposed:
- StringName '@' StringName
- {
- $$ = &auth.RoleIdentity{Username: $1, Hostname: $3}
- }
- | StringName singleAtIdentifier
- {
- $$ = &auth.RoleIdentity{Username: $1, Hostname: strings.TrimPrefix($2, "@")}
- }
- RolenameWithoutIdent:
- stringLit
- {
- $$ = &auth.RoleIdentity{Username: $1, Hostname: "%"}
- }
- | RolenameComposed
- {
- $$ = $1
- }
- Rolename:
- RoleNameString
- {
- $$ = &auth.RoleIdentity{Username: $1, Hostname: "%"}
- }
- | RolenameComposed
- {
- $$ = $1
- }
- RolenameList:
- Rolename
- {
- $$ = []*auth.RoleIdentity{$1.(*auth.RoleIdentity)}
- }
- | RolenameList ',' Rolename
- {
- $$ = append($1.([]*auth.RoleIdentity), $3.(*auth.RoleIdentity))
- }
- /****************************Admin Statement*******************************/
- AdminStmt:
- "ADMIN" "SHOW" "DDL"
- {
- $$ = &ast.AdminStmt{Tp: ast.AdminShowDDL}
- }
- | "ADMIN" "SHOW" "DDL" "JOBS" WhereClauseOptional
- {
- stmt := &ast.AdminStmt{Tp: ast.AdminShowDDLJobs}
- if $5 != nil {
- stmt.Where = $5.(ast.ExprNode)
- }
- $$ = stmt
- }
- | "ADMIN" "SHOW" "DDL" "JOBS" Int64Num WhereClauseOptional
- {
- stmt := &ast.AdminStmt{
- Tp: ast.AdminShowDDLJobs,
- JobNumber: $5.(int64),
- }
- if $6 != nil {
- stmt.Where = $6.(ast.ExprNode)
- }
- $$ = stmt
- }
- | "ADMIN" "SHOW" TableName "NEXT_ROW_ID"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminShowNextRowID,
- Tables: []*ast.TableName{$3.(*ast.TableName)},
- }
- }
- | "ADMIN" "CHECK" "TABLE" TableNameList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminCheckTable,
- Tables: $4.([]*ast.TableName),
- }
- }
- | "ADMIN" "CHECK" "INDEX" TableName Identifier
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminCheckIndex,
- Tables: []*ast.TableName{$4.(*ast.TableName)},
- Index: string($5),
- }
- }
- | "ADMIN" "RECOVER" "INDEX" TableName Identifier
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminRecoverIndex,
- Tables: []*ast.TableName{$4.(*ast.TableName)},
- Index: string($5),
- }
- }
- | "ADMIN" "CLEANUP" "INDEX" TableName Identifier
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminCleanupIndex,
- Tables: []*ast.TableName{$4.(*ast.TableName)},
- Index: string($5),
- }
- }
- | "ADMIN" "CHECK" "INDEX" TableName Identifier HandleRangeList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminCheckIndexRange,
- Tables: []*ast.TableName{$4.(*ast.TableName)},
- Index: string($5),
- HandleRanges: $6.([]ast.HandleRange),
- }
- }
- | "ADMIN" "CHECKSUM" "TABLE" TableNameList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminChecksumTable,
- Tables: $4.([]*ast.TableName),
- }
- }
- | "ADMIN" "CANCEL" "DDL" "JOBS" NumList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminCancelDDLJobs,
- JobIDs: $5.([]int64),
- }
- }
- | "ADMIN" "SHOW" "DDL" "JOB" "QUERIES" NumList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminShowDDLJobQueries,
- JobIDs: $6.([]int64),
- }
- }
- | "ADMIN" "SHOW" "SLOW" AdminShowSlow
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminShowSlow,
- ShowSlow: $4.(*ast.ShowSlow),
- }
- }
- | "ADMIN" "RELOAD" "EXPR_PUSHDOWN_BLACKLIST"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminReloadExprPushdownBlacklist,
- }
- }
- | "ADMIN" "RELOAD" "OPT_RULE_BLACKLIST"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminReloadOptRuleBlacklist,
- }
- }
- | "ADMIN" "PLUGINS" "ENABLE" PluginNameList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminPluginEnable,
- Plugins: $4.([]string),
- }
- }
- | "ADMIN" "PLUGINS" "DISABLE" PluginNameList
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminPluginDisable,
- Plugins: $4.([]string),
- }
- }
- | "ADMIN" "CLEANUP" "TABLE" "LOCK" TableNameList
- {
- $$ = &ast.CleanupTableLockStmt{
- Tables: $5.([]*ast.TableName),
- }
- }
- | "ADMIN" "REPAIR" "TABLE" TableName CreateTableStmt
- {
- $$ = &ast.RepairTableStmt{
- Table: $4.(*ast.TableName),
- CreateStmt: $5.(*ast.CreateTableStmt),
- }
- }
- | "ADMIN" "FLUSH" "BINDINGS"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminFlushBindings,
- }
- }
- | "ADMIN" "CAPTURE" "BINDINGS"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminCaptureBindings,
- }
- }
- | "ADMIN" "EVOLVE" "BINDINGS"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminEvolveBindings,
- }
- }
- | "ADMIN" "RELOAD" "BINDINGS"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminReloadBindings,
- }
- }
- | "ADMIN" "RELOAD" "STATS_EXTENDED"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminReloadStatistics,
- }
- }
- | "ADMIN" "RELOAD" "STATISTICS"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminReloadStatistics,
- }
- }
- | "ADMIN" "SHOW" "TELEMETRY"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminShowTelemetry,
- }
- }
- | "ADMIN" "RESET" "TELEMETRY_ID"
- {
- $$ = &ast.AdminStmt{
- Tp: ast.AdminResetTelemetryID,
- }
- }
- AdminShowSlow:
- "RECENT" NUM
- {
- $$ = &ast.ShowSlow{
- Tp: ast.ShowSlowRecent,
- Count: getUint64FromNUM($2),
- }
- }
- | "TOP" NUM
- {
- $$ = &ast.ShowSlow{
- Tp: ast.ShowSlowTop,
- Kind: ast.ShowSlowKindDefault,
- Count: getUint64FromNUM($2),
- }
- }
- | "TOP" "INTERNAL" NUM
- {
- $$ = &ast.ShowSlow{
- Tp: ast.ShowSlowTop,
- Kind: ast.ShowSlowKindInternal,
- Count: getUint64FromNUM($3),
- }
- }
- | "TOP" "ALL" NUM
- {
- $$ = &ast.ShowSlow{
- Tp: ast.ShowSlowTop,
- Kind: ast.ShowSlowKindAll,
- Count: getUint64FromNUM($3),
- }
- }
- HandleRangeList:
- HandleRange
- {
- $$ = []ast.HandleRange{$1.(ast.HandleRange)}
- }
- | HandleRangeList ',' HandleRange
- {
- $$ = append($1.([]ast.HandleRange), $3.(ast.HandleRange))
- }
- HandleRange:
- '(' Int64Num ',' Int64Num ')'
- {
- $$ = ast.HandleRange{Begin: $2.(int64), End: $4.(int64)}
- }
- NumList:
- Int64Num
- {
- $$ = []int64{$1.(int64)}
- }
- | NumList ',' Int64Num
- {
- $$ = append($1.([]int64), $3.(int64))
- }
- /****************************Show Statement*******************************/
- ShowStmt:
- "SHOW" ShowTargetFilterable ShowLikeOrWhereOpt
- {
- stmt := $2.(*ast.ShowStmt)
- if $3 != nil {
- if x, ok := $3.(*ast.PatternLikeExpr); ok && x.Expr == nil {
- stmt.Pattern = x
- } else {
- stmt.Where = $3.(ast.ExprNode)
- }
- }
- $$ = stmt
- }
- | "SHOW" "CREATE" "TABLE" TableName
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCreateTable,
- Table: $4.(*ast.TableName),
- }
- }
- | "SHOW" "CREATE" "VIEW" TableName
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCreateView,
- Table: $4.(*ast.TableName),
- }
- }
- | "SHOW" "CREATE" "DATABASE" IfNotExists DBName
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCreateDatabase,
- IfNotExists: $4.(bool),
- DBName: $5,
- }
- }
- | "SHOW" "CREATE" "SEQUENCE" TableName
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCreateSequence,
- Table: $4.(*ast.TableName),
- }
- }
- | "SHOW" "CREATE" "USER" Username
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/show-create-user.html
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCreateUser,
- User: $4.(*auth.UserIdentity),
- }
- }
- | "SHOW" "CREATE" "IMPORT" Identifier
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCreateImport,
- DBName: $4, // we reuse DBName of ShowStmt
- }
- }
- | "SHOW" "TABLE" TableName PartitionNameListOpt "REGIONS" WhereClauseOptional
- {
- stmt := &ast.ShowStmt{
- Tp: ast.ShowRegions,
- Table: $3.(*ast.TableName),
- }
- stmt.Table.PartitionNames = $4.([]model.CIStr)
- if $6 != nil {
- stmt.Where = $6.(ast.ExprNode)
- }
- $$ = stmt
- }
- | "SHOW" "TABLE" TableName "NEXT_ROW_ID"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowTableNextRowId,
- Table: $3.(*ast.TableName),
- }
- }
- | "SHOW" "TABLE" TableName PartitionNameListOpt "INDEX" Identifier "REGIONS" WhereClauseOptional
- {
- stmt := &ast.ShowStmt{
- Tp: ast.ShowRegions,
- Table: $3.(*ast.TableName),
- IndexName: model.NewCIStr($6),
- }
- stmt.Table.PartitionNames = $4.([]model.CIStr)
- if $8 != nil {
- stmt.Where = $8.(ast.ExprNode)
- }
- $$ = stmt
- }
- | "SHOW" "GRANTS"
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/show-grants.html
- $$ = &ast.ShowStmt{Tp: ast.ShowGrants}
- }
- | "SHOW" "GRANTS" "FOR" Username UsingRoles
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/show-grants.html
- if $5 != nil {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowGrants,
- User: $4.(*auth.UserIdentity),
- Roles: $5.([]*auth.RoleIdentity),
- }
- } else {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowGrants,
- User: $4.(*auth.UserIdentity),
- Roles: nil,
- }
- }
- }
- | "SHOW" "MASTER" "STATUS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowMasterStatus,
- }
- }
- | "SHOW" OptFull "PROCESSLIST"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowProcessList,
- Full: $2.(bool),
- }
- }
- | "SHOW" "PROFILES"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowProfiles,
- }
- }
- | "SHOW" "PROFILE" ShowProfileTypesOpt ShowProfileArgsOpt SelectStmtLimitOpt
- {
- v := &ast.ShowStmt{
- Tp: ast.ShowProfile,
- }
- if $3 != nil {
- v.ShowProfileTypes = $3.([]int)
- }
- if $4 != nil {
- v.ShowProfileArgs = $4.(*int64)
- }
- if $5 != nil {
- v.ShowProfileLimit = $5.(*ast.Limit)
- }
- $$ = v
- }
- | "SHOW" "PRIVILEGES"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowPrivileges,
- }
- }
- | "SHOW" "BUILTINS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowBuiltins,
- }
- }
- ShowProfileTypesOpt:
- {
- $$ = nil
- }
- | ShowProfileTypes
- ShowProfileTypes:
- ShowProfileType
- {
- $$ = []int{$1.(int)}
- }
- | ShowProfileTypes ',' ShowProfileType
- {
- l := $1.([]int)
- l = append(l, $3.(int))
- $$ = l
- }
- ShowProfileType:
- "CPU"
- {
- $$ = ast.ProfileTypeCPU
- }
- | "MEMORY"
- {
- $$ = ast.ProfileTypeMemory
- }
- | "BLOCK" "IO"
- {
- $$ = ast.ProfileTypeBlockIo
- }
- | "CONTEXT" "SWITCHES"
- {
- $$ = ast.ProfileTypeContextSwitch
- }
- | "PAGE" "FAULTS"
- {
- $$ = ast.ProfileTypePageFaults
- }
- | "IPC"
- {
- $$ = ast.ProfileTypeIpc
- }
- | "SWAPS"
- {
- $$ = ast.ProfileTypeSwaps
- }
- | "SOURCE"
- {
- $$ = ast.ProfileTypeSource
- }
- | "ALL"
- {
- $$ = ast.ProfileTypeAll
- }
- ShowProfileArgsOpt:
- {
- $$ = nil
- }
- | "FOR" "QUERY" Int64Num
- {
- v := $3.(int64)
- $$ = &v
- }
- UsingRoles:
- {
- $$ = nil
- }
- | "USING" RolenameList
- {
- $$ = $2.([]*auth.RoleIdentity)
- }
- ShowIndexKwd:
- "INDEX"
- | "INDEXES"
- | "KEYS"
- FromOrIn:
- "FROM"
- | "IN"
- ShowTargetFilterable:
- "ENGINES"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowEngines}
- }
- | "DATABASES"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowDatabases}
- }
- | "CONFIG"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowConfig}
- }
- | CharsetKw
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowCharset}
- }
- | OptFull "TABLES" ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowTables,
- DBName: $3,
- Full: $1.(bool),
- }
- }
- | "OPEN" "TABLES" ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowOpenTables,
- DBName: $3,
- }
- }
- | "TABLE" "STATUS" ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowTableStatus,
- DBName: $3,
- }
- }
- | ShowIndexKwd FromOrIn TableName
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowIndex,
- Table: $3.(*ast.TableName),
- }
- }
- | ShowIndexKwd FromOrIn Identifier FromOrIn Identifier
- {
- show := &ast.ShowStmt{
- Tp: ast.ShowIndex,
- Table: &ast.TableName{Name: model.NewCIStr($3), Schema: model.NewCIStr($5)},
- }
- $$ = show
- }
- | OptFull FieldsOrColumns ShowTableAliasOpt ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowColumns,
- Table: $3.(*ast.TableName),
- DBName: $4,
- Full: $1.(bool),
- }
- }
- | "EXTENDED" OptFull FieldsOrColumns ShowTableAliasOpt ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowColumns,
- Table: $4.(*ast.TableName),
- DBName: $5,
- Full: $2.(bool),
- Extended: true,
- }
- }
- | "WARNINGS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowWarnings}
- }
- | "ERRORS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowErrors}
- }
- | GlobalScope "VARIABLES"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowVariables,
- GlobalScope: $1.(bool),
- }
- }
- | GlobalScope "STATUS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowStatus,
- GlobalScope: $1.(bool),
- }
- }
- | GlobalScope "BINDINGS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowBindings,
- GlobalScope: $1.(bool),
- }
- }
- | "COLLATION"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowCollation,
- }
- }
- | "TRIGGERS" ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowTriggers,
- DBName: $2,
- }
- }
- | "PROCEDURE" "STATUS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowProcedureStatus,
- }
- }
- | "PUMP" "STATUS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowPumpStatus,
- }
- }
- | "DRAINER" "STATUS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowDrainerStatus,
- }
- }
- | "FUNCTION" "STATUS"
- {
- // This statement is similar to SHOW PROCEDURE STATUS but for stored functions.
- // See http://dev.mysql.com/doc/refman/5.7/en/show-function-status.html
- // We do not support neither stored functions nor stored procedures.
- // So we reuse show procedure status process logic.
- $$ = &ast.ShowStmt{
- Tp: ast.ShowProcedureStatus,
- }
- }
- | "EVENTS" ShowDatabaseNameOpt
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowEvents,
- DBName: $2,
- }
- }
- | "PLUGINS"
- {
- $$ = &ast.ShowStmt{
- Tp: ast.ShowPlugins,
- }
- }
- | "STATS_EXTENDED"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowStatsExtended}
- }
- | "STATS_META"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowStatsMeta}
- }
- | "STATS_HISTOGRAMS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowStatsHistograms}
- }
- | "STATS_TOPN"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowStatsTopN}
- }
- | "STATS_BUCKETS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowStatsBuckets}
- }
- | "STATS_HEALTHY"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowStatsHealthy}
- }
- | "ANALYZE" "STATUS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowAnalyzeStatus}
- }
- | "BACKUPS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowBackups}
- }
- | "RESTORES"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowRestores}
- }
- | "IMPORTS"
- {
- $$ = &ast.ShowStmt{Tp: ast.ShowImports}
- }
- ShowLikeOrWhereOpt:
- {
- $$ = nil
- }
- | "LIKE" SimpleExpr
- {
- $$ = &ast.PatternLikeExpr{
- Pattern: $2,
- Escape: '\\',
- }
- }
- | "WHERE" Expression
- {
- $$ = $2
- }
- GlobalScope:
- {
- $$ = false
- }
- | "GLOBAL"
- {
- $$ = true
- }
- | "SESSION"
- {
- $$ = false
- }
- OptFull:
- {
- $$ = false
- }
- | "FULL"
- {
- $$ = true
- }
- ShowDatabaseNameOpt:
- {
- $$ = ""
- }
- | FromOrIn DBName
- {
- $$ = $2
- }
- ShowTableAliasOpt:
- FromOrIn TableName
- {
- $$ = $2.(*ast.TableName)
- }
- FlushStmt:
- "FLUSH" NoWriteToBinLogAliasOpt FlushOption
- {
- tmp := $3.(*ast.FlushStmt)
- tmp.NoWriteToBinLog = $2.(bool)
- $$ = tmp
- }
- PluginNameList:
- Identifier
- {
- $$ = []string{$1}
- }
- | PluginNameList ',' Identifier
- {
- $$ = append($1.([]string), $3)
- }
- FlushOption:
- "PRIVILEGES"
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushPrivileges,
- }
- }
- | "STATUS"
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushStatus,
- }
- }
- | "TIDB" "PLUGINS" PluginNameList
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushTiDBPlugin,
- Plugins: $3.([]string),
- }
- }
- | "HOSTS"
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushHosts,
- }
- }
- | LogTypeOpt "LOGS"
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushLogs,
- LogType: $1.(ast.LogType),
- }
- }
- | TableOrTables TableNameListOpt WithReadLockOpt
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushTables,
- Tables: $2.([]*ast.TableName),
- ReadLock: $3.(bool),
- }
- }
- | "CLIENT_ERRORS_SUMMARY"
- {
- $$ = &ast.FlushStmt{
- Tp: ast.FlushClientErrorsSummary,
- }
- }
- LogTypeOpt:
- /* empty */
- {
- $$ = ast.LogTypeDefault
- }
- | "BINARY"
- {
- $$ = ast.LogTypeBinary
- }
- | "ENGINE"
- {
- $$ = ast.LogTypeEngine
- }
- | "ERROR"
- {
- $$ = ast.LogTypeError
- }
- | "GENERAL"
- {
- $$ = ast.LogTypeGeneral
- }
- | "SLOW"
- {
- $$ = ast.LogTypeSlow
- }
- NoWriteToBinLogAliasOpt:
- %prec lowerThanLocal
- {
- $$ = false
- }
- | "NO_WRITE_TO_BINLOG"
- {
- $$ = true
- }
- | "LOCAL"
- {
- $$ = true
- }
- TableNameListOpt:
- %prec empty
- {
- $$ = []*ast.TableName{}
- }
- | TableNameList
- TableNameListOpt2:
- %prec empty
- {
- $$ = []*ast.TableName{}
- }
- | "TABLE" TableNameList
- {
- $$ = $2
- }
- WithReadLockOpt:
- {
- $$ = false
- }
- | "WITH" "READ" "LOCK"
- {
- $$ = true
- }
- Statement:
- EmptyStmt
- | AdminStmt
- | AlterDatabaseStmt
- | AlterTableStmt
- | AlterUserStmt
- | AlterImportStmt
- | AlterInstanceStmt
- | AlterSequenceStmt
- | AnalyzeTableStmt
- | BeginTransactionStmt
- | BinlogStmt
- | BRIEStmt
- | CommitStmt
- | DeallocateStmt
- | DeleteFromStmt
- | ExecuteStmt
- | ExplainStmt
- | ChangeStmt
- | CreateDatabaseStmt
- | CreateImportStmt
- | CreateIndexStmt
- | CreateTableStmt
- | CreateViewStmt
- | CreateUserStmt
- | CreateRoleStmt
- | CreateBindingStmt
- | CreateSequenceStmt
- | CreateStatisticsStmt
- | DoStmt
- | DropDatabaseStmt
- | DropImportStmt
- | DropIndexStmt
- | DropTableStmt
- | DropSequenceStmt
- | DropViewStmt
- | DropUserStmt
- | DropRoleStmt
- | DropStatisticsStmt
- | DropStatsStmt
- | DropBindingStmt
- | FlushStmt
- | FlashbackTableStmt
- | GrantStmt
- | GrantProxyStmt
- | GrantRoleStmt
- | CallStmt
- | InsertIntoStmt
- | IndexAdviseStmt
- | KillStmt
- | LoadDataStmt
- | LoadStatsStmt
- | PreparedStmt
- | PurgeImportStmt
- | RollbackStmt
- | RenameTableStmt
- | RenameUserStmt
- | ReplaceIntoStmt
- | RecoverTableStmt
- | ResumeImportStmt
- | RevokeStmt
- | RevokeRoleStmt
- | SetOprStmt1
- | SetStmt
- | SetRoleStmt
- | SetDefaultRoleStmt
- | SplitRegionStmt
- | StopImportStmt
- | ShowImportStmt
- | ShowStmt
- | SubSelect
- {
- // `(select 1)`; is a valid select statement
- // TODO: This is used to fix issue #320. There may be a better solution.
- $$ = $1.(*ast.SubqueryExpr).Query.(ast.StmtNode)
- }
- | TraceStmt
- | TruncateTableStmt
- | UpdateStmt
- | UseStmt
- | UnlockTablesStmt
- | LockTablesStmt
- | ShutdownStmt
- TraceableStmt:
- DeleteFromStmt
- | UpdateStmt
- | InsertIntoStmt
- | ReplaceIntoStmt
- | SetOprStmt1
- | LoadDataStmt
- | BeginTransactionStmt
- | CommitStmt
- | RollbackStmt
- | SetStmt
- ExplainableStmt:
- DeleteFromStmt
- | UpdateStmt
- | InsertIntoStmt
- | ReplaceIntoStmt
- | SetOprStmt1
- | AlterTableStmt
- StatementList:
- Statement
- {
- if $1 != nil {
- s := $1
- if lexer, ok := yylex.(stmtTexter); ok {
- s.SetText(lexer.stmtText())
- }
- parser.result = append(parser.result, s)
- }
- }
- | StatementList ';' Statement
- {
- if $3 != nil {
- s := $3
- if lexer, ok := yylex.(stmtTexter); ok {
- s.SetText(lexer.stmtText())
- }
- parser.result = append(parser.result, s)
- }
- }
- Constraint:
- ConstraintKeywordOpt ConstraintElem
- {
- cst := $2.(*ast.Constraint)
- if $1 != nil {
- cst.Name = $1.(string)
- }
- $$ = cst
- }
- CheckConstraintKeyword:
- "CHECK"
- | "CONSTRAINT"
- TableElement:
- ColumnDef
- | Constraint
- TableElementList:
- TableElement
- {
- if $1 != nil {
- $$ = []interface{}{$1.(interface{})}
- } else {
- $$ = []interface{}{}
- }
- }
- | TableElementList ',' TableElement
- {
- if $3 != nil {
- $$ = append($1.([]interface{}), $3)
- } else {
- $$ = $1
- }
- }
- TableElementListOpt:
- /* empty */ %prec lowerThanCreateTableSelect
- {
- var columnDefs []*ast.ColumnDef
- var constraints []*ast.Constraint
- $$ = &ast.CreateTableStmt{
- Cols: columnDefs,
- Constraints: constraints,
- }
- }
- | '(' TableElementList ')'
- {
- tes := $2.([]interface{})
- var columnDefs []*ast.ColumnDef
- var constraints []*ast.Constraint
- for _, te := range tes {
- switch te := te.(type) {
- case *ast.ColumnDef:
- columnDefs = append(columnDefs, te)
- case *ast.Constraint:
- constraints = append(constraints, te)
- }
- }
- $$ = &ast.CreateTableStmt{
- Cols: columnDefs,
- Constraints: constraints,
- }
- }
- TableOption:
- PartDefOption
- | DefaultKwdOpt CharsetKw EqOpt CharsetName
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionCharset, StrValue: $4,
- UintValue: ast.TableOptionCharsetWithoutConvertTo}
- }
- | DefaultKwdOpt "COLLATE" EqOpt CollationName
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionCollate, StrValue: $4,
- UintValue: ast.TableOptionCharsetWithoutConvertTo}
- }
- | "AUTO_INCREMENT" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionAutoIncrement, UintValue: $3.(uint64)}
- }
- | "AUTO_ID_CACHE" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionAutoIdCache, UintValue: $3.(uint64)}
- }
- | "AUTO_RANDOM_BASE" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionAutoRandomBase, UintValue: $3.(uint64)}
- }
- | "AVG_ROW_LENGTH" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionAvgRowLength, UintValue: $3.(uint64)}
- }
- | "CONNECTION" EqOpt stringLit
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionConnection, StrValue: $3}
- }
- | "CHECKSUM" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionCheckSum, UintValue: $3.(uint64)}
- }
- | "TABLE_CHECKSUM" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionTableCheckSum, UintValue: $3.(uint64)}
- }
- | "PASSWORD" EqOpt stringLit
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionPassword, StrValue: $3}
- }
- | "COMPRESSION" EqOpt stringLit
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionCompression, StrValue: $3}
- }
- | "KEY_BLOCK_SIZE" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionKeyBlockSize, UintValue: $3.(uint64)}
- }
- | "DELAY_KEY_WRITE" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionDelayKeyWrite, UintValue: $3.(uint64)}
- }
- | RowFormat
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionRowFormat, UintValue: $1.(uint64)}
- }
- | "STATS_PERSISTENT" EqOpt StatsPersistentVal
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionStatsPersistent}
- }
- | "STATS_AUTO_RECALC" EqOpt LengthNum
- {
- n := $3.(uint64)
- if n != 0 && n != 1 {
- yylex.AppendError(yylex.Errorf("The value of STATS_AUTO_RECALC must be one of [0|1|DEFAULT]."))
- return 1
- }
- $$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, UintValue: n}
- yylex.AppendError(yylex.Errorf("The STATS_AUTO_RECALC is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "STATS_AUTO_RECALC" EqOpt "DEFAULT"
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionStatsAutoRecalc, Default: true}
- yylex.AppendError(yylex.Errorf("The STATS_AUTO_RECALC is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "STATS_SAMPLE_PAGES" EqOpt LengthNum
- {
- // Parse it but will ignore it.
- // In MySQL, STATS_SAMPLE_PAGES=N(Where 0<N<=65535) or STAS_SAMPLE_PAGES=DEFAULT.
- // Cause we don't support it, so we don't check range of the value.
- $$ = &ast.TableOption{Tp: ast.TableOptionStatsSamplePages, UintValue: $3.(uint64)}
- yylex.AppendError(yylex.Errorf("The STATS_SAMPLE_PAGES is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "STATS_SAMPLE_PAGES" EqOpt "DEFAULT"
- {
- // Parse it but will ignore it.
- // In MySQL, default value of STATS_SAMPLE_PAGES is 0.
- $$ = &ast.TableOption{Tp: ast.TableOptionStatsSamplePages, Default: true}
- yylex.AppendError(yylex.Errorf("The STATS_SAMPLE_PAGES is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "SHARD_ROW_ID_BITS" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionShardRowID, UintValue: $3.(uint64)}
- }
- | "PRE_SPLIT_REGIONS" EqOpt LengthNum
- {
- $$ = &ast.TableOption{Tp: ast.TableOptionPreSplitRegion, UintValue: $3.(uint64)}
- }
- | "PACK_KEYS" EqOpt StatsPersistentVal
- {
- // Parse it but will ignore it.
- $$ = &ast.TableOption{Tp: ast.TableOptionPackKeys}
- }
- | "STORAGE" "MEMORY"
- {
- // Parse it but will ignore it.
- $$ = &ast.TableOption{Tp: ast.TableOptionStorageMedia, StrValue: "MEMORY"}
- yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "STORAGE" "DISK"
- {
- // Parse it but will ignore it.
- $$ = &ast.TableOption{Tp: ast.TableOptionStorageMedia, StrValue: "DISK"}
- yylex.AppendError(yylex.Errorf("The STORAGE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "SECONDARY_ENGINE" EqOpt "NULL"
- {
- // Parse it but will ignore it
- // See https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L5977-L5984
- $$ = &ast.TableOption{Tp: ast.TableOptionSecondaryEngineNull}
- yylex.AppendError(yylex.Errorf("The SECONDARY_ENGINE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "SECONDARY_ENGINE" EqOpt StringName
- {
- // Parse it but will ignore it
- // See https://github.com/mysql/mysql-server/blob/8.0/sql/sql_yacc.yy#L5977-L5984
- $$ = &ast.TableOption{Tp: ast.TableOptionSecondaryEngine, StrValue: $3}
- yylex.AppendError(yylex.Errorf("The SECONDARY_ENGINE clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "UNION" EqOpt '(' TableNameListOpt ')'
- {
- // Parse it but will ignore it
- $$ = &ast.TableOption{
- Tp: ast.TableOptionUnion,
- TableNames: $4.([]*ast.TableName),
- }
- yylex.AppendError(yylex.Errorf("The UNION option is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- }
- | "ENCRYPTION" EqOpt EncryptionOpt
- {
- // Parse it but will ignore it
- $$ = &ast.TableOption{Tp: ast.TableOptionEncryption, StrValue: $3}
- }
- StatsPersistentVal:
- "DEFAULT"
- {}
- | LengthNum
- {}
- CreateTableOptionListOpt:
- /* empty */ %prec lowerThanCreateTableSelect
- {
- $$ = []*ast.TableOption{}
- }
- | TableOptionList %prec lowerThanComma
- TableOptionList:
- TableOption
- {
- $$ = []*ast.TableOption{$1.(*ast.TableOption)}
- }
- | TableOptionList TableOption
- {
- $$ = append($1.([]*ast.TableOption), $2.(*ast.TableOption))
- }
- | TableOptionList ',' TableOption
- {
- $$ = append($1.([]*ast.TableOption), $3.(*ast.TableOption))
- }
- OptTable:
- {}
- | "TABLE"
- TruncateTableStmt:
- "TRUNCATE" OptTable TableName
- {
- $$ = &ast.TruncateTableStmt{Table: $3.(*ast.TableName)}
- }
- RowFormat:
- "ROW_FORMAT" EqOpt "DEFAULT"
- {
- $$ = ast.RowFormatDefault
- }
- | "ROW_FORMAT" EqOpt "DYNAMIC"
- {
- $$ = ast.RowFormatDynamic
- }
- | "ROW_FORMAT" EqOpt "FIXED"
- {
- $$ = ast.RowFormatFixed
- }
- | "ROW_FORMAT" EqOpt "COMPRESSED"
- {
- $$ = ast.RowFormatCompressed
- }
- | "ROW_FORMAT" EqOpt "REDUNDANT"
- {
- $$ = ast.RowFormatRedundant
- }
- | "ROW_FORMAT" EqOpt "COMPACT"
- {
- $$ = ast.RowFormatCompact
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_DEFAULT"
- {
- $$ = ast.TokuDBRowFormatDefault
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_FAST"
- {
- $$ = ast.TokuDBRowFormatFast
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_SMALL"
- {
- $$ = ast.TokuDBRowFormatSmall
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_ZLIB"
- {
- $$ = ast.TokuDBRowFormatZlib
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_QUICKLZ"
- {
- $$ = ast.TokuDBRowFormatQuickLZ
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_LZMA"
- {
- $$ = ast.TokuDBRowFormatLzma
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_SNAPPY"
- {
- $$ = ast.TokuDBRowFormatSnappy
- }
- | "ROW_FORMAT" EqOpt "TOKUDB_UNCOMPRESSED"
- {
- $$ = ast.TokuDBRowFormatUncompressed
- }
- /*************************************Type Begin***************************************/
- Type:
- NumericType
- | StringType
- | DateAndTimeType
- NumericType:
- IntegerType OptFieldLen FieldOpts
- {
- // TODO: check flen 0
- x := types.NewFieldType($1.(byte))
- x.Flen = $2.(int)
- if $2.(int) != types.UnspecifiedLength && types.TiDBStrictIntegerDisplayWidth {
- yylex.AppendError(ErrWarnDeprecatedIntegerDisplayWidth)
- parser.lastErrorAsWarn()
- }
- for _, o := range $3.([]*ast.TypeOpt) {
- if o.IsUnsigned {
- x.Flag |= mysql.UnsignedFlag
- }
- if o.IsZerofill {
- x.Flag |= mysql.ZerofillFlag
- }
- }
- $$ = x
- }
- | BooleanType FieldOpts
- {
- // TODO: check flen 0
- x := types.NewFieldType($1.(byte))
- x.Flen = 1
- for _, o := range $2.([]*ast.TypeOpt) {
- if o.IsUnsigned {
- x.Flag |= mysql.UnsignedFlag
- }
- if o.IsZerofill {
- x.Flag |= mysql.ZerofillFlag
- }
- }
- $$ = x
- }
- | FixedPointType FloatOpt FieldOpts
- {
- fopt := $2.(*ast.FloatOpt)
- x := types.NewFieldType($1.(byte))
- x.Flen = fopt.Flen
- x.Decimal = fopt.Decimal
- for _, o := range $3.([]*ast.TypeOpt) {
- if o.IsUnsigned {
- x.Flag |= mysql.UnsignedFlag
- }
- if o.IsZerofill {
- x.Flag |= mysql.ZerofillFlag
- }
- }
- $$ = x
- }
- | FloatingPointType FloatOpt FieldOpts
- {
- fopt := $2.(*ast.FloatOpt)
- x := types.NewFieldType($1.(byte))
- // check for a double(10) for syntax error
- if x.Tp == mysql.TypeDouble && parser.strictDoubleFieldType {
- if fopt.Flen != types.UnspecifiedLength && fopt.Decimal == types.UnspecifiedLength {
- yylex.AppendError(ErrSyntax)
- return 1
- }
- }
- x.Flen = fopt.Flen
- if x.Tp == mysql.TypeFloat && fopt.Decimal == types.UnspecifiedLength && x.Flen <= mysql.MaxDoublePrecisionLength {
- if x.Flen > mysql.MaxFloatPrecisionLength {
- x.Tp = mysql.TypeDouble
- }
- x.Flen = types.UnspecifiedLength
- }
- x.Decimal = fopt.Decimal
- for _, o := range $3.([]*ast.TypeOpt) {
- if o.IsUnsigned {
- x.Flag |= mysql.UnsignedFlag
- }
- if o.IsZerofill {
- x.Flag |= mysql.ZerofillFlag
- }
- }
- $$ = x
- }
- | BitValueType OptFieldLen
- {
- x := types.NewFieldType($1.(byte))
- x.Flen = $2.(int)
- if x.Flen == types.UnspecifiedLength {
- x.Flen = 1
- }
- $$ = x
- }
- IntegerType:
- "TINYINT"
- {
- $$ = mysql.TypeTiny
- }
- | "SMALLINT"
- {
- $$ = mysql.TypeShort
- }
- | "MEDIUMINT"
- {
- $$ = mysql.TypeInt24
- }
- | "INT"
- {
- $$ = mysql.TypeLong
- }
- | "INT1"
- {
- $$ = mysql.TypeTiny
- }
- | "INT2"
- {
- $$ = mysql.TypeShort
- }
- | "INT3"
- {
- $$ = mysql.TypeInt24
- }
- | "INT4"
- {
- $$ = mysql.TypeLong
- }
- | "INT8"
- {
- $$ = mysql.TypeLonglong
- }
- | "INTEGER"
- {
- $$ = mysql.TypeLong
- }
- | "BIGINT"
- {
- $$ = mysql.TypeLonglong
- }
- BooleanType:
- "BOOL"
- {
- $$ = mysql.TypeTiny
- }
- | "BOOLEAN"
- {
- $$ = mysql.TypeTiny
- }
- OptInteger:
- {}
- | "INTEGER"
- | "INT"
- FixedPointType:
- "DECIMAL"
- {
- $$ = mysql.TypeNewDecimal
- }
- | "NUMERIC"
- {
- $$ = mysql.TypeNewDecimal
- }
- | "FIXED"
- {
- $$ = mysql.TypeNewDecimal
- }
- FloatingPointType:
- "FLOAT"
- {
- $$ = mysql.TypeFloat
- }
- | "REAL"
- {
- if parser.lexer.GetSQLMode().HasRealAsFloatMode() {
- $$ = mysql.TypeFloat
- } else {
- $$ = mysql.TypeDouble
- }
- }
- | "DOUBLE"
- {
- $$ = mysql.TypeDouble
- }
- | "DOUBLE" "PRECISION"
- {
- $$ = mysql.TypeDouble
- }
- BitValueType:
- "BIT"
- {
- $$ = mysql.TypeBit
- }
- StringType:
- Char FieldLen OptBinary
- {
- x := types.NewFieldType(mysql.TypeString)
- x.Flen = $2.(int)
- x.Charset = $3.(*ast.OptBinary).Charset
- if $3.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | Char OptBinary
- {
- x := types.NewFieldType(mysql.TypeString)
- x.Charset = $2.(*ast.OptBinary).Charset
- if $2.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | NChar FieldLen OptBinary
- {
- x := types.NewFieldType(mysql.TypeString)
- x.Flen = $2.(int)
- x.Charset = $3.(*ast.OptBinary).Charset
- if $3.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | NChar OptBinary
- {
- x := types.NewFieldType(mysql.TypeString)
- x.Charset = $2.(*ast.OptBinary).Charset
- if $2.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | Varchar FieldLen OptBinary
- {
- x := types.NewFieldType(mysql.TypeVarchar)
- x.Flen = $2.(int)
- x.Charset = $3.(*ast.OptBinary).Charset
- if $3.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | NVarchar FieldLen OptBinary
- {
- x := types.NewFieldType(mysql.TypeVarchar)
- x.Flen = $2.(int)
- x.Charset = $3.(*ast.OptBinary).Charset
- if $3.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | "BINARY" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeString)
- x.Flen = $2.(int)
- x.Charset = charset.CharsetBin
- x.Collate = charset.CharsetBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | "VARBINARY" FieldLen
- {
- x := types.NewFieldType(mysql.TypeVarchar)
- x.Flen = $2.(int)
- x.Charset = charset.CharsetBin
- x.Collate = charset.CharsetBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | BlobType
- {
- x := $1.(*types.FieldType)
- x.Charset = charset.CharsetBin
- x.Collate = charset.CharsetBin
- x.Flag |= mysql.BinaryFlag
- $$ = x
- }
- | TextType OptCharsetWithOptBinary
- {
- x := $1.(*types.FieldType)
- x.Charset = $2.(*ast.OptBinary).Charset
- if $2.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | "ENUM" '(' TextStringList ')' OptCharsetWithOptBinary
- {
- x := types.NewFieldType(mysql.TypeEnum)
- x.Elems = $3.([]string)
- fieldLen := -1 // enum_flen = max(ele_flen)
- for i := range x.Elems {
- x.Elems[i] = strings.TrimRight(x.Elems[i], " ")
- if len(x.Elems[i]) > fieldLen {
- fieldLen = len(x.Elems[i])
- }
- }
- x.Flen = fieldLen
- opt := $5.(*ast.OptBinary)
- x.Charset = opt.Charset
- if opt.IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | "SET" '(' TextStringList ')' OptCharsetWithOptBinary
- {
- x := types.NewFieldType(mysql.TypeSet)
- x.Elems = $3.([]string)
- fieldLen := len(x.Elems) - 1 // set_flen = sum(ele_flen) + number_of_ele - 1
- for i := range x.Elems {
- x.Elems[i] = strings.TrimRight(x.Elems[i], " ")
- fieldLen += len(x.Elems[i])
- }
- x.Flen = fieldLen
- opt := $5.(*ast.OptBinary)
- x.Charset = opt.Charset
- if opt.IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | "JSON"
- {
- x := types.NewFieldType(mysql.TypeJSON)
- x.Decimal = 0
- x.Charset = charset.CharsetBin
- x.Collate = charset.CollationBin
- $$ = x
- }
- | "LONG" Varchar OptCharsetWithOptBinary
- {
- x := types.NewFieldType(mysql.TypeMediumBlob)
- x.Charset = $3.(*ast.OptBinary).Charset
- if $3.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- | "LONG" OptCharsetWithOptBinary
- {
- x := types.NewFieldType(mysql.TypeMediumBlob)
- x.Charset = $2.(*ast.OptBinary).Charset
- if $2.(*ast.OptBinary).IsBinary {
- x.Flag |= mysql.BinaryFlag
- }
- $$ = x
- }
- Char:
- "CHARACTER"
- | "CHAR"
- NChar:
- "NCHAR"
- | "NATIONAL" "CHARACTER"
- | "NATIONAL" "CHAR"
- Varchar:
- "CHARACTER" "VARYING"
- | "CHAR" "VARYING"
- | "VARCHAR"
- | "VARCHARACTER"
- NVarchar:
- "NATIONAL" "VARCHAR"
- | "NATIONAL" "VARCHARACTER"
- | "NVARCHAR"
- | "NCHAR" "VARCHAR"
- | "NCHAR" "VARCHARACTER"
- | "NATIONAL" "CHARACTER" "VARYING"
- | "NATIONAL" "CHAR" "VARYING"
- | "NCHAR" "VARYING"
- Year:
- "YEAR"
- | "SQL_TSI_YEAR"
- BlobType:
- "TINYBLOB"
- {
- x := types.NewFieldType(mysql.TypeTinyBlob)
- $$ = x
- }
- | "BLOB" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeBlob)
- x.Flen = $2.(int)
- $$ = x
- }
- | "MEDIUMBLOB"
- {
- x := types.NewFieldType(mysql.TypeMediumBlob)
- $$ = x
- }
- | "LONGBLOB"
- {
- x := types.NewFieldType(mysql.TypeLongBlob)
- $$ = x
- }
- | "LONG" "VARBINARY"
- {
- x := types.NewFieldType(mysql.TypeMediumBlob)
- $$ = x
- }
- TextType:
- "TINYTEXT"
- {
- x := types.NewFieldType(mysql.TypeTinyBlob)
- $$ = x
- }
- | "TEXT" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeBlob)
- x.Flen = $2.(int)
- $$ = x
- }
- | "MEDIUMTEXT"
- {
- x := types.NewFieldType(mysql.TypeMediumBlob)
- $$ = x
- }
- | "LONGTEXT"
- {
- x := types.NewFieldType(mysql.TypeLongBlob)
- $$ = x
- }
- OptCharsetWithOptBinary:
- OptBinary
- | "ASCII"
- {
- $$ = &ast.OptBinary{
- IsBinary: false,
- Charset: charset.CharsetLatin1,
- }
- }
- | "UNICODE"
- {
- name, _, err := charset.GetCharsetInfo("ucs2")
- if err != nil {
- yylex.AppendError(ErrUnknownCharacterSet.GenWithStackByArgs("ucs2"))
- return 1
- }
- $$ = &ast.OptBinary{
- IsBinary: false,
- Charset: name,
- }
- }
- | "BYTE"
- {
- $$ = &ast.OptBinary{
- IsBinary: false,
- Charset: "",
- }
- }
- DateAndTimeType:
- "DATE"
- {
- x := types.NewFieldType(mysql.TypeDate)
- $$ = x
- }
- | "DATETIME" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeDatetime)
- x.Flen = mysql.MaxDatetimeWidthNoFsp
- x.Decimal = $2.(int)
- if x.Decimal > 0 {
- x.Flen = x.Flen + 1 + x.Decimal
- }
- $$ = x
- }
- | "TIMESTAMP" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeTimestamp)
- x.Flen = mysql.MaxDatetimeWidthNoFsp
- x.Decimal = $2.(int)
- if x.Decimal > 0 {
- x.Flen = x.Flen + 1 + x.Decimal
- }
- $$ = x
- }
- | "TIME" OptFieldLen
- {
- x := types.NewFieldType(mysql.TypeDuration)
- x.Flen = mysql.MaxDurationWidthNoFsp
- x.Decimal = $2.(int)
- if x.Decimal > 0 {
- x.Flen = x.Flen + 1 + x.Decimal
- }
- $$ = x
- }
- | Year OptFieldLen FieldOpts
- {
- x := types.NewFieldType(mysql.TypeYear)
- x.Flen = $2.(int)
- if x.Flen != types.UnspecifiedLength && x.Flen != 4 {
- yylex.AppendError(ErrInvalidYearColumnLength.GenWithStackByArgs())
- return -1
- }
- $$ = x
- }
- FieldLen:
- '(' LengthNum ')'
- {
- $$ = int($2.(uint64))
- }
- OptFieldLen:
- {
- $$ = types.UnspecifiedLength
- }
- | FieldLen
- FieldOpt:
- "UNSIGNED"
- {
- $$ = &ast.TypeOpt{IsUnsigned: true}
- }
- | "SIGNED"
- {
- $$ = &ast.TypeOpt{IsUnsigned: false}
- }
- | "ZEROFILL"
- {
- $$ = &ast.TypeOpt{IsZerofill: true, IsUnsigned: true}
- }
- FieldOpts:
- {
- $$ = []*ast.TypeOpt{}
- }
- | FieldOpts FieldOpt
- {
- $$ = append($1.([]*ast.TypeOpt), $2.(*ast.TypeOpt))
- }
- FloatOpt:
- {
- $$ = &ast.FloatOpt{Flen: types.UnspecifiedLength, Decimal: types.UnspecifiedLength}
- }
- | FieldLen
- {
- $$ = &ast.FloatOpt{Flen: $1.(int), Decimal: types.UnspecifiedLength}
- }
- | Precision
- Precision:
- '(' LengthNum ',' LengthNum ')'
- {
- $$ = &ast.FloatOpt{Flen: int($2.(uint64)), Decimal: int($4.(uint64))}
- }
- OptBinMod:
- {
- $$ = false
- }
- | "BINARY"
- {
- $$ = true
- }
- OptBinary:
- {
- $$ = &ast.OptBinary{
- IsBinary: false,
- Charset: "",
- }
- }
- | "BINARY" OptCharset
- {
- $$ = &ast.OptBinary{
- IsBinary: true,
- Charset: $2,
- }
- }
- | CharsetKw CharsetName OptBinMod
- {
- $$ = &ast.OptBinary{
- IsBinary: $3.(bool),
- Charset: $2,
- }
- }
- OptCharset:
- {
- $$ = ""
- }
- | CharsetKw CharsetName
- {
- $$ = $2
- }
- CharsetKw:
- "CHARACTER" "SET"
- | "CHARSET"
- | "CHAR" "SET"
- OptCollate:
- {
- $$ = ""
- }
- | "COLLATE" CollationName
- {
- $$ = $2
- }
- StringList:
- stringLit
- {
- $$ = []string{$1}
- }
- | StringList ',' stringLit
- {
- $$ = append($1.([]string), $3)
- }
- TextString:
- stringLit
- | hexLit
- {
- $$ = $1.(ast.BinaryLiteral).ToString()
- }
- | bitLit
- {
- $$ = $1.(ast.BinaryLiteral).ToString()
- }
- TextStringList:
- TextString
- {
- $$ = []string{$1}
- }
- | TextStringList ',' TextString
- {
- $$ = append($1.([]string), $3)
- }
- StringName:
- stringLit
- | Identifier
- StringNameOrBRIEOptionKeyword:
- StringName
- | "IGNORE"
- | "REPLACE"
- /***********************************************************************************
- * Update Statement
- * See https://dev.mysql.com/doc/refman/5.7/en/update.html
- ***********************************************************************************/
- UpdateStmt:
- UpdateStmtNoWith
- | WithClause UpdateStmtNoWith
- {
- u := $2.(*ast.UpdateStmt)
- u.With = $1.(*ast.WithClause)
- $$ = u
- }
- UpdateStmtNoWith:
- "UPDATE" TableOptimizerHintsOpt PriorityOpt IgnoreOptional TableRef "SET" AssignmentList WhereClauseOptional OrderByOptional LimitClause
- {
- var refs *ast.Join
- if x, ok := $5.(*ast.Join); ok {
- refs = x
- } else {
- refs = &ast.Join{Left: $5.(ast.ResultSetNode)}
- }
- st := &ast.UpdateStmt{
- Priority: $3.(mysql.PriorityEnum),
- TableRefs: &ast.TableRefsClause{TableRefs: refs},
- List: $7.([]*ast.Assignment),
- IgnoreErr: $4.(bool),
- }
- if $2 != nil {
- st.TableHints = $2.([]*ast.TableOptimizerHint)
- }
- if $8 != nil {
- st.Where = $8.(ast.ExprNode)
- }
- if $9 != nil {
- st.Order = $9.(*ast.OrderByClause)
- }
- if $10 != nil {
- st.Limit = $10.(*ast.Limit)
- }
- $$ = st
- }
- | "UPDATE" TableOptimizerHintsOpt PriorityOpt IgnoreOptional TableRefs "SET" AssignmentList WhereClauseOptional
- {
- st := &ast.UpdateStmt{
- Priority: $3.(mysql.PriorityEnum),
- TableRefs: &ast.TableRefsClause{TableRefs: $5.(*ast.Join)},
- List: $7.([]*ast.Assignment),
- IgnoreErr: $4.(bool),
- }
- if $2 != nil {
- st.TableHints = $2.([]*ast.TableOptimizerHint)
- }
- if $8 != nil {
- st.Where = $8.(ast.ExprNode)
- }
- $$ = st
- }
- UseStmt:
- "USE" DBName
- {
- $$ = &ast.UseStmt{DBName: $2}
- }
- WhereClause:
- "WHERE" Expression
- {
- $$ = $2
- }
- WhereClauseOptional:
- {
- $$ = nil
- }
- | WhereClause
- CommaOpt:
- {}
- | ','
- {}
- /************************************************************************************
- * Account Management Statements
- * https://dev.mysql.com/doc/refman/5.7/en/account-management-sql.html
- ************************************************************************************/
- CreateUserStmt:
- "CREATE" "USER" IfNotExists UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions
- {
- // See https://dev.mysql.com/doc/refman/5.7/en/create-user.html
- $$ = &ast.CreateUserStmt{
- IsCreateRole: false,
- IfNotExists: $3.(bool),
- Specs: $4.([]*ast.UserSpec),
- TLSOptions: $5.([]*ast.TLSOption),
- ResourceOptions: $6.([]*ast.ResourceOption),
- PasswordOrLockOptions: $7.([]*ast.PasswordOrLockOption),
- }
- }
- CreateRoleStmt:
- "CREATE" "ROLE" IfNotExists RoleSpecList
- {
- // See https://dev.mysql.com/doc/refman/8.0/en/create-role.html
- $$ = &ast.CreateUserStmt{
- IsCreateRole: true,
- IfNotExists: $3.(bool),
- Specs: $4.([]*ast.UserSpec),
- }
- }
- /* See http://dev.mysql.com/doc/refman/5.7/en/alter-user.html */
- AlterUserStmt:
- "ALTER" "USER" IfExists UserSpecList RequireClauseOpt ConnectionOptions PasswordOrLockOptions
- {
- $$ = &ast.AlterUserStmt{
- IfExists: $3.(bool),
- Specs: $4.([]*ast.UserSpec),
- TLSOptions: $5.([]*ast.TLSOption),
- ResourceOptions: $6.([]*ast.ResourceOption),
- PasswordOrLockOptions: $7.([]*ast.PasswordOrLockOption),
- }
- }
- | "ALTER" "USER" IfExists "USER" '(' ')' "IDENTIFIED" "BY" AuthString
- {
- auth := &ast.AuthOption{
- AuthString: $9,
- ByAuthString: true,
- }
- $$ = &ast.AlterUserStmt{
- IfExists: $3.(bool),
- CurrentAuth: auth,
- }
- }
- /* See https://dev.mysql.com/doc/refman/8.0/en/alter-instance.html */
- AlterInstanceStmt:
- "ALTER" "INSTANCE" InstanceOption
- {
- $$ = $3.(*ast.AlterInstanceStmt)
- }
- InstanceOption:
- "RELOAD" "TLS"
- {
- $$ = &ast.AlterInstanceStmt{
- ReloadTLS: true,
- }
- }
- | "RELOAD" "TLS" "NO" "ROLLBACK" "ON" "ERROR"
- {
- $$ = &ast.AlterInstanceStmt{
- ReloadTLS: true,
- NoRollbackOnError: true,
- }
- }
- UserSpec:
- Username AuthOption
- {
- userSpec := &ast.UserSpec{
- User: $1.(*auth.UserIdentity),
- }
- if $2 != nil {
- userSpec.AuthOpt = $2.(*ast.AuthOption)
- }
- $$ = userSpec
- }
- UserSpecList:
- UserSpec
- {
- $$ = []*ast.UserSpec{$1.(*ast.UserSpec)}
- }
- | UserSpecList ',' UserSpec
- {
- $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec))
- }
- ConnectionOptions:
- {
- l := []*ast.ResourceOption{}
- $$ = l
- }
- | "WITH" ConnectionOptionList
- {
- $$ = $2
- yylex.AppendError(yylex.Errorf("TiDB does not support WITH ConnectionOptions now, they would be parsed but ignored."))
- parser.lastErrorAsWarn()
- }
- ConnectionOptionList:
- ConnectionOption
- {
- $$ = []*ast.ResourceOption{$1.(*ast.ResourceOption)}
- }
- | ConnectionOptionList ConnectionOption
- {
- l := $1.([]*ast.ResourceOption)
- l = append(l, $2.(*ast.ResourceOption))
- $$ = l
- }
- ConnectionOption:
- "MAX_QUERIES_PER_HOUR" Int64Num
- {
- $$ = &ast.ResourceOption{
- Type: ast.MaxQueriesPerHour,
- Count: $2.(int64),
- }
- }
- | "MAX_UPDATES_PER_HOUR" Int64Num
- {
- $$ = &ast.ResourceOption{
- Type: ast.MaxUpdatesPerHour,
- Count: $2.(int64),
- }
- }
- | "MAX_CONNECTIONS_PER_HOUR" Int64Num
- {
- $$ = &ast.ResourceOption{
- Type: ast.MaxConnectionsPerHour,
- Count: $2.(int64),
- }
- }
- | "MAX_USER_CONNECTIONS" Int64Num
- {
- $$ = &ast.ResourceOption{
- Type: ast.MaxUserConnections,
- Count: $2.(int64),
- }
- }
- RequireClauseOpt:
- {
- $$ = []*ast.TLSOption{}
- }
- | RequireClause
- RequireClause:
- "REQUIRE" "NONE"
- {
- t := &ast.TLSOption{
- Type: ast.TslNone,
- }
- $$ = []*ast.TLSOption{t}
- }
- | "REQUIRE" "SSL"
- {
- t := &ast.TLSOption{
- Type: ast.Ssl,
- }
- $$ = []*ast.TLSOption{t}
- }
- | "REQUIRE" "X509"
- {
- t := &ast.TLSOption{
- Type: ast.X509,
- }
- $$ = []*ast.TLSOption{t}
- }
- | "REQUIRE" RequireList
- {
- $$ = $2
- }
- RequireList:
- RequireListElement
- {
- $$ = []*ast.TLSOption{$1.(*ast.TLSOption)}
- }
- | RequireList "AND" RequireListElement
- {
- l := $1.([]*ast.TLSOption)
- l = append(l, $3.(*ast.TLSOption))
- $$ = l
- }
- | RequireList RequireListElement
- {
- l := $1.([]*ast.TLSOption)
- l = append(l, $2.(*ast.TLSOption))
- $$ = l
- }
- RequireListElement:
- "ISSUER" stringLit
- {
- $$ = &ast.TLSOption{
- Type: ast.Issuer,
- Value: $2,
- }
- }
- | "SUBJECT" stringLit
- {
- $$ = &ast.TLSOption{
- Type: ast.Subject,
- Value: $2,
- }
- }
- | "CIPHER" stringLit
- {
- $$ = &ast.TLSOption{
- Type: ast.Cipher,
- Value: $2,
- }
- }
- | "SAN" stringLit
- {
- $$ = &ast.TLSOption{
- Type: ast.SAN,
- Value: $2,
- }
- }
- PasswordOrLockOptions:
- {
- l := []*ast.PasswordOrLockOption{}
- $$ = l
- }
- | PasswordOrLockOptionList
- {
- $$ = $1
- yylex.AppendError(yylex.Errorf("TiDB does not support PASSWORD EXPIRE and ACCOUNT LOCK now, they would be parsed but ignored."))
- parser.lastErrorAsWarn()
- }
- PasswordOrLockOptionList:
- PasswordOrLockOption
- {
- $$ = []*ast.PasswordOrLockOption{$1.(*ast.PasswordOrLockOption)}
- }
- | PasswordOrLockOptionList PasswordOrLockOption
- {
- l := $1.([]*ast.PasswordOrLockOption)
- l = append(l, $2.(*ast.PasswordOrLockOption))
- $$ = l
- }
- PasswordOrLockOption:
- "ACCOUNT" "UNLOCK"
- {
- $$ = &ast.PasswordOrLockOption{
- Type: ast.Unlock,
- }
- }
- | "ACCOUNT" "LOCK"
- {
- $$ = &ast.PasswordOrLockOption{
- Type: ast.Lock,
- }
- }
- | PasswordExpire
- {
- $$ = &ast.PasswordOrLockOption{
- Type: ast.PasswordExpire,
- }
- }
- | PasswordExpire "INTERVAL" Int64Num "DAY"
- {
- $$ = &ast.PasswordOrLockOption{
- Type: ast.PasswordExpireInterval,
- Count: $3.(int64),
- }
- }
- | PasswordExpire "NEVER"
- {
- $$ = &ast.PasswordOrLockOption{
- Type: ast.PasswordExpireNever,
- }
- }
- | PasswordExpire "DEFAULT"
- {
- $$ = &ast.PasswordOrLockOption{
- Type: ast.PasswordExpireDefault,
- }
- }
- PasswordExpire:
- "PASSWORD" "EXPIRE" ClearPasswordExpireOptions
- {
- $$ = nil
- }
- ClearPasswordExpireOptions:
- {
- $$ = nil
- }
- AuthOption:
- {
- $$ = nil
- }
- | "IDENTIFIED" "BY" AuthString
- {
- $$ = &ast.AuthOption{
- AuthString: $3,
- ByAuthString: true,
- }
- }
- | "IDENTIFIED" "WITH" StringName
- {
- $$ = nil
- }
- | "IDENTIFIED" "WITH" StringName "BY" AuthString
- {
- $$ = &ast.AuthOption{
- AuthString: $5,
- ByAuthString: true,
- }
- }
- | "IDENTIFIED" "WITH" StringName "AS" HashString
- {
- $$ = &ast.AuthOption{
- HashString: $5,
- }
- }
- | "IDENTIFIED" "BY" "PASSWORD" HashString
- {
- $$ = &ast.AuthOption{
- HashString: $4,
- }
- }
- HashString:
- stringLit
- RoleSpec:
- Rolename
- {
- role := $1.(*auth.RoleIdentity)
- roleSpec := &ast.UserSpec{
- User: &auth.UserIdentity{
- Username: role.Username,
- Hostname: role.Hostname,
- },
- IsRole: true,
- }
- $$ = roleSpec
- }
- RoleSpecList:
- RoleSpec
- {
- $$ = []*ast.UserSpec{$1.(*ast.UserSpec)}
- }
- | RoleSpecList ',' RoleSpec
- {
- $$ = append($1.([]*ast.UserSpec), $3.(*ast.UserSpec))
- }
- BindableStmt:
- SetOprStmt1
- | UpdateStmt
- | DeleteWithoutUsingStmt
- | InsertIntoStmt
- | ReplaceIntoStmt
- /*******************************************************************
- *
- * Create Binding Statement
- *
- * Example:
- * CREATE GLOBAL BINDING FOR select Col1,Col2 from table USING select Col1,Col2 from table use index(Col1)
- *******************************************************************/
- CreateBindingStmt:
- "CREATE" GlobalScope "BINDING" "FOR" BindableStmt "USING" BindableStmt
- {
- startOffset := parser.startOffset(&yyS[yypt-2])
- endOffset := parser.startOffset(&yyS[yypt-1])
- originStmt := $5
- originStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset]))
- startOffset = parser.startOffset(&yyS[yypt])
- hintedStmt := $7
- hintedStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
- x := &ast.CreateBindingStmt{
- OriginNode: originStmt,
- HintedNode: hintedStmt,
- GlobalScope: $2.(bool),
- }
- $$ = x
- }
- /*******************************************************************
- *
- * Drop Binding Statement
- *
- * Example:
- * DROP GLOBAL BINDING FOR select Col1,Col2 from table
- *******************************************************************/
- DropBindingStmt:
- "DROP" GlobalScope "BINDING" "FOR" BindableStmt
- {
- startOffset := parser.startOffset(&yyS[yypt])
- originStmt := $5
- originStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
- x := &ast.DropBindingStmt{
- OriginNode: originStmt,
- GlobalScope: $2.(bool),
- }
- $$ = x
- }
- | "DROP" GlobalScope "BINDING" "FOR" BindableStmt "USING" BindableStmt
- {
- startOffset := parser.startOffset(&yyS[yypt-2])
- endOffset := parser.startOffset(&yyS[yypt-1])
- originStmt := $5
- originStmt.SetText(strings.TrimSpace(parser.src[startOffset:endOffset]))
- startOffset = parser.startOffset(&yyS[yypt])
- hintedStmt := $7
- hintedStmt.SetText(strings.TrimSpace(parser.src[startOffset:]))
- x := &ast.DropBindingStmt{
- OriginNode: originStmt,
- HintedNode: hintedStmt,
- GlobalScope: $2.(bool),
- }
- $$ = x
- }
- /*************************************************************************************
- * Grant statement
- * See https://dev.mysql.com/doc/refman/5.7/en/grant.html
- *************************************************************************************/
- GrantStmt:
- "GRANT" RoleOrPrivElemList "ON" ObjectType PrivLevel "TO" UserSpecList RequireClauseOpt WithGrantOptionOpt
- {
- p, err := convertToPriv($2.([]*ast.RoleOrPriv))
- if err != nil {
- yylex.AppendError(err)
- return 1
- }
- $$ = &ast.GrantStmt{
- Privs: p,
- ObjectType: $4.(ast.ObjectTypeType),
- Level: $5.(*ast.GrantLevel),
- Users: $7.([]*ast.UserSpec),
- TLSOptions: $8.([]*ast.TLSOption),
- WithGrant: $9.(bool),
- }
- }
- GrantProxyStmt:
- "GRANT" "PROXY" "ON" Username "TO" UsernameList WithGrantOptionOpt
- {
- $$ = &ast.GrantProxyStmt{
- LocalUser: $4.(*auth.UserIdentity),
- ExternalUsers: $6.([]*auth.UserIdentity),
- WithGrant: $7.(bool),
- }
- }
- GrantRoleStmt:
- "GRANT" RoleOrPrivElemList "TO" UsernameList
- {
- r, err := convertToRole($2.([]*ast.RoleOrPriv))
- if err != nil {
- yylex.AppendError(err)
- return 1
- }
- $$ = &ast.GrantRoleStmt{
- Roles: r,
- Users: $4.([]*auth.UserIdentity),
- }
- }
- WithGrantOptionOpt:
- {
- $$ = false
- }
- | "WITH" "GRANT" "OPTION"
- {
- $$ = true
- }
- | "WITH" "MAX_QUERIES_PER_HOUR" NUM
- {
- $$ = false
- }
- | "WITH" "MAX_UPDATES_PER_HOUR" NUM
- {
- $$ = false
- }
- | "WITH" "MAX_CONNECTIONS_PER_HOUR" NUM
- {
- $$ = false
- }
- | "WITH" "MAX_USER_CONNECTIONS" NUM
- {
- $$ = false
- }
- ExtendedPriv:
- identifier
- {
- $$ = []string{$1}
- }
- | ExtendedPriv identifier
- {
- $$ = append($1.([]string), $2)
- }
- RoleOrPrivElem:
- PrivElem
- {
- $$ = &ast.RoleOrPriv{
- Node: $1,
- }
- }
- | RolenameWithoutIdent
- {
- $$ = &ast.RoleOrPriv{
- Node: $1,
- }
- }
- | ExtendedPriv
- {
- $$ = &ast.RoleOrPriv{
- Symbols: strings.Join($1.([]string), " "),
- }
- }
- | "LOAD" "FROM" "S3"
- {
- $$ = &ast.RoleOrPriv{
- Symbols: "LOAD FROM S3",
- }
- }
- | "SELECT" "INTO" "S3"
- {
- $$ = &ast.RoleOrPriv{
- Symbols: "SELECT INTO S3",
- }
- }
- RoleOrPrivElemList:
- RoleOrPrivElem
- {
- $$ = []*ast.RoleOrPriv{$1.(*ast.RoleOrPriv)}
- }
- | RoleOrPrivElemList ',' RoleOrPrivElem
- {
- $$ = append($1.([]*ast.RoleOrPriv), $3.(*ast.RoleOrPriv))
- }
- PrivElem:
- PrivType
- {
- $$ = &ast.PrivElem{
- Priv: $1.(mysql.PrivilegeType),
- }
- }
- | PrivType '(' ColumnNameList ')'
- {
- $$ = &ast.PrivElem{
- Priv: $1.(mysql.PrivilegeType),
- Cols: $3.([]*ast.ColumnName),
- }
- }
- PrivType:
- "ALL"
- {
- $$ = mysql.AllPriv
- }
- | "ALL" "PRIVILEGES"
- {
- $$ = mysql.AllPriv
- }
- | "ALTER"
- {
- $$ = mysql.AlterPriv
- }
- | "CREATE"
- {
- $$ = mysql.CreatePriv
- }
- | "CREATE" "USER"
- {
- $$ = mysql.CreateUserPriv
- }
- | "CREATE" "TABLESPACE"
- {
- $$ = mysql.CreateTablespacePriv
- }
- | "TRIGGER"
- {
- $$ = mysql.TriggerPriv
- }
- | "DELETE"
- {
- $$ = mysql.DeletePriv
- }
- | "DROP"
- {
- $$ = mysql.DropPriv
- }
- | "PROCESS"
- {
- $$ = mysql.ProcessPriv
- }
- | "EXECUTE"
- {
- $$ = mysql.ExecutePriv
- }
- | "INDEX"
- {
- $$ = mysql.IndexPriv
- }
- | "INSERT"
- {
- $$ = mysql.InsertPriv
- }
- | "SELECT"
- {
- $$ = mysql.SelectPriv
- }
- | "SUPER"
- {
- $$ = mysql.SuperPriv
- }
- | "SHOW" "DATABASES"
- {
- $$ = mysql.ShowDBPriv
- }
- | "UPDATE"
- {
- $$ = mysql.UpdatePriv
- }
- | "GRANT" "OPTION"
- {
- $$ = mysql.GrantPriv
- }
- | "REFERENCES"
- {
- $$ = mysql.ReferencesPriv
- }
- | "REPLICATION" "SLAVE"
- {
- $$ = mysql.ReplicationSlavePriv
- }
- | "REPLICATION" "CLIENT"
- {
- $$ = mysql.ReplicationClientPriv
- }
- | "USAGE"
- {
- $$ = mysql.UsagePriv
- }
- | "RELOAD"
- {
- $$ = mysql.ReloadPriv
- }
- | "FILE"
- {
- $$ = mysql.FilePriv
- }
- | "CONFIG"
- {
- $$ = mysql.ConfigPriv
- }
- | "CREATE" "TEMPORARY" "TABLES"
- {
- $$ = mysql.CreateTMPTablePriv
- }
- | "LOCK" "TABLES"
- {
- $$ = mysql.LockTablesPriv
- }
- | "CREATE" "VIEW"
- {
- $$ = mysql.CreateViewPriv
- }
- | "SHOW" "VIEW"
- {
- $$ = mysql.ShowViewPriv
- }
- | "CREATE" "ROLE"
- {
- $$ = mysql.CreateRolePriv
- }
- | "DROP" "ROLE"
- {
- $$ = mysql.DropRolePriv
- }
- | "CREATE" "ROUTINE"
- {
- $$ = mysql.CreateRoutinePriv
- }
- | "ALTER" "ROUTINE"
- {
- $$ = mysql.AlterRoutinePriv
- }
- | "EVENT"
- {
- $$ = mysql.EventPriv
- }
- | "SHUTDOWN"
- {
- $$ = mysql.ShutdownPriv
- }
- ObjectType:
- %prec lowerThanFunction
- {
- $$ = ast.ObjectTypeNone
- }
- | "TABLE"
- {
- $$ = ast.ObjectTypeTable
- }
- | "FUNCTION"
- {
- $$ = ast.ObjectTypeFunction
- }
- | "PROCEDURE"
- {
- $$ = ast.ObjectTypeProcedure
- }
- PrivLevel:
- '*'
- {
- $$ = &ast.GrantLevel{
- Level: ast.GrantLevelDB,
- }
- }
- | '*' '.' '*'
- {
- $$ = &ast.GrantLevel{
- Level: ast.GrantLevelGlobal,
- }
- }
- | Identifier '.' '*'
- {
- $$ = &ast.GrantLevel{
- Level: ast.GrantLevelDB,
- DBName: $1,
- }
- }
- | Identifier '.' Identifier
- {
- $$ = &ast.GrantLevel{
- Level: ast.GrantLevelTable,
- DBName: $1,
- TableName: $3,
- }
- }
- | Identifier
- {
- $$ = &ast.GrantLevel{
- Level: ast.GrantLevelTable,
- TableName: $1,
- }
- }
- /**************************************RevokeStmt*******************************************
- * See https://dev.mysql.com/doc/refman/5.7/en/revoke.html
- *******************************************************************************************/
- RevokeStmt:
- "REVOKE" RoleOrPrivElemList "ON" ObjectType PrivLevel "FROM" UserSpecList
- {
- p, err := convertToPriv($2.([]*ast.RoleOrPriv))
- if err != nil {
- yylex.AppendError(err)
- return 1
- }
- $$ = &ast.RevokeStmt{
- Privs: p,
- ObjectType: $4.(ast.ObjectTypeType),
- Level: $5.(*ast.GrantLevel),
- Users: $7.([]*ast.UserSpec),
- }
- }
- RevokeRoleStmt:
- "REVOKE" RoleOrPrivElemList "FROM" UsernameList
- {
- r, err := convertToRole($2.([]*ast.RoleOrPriv))
- if err != nil {
- yylex.AppendError(err)
- return 1
- }
- $$ = &ast.RevokeRoleStmt{
- Roles: r,
- Users: $4.([]*auth.UserIdentity),
- }
- }
- /**************************************LoadDataStmt*****************************************
- * See https://dev.mysql.com/doc/refman/5.7/en/load-data.html
- *******************************************************************************************/
- LoadDataStmt:
- "LOAD" "DATA" LocalOpt "INFILE" stringLit DuplicateOpt "INTO" "TABLE" TableName CharsetOpt Fields Lines IgnoreLines ColumnNameOrUserVarListOptWithBrackets LoadDataSetSpecOpt
- {
- x := &ast.LoadDataStmt{
- Path: $5,
- OnDuplicate: $6.(ast.OnDuplicateKeyHandlingType),
- Table: $9.(*ast.TableName),
- ColumnsAndUserVars: $14.([]*ast.ColumnNameOrUserVar),
- IgnoreLines: $13.(uint64),
- }
- if $3 != nil {
- x.IsLocal = true
- // See https://dev.mysql.com/doc/refman/5.7/en/load-data.html#load-data-duplicate-key-handling
- // If you do not specify IGNORE or REPLACE modifier , then we set default behavior to IGNORE when LOCAL modifier is specified
- if x.OnDuplicate == ast.OnDuplicateKeyHandlingError {
- x.OnDuplicate = ast.OnDuplicateKeyHandlingIgnore
- }
- }
- if $11 != nil {
- x.FieldsInfo = $11.(*ast.FieldsClause)
- }
- if $12 != nil {
- x.LinesInfo = $12.(*ast.LinesClause)
- }
- if $15 != nil {
- x.ColumnAssignments = $15.([]*ast.Assignment)
- }
- columns := []*ast.ColumnName{}
- for _, v := range x.ColumnsAndUserVars {
- if v.ColumnName != nil {
- columns = append(columns, v.ColumnName)
- }
- }
- x.Columns = columns
- $$ = x
- }
- IgnoreLines:
- {
- $$ = uint64(0)
- }
- | "IGNORE" NUM "LINES"
- {
- $$ = getUint64FromNUM($2)
- }
- CharsetOpt:
- {}
- | "CHARACTER" "SET" CharsetName
- LocalOpt:
- {
- $$ = nil
- }
- | "LOCAL"
- {
- $$ = $1
- }
- Fields:
- {
- escape := "\\"
- $$ = &ast.FieldsClause{
- Terminated: "\t",
- Escaped: escape[0],
- }
- }
- | FieldsOrColumns FieldItemList
- {
- fieldsClause := &ast.FieldsClause{
- Terminated: "\t",
- Escaped: []byte("\\")[0],
- }
- fieldItems := $2.([]*ast.FieldItem)
- for _, item := range fieldItems {
- switch item.Type {
- case ast.Terminated:
- fieldsClause.Terminated = item.Value
- case ast.Enclosed:
- var enclosed byte
- if len(item.Value) > 0 {
- enclosed = item.Value[0]
- }
- fieldsClause.Enclosed = enclosed
- if item.OptEnclosed {
- fieldsClause.OptEnclosed = true
- }
- case ast.Escaped:
- var escaped byte
- if len(item.Value) > 0 {
- escaped = item.Value[0]
- }
- fieldsClause.Escaped = escaped
- }
- }
- $$ = fieldsClause
- }
- FieldsOrColumns:
- "FIELDS"
- | "COLUMNS"
- FieldItemList:
- FieldItemList FieldItem
- {
- fieldItems := $1.([]*ast.FieldItem)
- $$ = append(fieldItems, $2.(*ast.FieldItem))
- }
- | FieldItem
- {
- fieldItems := make([]*ast.FieldItem, 1, 1)
- fieldItems[0] = $1.(*ast.FieldItem)
- $$ = fieldItems
- }
- FieldItem:
- "TERMINATED" "BY" FieldTerminator
- {
- $$ = &ast.FieldItem{
- Type: ast.Terminated,
- Value: $3,
- }
- }
- | "OPTIONALLY" "ENCLOSED" "BY" FieldTerminator
- {
- str := $4
- if str != "\\" && len(str) > 1 {
- yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs())
- return 1
- }
- $$ = &ast.FieldItem{
- Type: ast.Enclosed,
- Value: str,
- OptEnclosed: true,
- }
- }
- | "ENCLOSED" "BY" FieldTerminator
- {
- str := $3
- if str != "\\" && len(str) > 1 {
- yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs())
- return 1
- }
- $$ = &ast.FieldItem{
- Type: ast.Enclosed,
- Value: str,
- }
- }
- | "ESCAPED" "BY" FieldTerminator
- {
- str := $3
- if str != "\\" && len(str) > 1 {
- yylex.AppendError(ErrWrongFieldTerminators.GenWithStackByArgs())
- return 1
- }
- $$ = &ast.FieldItem{
- Type: ast.Escaped,
- Value: str,
- }
- }
- FieldTerminator:
- stringLit
- | hexLit
- {
- $$ = $1.(ast.BinaryLiteral).ToString()
- }
- | bitLit
- {
- $$ = $1.(ast.BinaryLiteral).ToString()
- }
- Lines:
- {
- $$ = &ast.LinesClause{Terminated: "\n"}
- }
- | "LINES" Starting LinesTerminated
- {
- $$ = &ast.LinesClause{Starting: $2, Terminated: $3}
- }
- Starting:
- {
- $$ = ""
- }
- | "STARTING" "BY" stringLit
- {
- $$ = $3
- }
- LinesTerminated:
- {
- $$ = "\n"
- }
- | "TERMINATED" "BY" stringLit
- {
- $$ = $3
- }
- LoadDataSetSpecOpt:
- {
- $$ = nil
- }
- | "SET" LoadDataSetList
- {
- $$ = $2
- }
- LoadDataSetList:
- LoadDataSetList ',' LoadDataSetItem
- {
- l := $1.([]*ast.Assignment)
- $$ = append(l, $3.(*ast.Assignment))
- }
- | LoadDataSetItem
- {
- $$ = []*ast.Assignment{$1.(*ast.Assignment)}
- }
- LoadDataSetItem:
- SimpleIdent "=" ExprOrDefault
- {
- $$ = &ast.Assignment{
- Column: $1.(*ast.ColumnNameExpr).Name,
- Expr: $3,
- }
- }
- /*********************************************************************
- * Lock/Unlock Tables
- * See http://dev.mysql.com/doc/refman/5.7/en/lock-tables.html
- * All the statement leaves empty. This is used to prevent mysqldump error.
- *********************************************************************/
- UnlockTablesStmt:
- "UNLOCK" TablesTerminalSym
- {
- $$ = &ast.UnlockTablesStmt{}
- }
- LockTablesStmt:
- "LOCK" TablesTerminalSym TableLockList
- {
- $$ = &ast.LockTablesStmt{
- TableLocks: $3.([]ast.TableLock),
- }
- }
- TablesTerminalSym:
- "TABLES"
- | "TABLE"
- TableLock:
- TableName LockType
- {
- $$ = ast.TableLock{
- Table: $1.(*ast.TableName),
- Type: $2.(model.TableLockType),
- }
- }
- LockType:
- "READ"
- {
- $$ = model.TableLockRead
- }
- | "READ" "LOCAL"
- {
- $$ = model.TableLockReadLocal
- }
- | "WRITE"
- {
- $$ = model.TableLockWrite
- }
- | "WRITE" "LOCAL"
- {
- $$ = model.TableLockWriteLocal
- }
- TableLockList:
- TableLock
- {
- $$ = []ast.TableLock{$1.(ast.TableLock)}
- }
- | TableLockList ',' TableLock
- {
- $$ = append($1.([]ast.TableLock), $3.(ast.TableLock))
- }
- /********************************************************************
- * Kill Statement
- * See https://dev.mysql.com/doc/refman/5.7/en/kill.html
- *******************************************************************/
- KillStmt:
- KillOrKillTiDB NUM
- {
- $$ = &ast.KillStmt{
- ConnectionID: getUint64FromNUM($2),
- TiDBExtension: $1.(bool),
- }
- }
- | KillOrKillTiDB "CONNECTION" NUM
- {
- $$ = &ast.KillStmt{
- ConnectionID: getUint64FromNUM($3),
- TiDBExtension: $1.(bool),
- }
- }
- | KillOrKillTiDB "QUERY" NUM
- {
- $$ = &ast.KillStmt{
- ConnectionID: getUint64FromNUM($3),
- Query: true,
- TiDBExtension: $1.(bool),
- }
- }
- KillOrKillTiDB:
- "KILL"
- {
- $$ = false
- }
- /* KILL TIDB is a special grammar extension in TiDB, it can be used only when
- the client connect to TiDB directly, not proxied under LVS. */
- | "KILL" "TIDB"
- {
- $$ = true
- }
- LoadStatsStmt:
- "LOAD" "STATS" stringLit
- {
- $$ = &ast.LoadStatsStmt{
- Path: $3,
- }
- }
- /********************************************************************************************
- *
- * Create Sequence Statement
- *
- * Example:
- * CREATE [TEMPORARY] SEQUENCE [IF NOT EXISTS] sequence_name
- * [ INCREMENT [ BY | = ] increment ]
- * [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]
- * [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]
- * [ START [ WITH | = ] start ]
- * [ CACHE [=] cache | NOCACHE | NO CACHE]
- * [ CYCLE | NOCYCLE | NO CYCLE]
- * [table_options]
- ********************************************************************************************/
- CreateSequenceStmt:
- "CREATE" "SEQUENCE" IfNotExists TableName CreateSequenceOptionListOpt CreateTableOptionListOpt
- {
- $$ = &ast.CreateSequenceStmt{
- IfNotExists: $3.(bool),
- Name: $4.(*ast.TableName),
- SeqOptions: $5.([]*ast.SequenceOption),
- TblOptions: $6.([]*ast.TableOption),
- }
- }
- CreateSequenceOptionListOpt:
- {
- $$ = []*ast.SequenceOption{}
- }
- | SequenceOptionList
- SequenceOptionList:
- SequenceOption
- {
- $$ = []*ast.SequenceOption{$1.(*ast.SequenceOption)}
- }
- | SequenceOptionList SequenceOption
- {
- $$ = append($1.([]*ast.SequenceOption), $2.(*ast.SequenceOption))
- }
- SequenceOption:
- "INCREMENT" EqOpt SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceOptionIncrementBy, IntValue: $3.(int64)}
- }
- | "INCREMENT" "BY" SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceOptionIncrementBy, IntValue: $3.(int64)}
- }
- | "START" EqOpt SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceStartWith, IntValue: $3.(int64)}
- }
- | "START" "WITH" SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceStartWith, IntValue: $3.(int64)}
- }
- | "MINVALUE" EqOpt SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceMinValue, IntValue: $3.(int64)}
- }
- | "NOMINVALUE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoMinValue}
- }
- | "NO" "MINVALUE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoMinValue}
- }
- | "MAXVALUE" EqOpt SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceMaxValue, IntValue: $3.(int64)}
- }
- | "NOMAXVALUE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoMaxValue}
- }
- | "NO" "MAXVALUE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoMaxValue}
- }
- | "CACHE" EqOpt SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceCache, IntValue: $3.(int64)}
- }
- | "NOCACHE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoCache}
- }
- | "NO" "CACHE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoCache}
- }
- | "CYCLE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceCycle}
- }
- | "NOCYCLE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoCycle}
- }
- | "NO" "CYCLE"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceNoCycle}
- }
- SignedNum:
- Int64Num
- | '+' Int64Num
- {
- $$ = $2
- }
- | '-' NUM
- {
- unsigned_num := getUint64FromNUM($2)
- if unsigned_num > 9223372036854775808 {
- yylex.AppendError(yylex.Errorf("the Signed Value should be at the range of [-9223372036854775808, 9223372036854775807]."))
- return 1
- } else if unsigned_num == 9223372036854775808 {
- signed_one := int64(1)
- $$ = signed_one << 63
- } else {
- $$ = -int64(unsigned_num)
- }
- }
- DropSequenceStmt:
- "DROP" "SEQUENCE" IfExists TableNameList
- {
- $$ = &ast.DropSequenceStmt{
- IfExists: $3.(bool),
- Sequences: $4.([]*ast.TableName),
- }
- }
- /********************************************************************************************
- *
- * Alter Sequence Statement
- *
- * Example:
- * ALTER SEQUENCE [IF EXISTS] sequence_name
- * [ INCREMENT [ BY | = ] increment ]
- * [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]
- * [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]
- * [ START [ WITH | = ] start ]
- * [ CACHE [=] cache | NOCACHE | NO CACHE]
- * [ CYCLE | NOCYCLE | NO CYCLE]
- * [ RESTART [WITH | = ] restart ]
- ********************************************************************************************/
- AlterSequenceStmt:
- "ALTER" "SEQUENCE" IfExists TableName AlterSequenceOptionList
- {
- $$ = &ast.AlterSequenceStmt{
- IfExists: $3.(bool),
- Name: $4.(*ast.TableName),
- SeqOptions: $5.([]*ast.SequenceOption),
- }
- }
- AlterSequenceOptionList:
- AlterSequenceOption
- {
- $$ = []*ast.SequenceOption{$1.(*ast.SequenceOption)}
- }
- | AlterSequenceOptionList AlterSequenceOption
- {
- $$ = append($1.([]*ast.SequenceOption), $2.(*ast.SequenceOption))
- }
- AlterSequenceOption:
- SequenceOption
- | "RESTART"
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceRestart}
- }
- | "RESTART" EqOpt SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceRestartWith, IntValue: $3.(int64)}
- }
- | "RESTART" "WITH" SignedNum
- {
- $$ = &ast.SequenceOption{Tp: ast.SequenceRestartWith, IntValue: $3.(int64)}
- }
- /********************************************************************
- * Index Advisor Statement
- *
- * INDEX ADVISE
- * [LOCAL]
- * INFILE 'file_name'
- * [MAX_MINUTES number]
- * [MAX_IDXNUM
- * [PER_TABLE number]
- * [PER_DB number]
- * ]
- * [LINES
- * [STARTING BY 'string']
- * [TERMINATED BY 'string']
- * ]
- *******************************************************************/
- IndexAdviseStmt:
- "INDEX" "ADVISE" LocalOpt "INFILE" stringLit MaxMinutesOpt MaxIndexNumOpt Lines
- {
- x := &ast.IndexAdviseStmt{
- Path: $5,
- MaxMinutes: $6.(uint64),
- }
- if $3 != nil {
- x.IsLocal = true
- }
- if $7 != nil {
- x.MaxIndexNum = $7.(*ast.MaxIndexNumClause)
- }
- if $8 != nil {
- x.LinesInfo = $8.(*ast.LinesClause)
- }
- $$ = x
- }
- MaxMinutesOpt:
- {
- $$ = uint64(ast.UnspecifiedSize)
- }
- | "MAX_MINUTES" NUM
- {
- $$ = getUint64FromNUM($2)
- }
- MaxIndexNumOpt:
- {
- $$ = nil
- }
- | "MAX_IDXNUM" PerTable PerDB
- {
- $$ = &ast.MaxIndexNumClause{
- PerTable: $2.(uint64),
- PerDB: $3.(uint64),
- }
- }
- PerTable:
- {
- $$ = uint64(ast.UnspecifiedSize)
- }
- | "PER_TABLE" NUM
- {
- $$ = getUint64FromNUM($2)
- }
- PerDB:
- {
- $$ = uint64(ast.UnspecifiedSize)
- }
- | "PER_DB" NUM
- {
- $$ = getUint64FromNUM($2)
- }
- EncryptionOpt:
- stringLit
- {
- // Parse it but will ignore it
- switch $1 {
- case "Y", "y":
- yylex.AppendError(yylex.Errorf("The ENCRYPTION clause is parsed but ignored by all storage engines."))
- parser.lastErrorAsWarn()
- case "N", "n":
- break
- default:
- yylex.AppendError(ErrWrongValue.GenWithStackByArgs("argument (should be Y or N)", $1))
- return 1
- }
- $$ = $1
- }
- ValuesStmtList:
- RowStmt
- {
- $$ = append([]*ast.RowExpr{}, $1.(*ast.RowExpr))
- }
- | ValuesStmtList ',' RowStmt
- {
- $$ = append($1.([]*ast.RowExpr), $3.(*ast.RowExpr))
- }
- RowStmt:
- "ROW" RowValue
- {
- $$ = &ast.RowExpr{Values: $2.([]ast.ExprNode)}
- }
- %%
|