handler.h 240 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919
  1. #ifndef HANDLER_INCLUDED
  2. #define HANDLER_INCLUDED
  3. /*
  4. Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License, version 2.0,
  7. as published by the Free Software Foundation.
  8. This program is also distributed with certain software (including
  9. but not limited to OpenSSL) that is licensed under separate terms,
  10. as designated in a particular file or component or in included license
  11. documentation. The authors of MySQL hereby grant you an additional
  12. permission to link the program and your derivative works with the
  13. separately licensed software that they have included with MySQL.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License, version 2.0, for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. /* Definitions for parameters to do with handler-routines */
  23. #include <fcntl.h>
  24. #include <float.h>
  25. #include <string.h>
  26. #include <sys/types.h>
  27. #include <time.h>
  28. #include <algorithm>
  29. #include <bitset>
  30. #include <functional>
  31. #include <map>
  32. #include <random> // std::mt19937
  33. #include <set>
  34. #include <string>
  35. #include <mysql/components/services/page_track_service.h>
  36. #include "ft_global.h" // ft_hints
  37. #include "lex_string.h"
  38. #include "m_ctype.h"
  39. #include "map_helpers.h"
  40. #include "my_alloc.h"
  41. #include "my_base.h"
  42. #include "my_bitmap.h"
  43. #include "my_compiler.h"
  44. #include "my_dbug.h"
  45. #include "my_double2ulonglong.h"
  46. #include "my_inttypes.h"
  47. #include "my_io.h"
  48. #include "my_sys.h"
  49. #include "my_thread_local.h" // my_errno
  50. #include "mysql/components/services/psi_table_bits.h"
  51. #include "sql/dd/object_id.h" // dd::Object_id
  52. #include "sql/dd/string_type.h"
  53. #include "sql/dd/types/object_table.h" // dd::Object_table
  54. #include "sql/discrete_interval.h" // Discrete_interval
  55. #include "sql/key.h"
  56. #include "sql/sql_const.h" // SHOW_COMP_OPTION
  57. #include "sql/sql_list.h" // SQL_I_List
  58. #include "sql/sql_plugin_ref.h" // plugin_ref
  59. #include "thr_lock.h" // thr_lock_type
  60. #include "typelib.h"
  61. class Alter_info;
  62. class Candidate_table_order;
  63. class Create_field;
  64. class Field;
  65. class Item;
  66. class JOIN;
  67. class Json_dom;
  68. class Partition_handler;
  69. class Plugin_table;
  70. class Plugin_tablespace;
  71. class Record_buffer;
  72. class SE_cost_constants; // see opt_costconstants.h
  73. class String;
  74. class THD;
  75. class handler;
  76. class partition_info;
  77. struct System_status_var;
  78. namespace dd {
  79. class Properties;
  80. } // namespace dd
  81. struct FOREIGN_KEY_INFO;
  82. struct KEY_CACHE;
  83. struct LEX;
  84. struct MY_BITMAP;
  85. struct SAVEPOINT;
  86. struct TABLE;
  87. struct TABLE_LIST;
  88. struct TABLE_SHARE;
  89. struct Tablespace_options;
  90. struct handlerton;
  91. typedef struct xid_t XID;
  92. typedef struct st_xarecover_txn XA_recover_txn;
  93. struct MDL_key;
  94. namespace dd {
  95. enum class enum_column_types;
  96. class Table;
  97. class Tablespace;
  98. } // namespace dd
  99. /** Id for identifying Table SDIs */
  100. constexpr const uint32 SDI_TYPE_TABLE = 1;
  101. /** Id for identifying Tablespace SDIs */
  102. constexpr const uint32 SDI_TYPE_TABLESPACE = 2;
  103. /** Key to identify a dictionary object */
  104. struct sdi_key_t {
  105. /** Type of Object, For ex: column, index, etc */
  106. uint32 type;
  107. /** Object id which should be unique in tablespsace */
  108. uint64 id;
  109. };
  110. using sdi_container = std::vector<sdi_key_t>;
  111. struct sdi_vector_t {
  112. sdi_container m_vec;
  113. };
  114. typedef bool (*qc_engine_callback)(THD *thd, const char *table_key,
  115. uint key_length, ulonglong *engine_data);
  116. typedef bool(stat_print_fn)(THD *thd, const char *type, size_t type_len,
  117. const char *file, size_t file_len,
  118. const char *status, size_t status_len);
  119. class ha_statistics;
  120. class ha_tablespace_statistics;
  121. namespace AQP {
  122. class Join_plan;
  123. }
  124. class Unique_on_insert;
  125. extern ulong savepoint_alloc_size;
  126. /// Maps from slot to plugin. May return NULL if plugin has been unloaded.
  127. st_plugin_int *hton2plugin(uint slot);
  128. /// Returns the size of the array holding pointers to plugins.
  129. size_t num_hton2plugins();
  130. /**
  131. For unit testing.
  132. Insert plugin into arbitrary slot in array.
  133. Remove plugin from arbitrary slot in array.
  134. */
  135. st_plugin_int *insert_hton2plugin(uint slot, st_plugin_int *plugin);
  136. st_plugin_int *remove_hton2plugin(uint slot);
  137. extern const char *ha_row_type[];
  138. extern const char *tx_isolation_names[];
  139. extern const char *binlog_format_names[];
  140. extern TYPELIB tx_isolation_typelib;
  141. extern ulong total_ha_2pc;
  142. // the following is for checking tables
  143. #define HA_ADMIN_ALREADY_DONE 1
  144. #define HA_ADMIN_OK 0
  145. #define HA_ADMIN_NOT_IMPLEMENTED -1
  146. #define HA_ADMIN_FAILED -2
  147. #define HA_ADMIN_CORRUPT -3
  148. #define HA_ADMIN_INTERNAL_ERROR -4
  149. #define HA_ADMIN_INVALID -5
  150. #define HA_ADMIN_REJECT -6
  151. #define HA_ADMIN_TRY_ALTER -7
  152. #define HA_ADMIN_WRONG_CHECKSUM -8
  153. #define HA_ADMIN_NOT_BASE_TABLE -9
  154. #define HA_ADMIN_NEEDS_UPGRADE -10
  155. #define HA_ADMIN_NEEDS_ALTER -11
  156. #define HA_ADMIN_NEEDS_CHECK -12
  157. #define HA_ADMIN_STATS_UPD_ERR -13
  158. /** User needs to dump and re-create table to fix pre 5.0 decimal types */
  159. #define HA_ADMIN_NEEDS_DUMP_UPGRADE -14
  160. /**
  161. Return values for check_if_supported_inplace_alter().
  162. @see check_if_supported_inplace_alter() for description of
  163. the individual values.
  164. */
  165. enum enum_alter_inplace_result {
  166. HA_ALTER_ERROR,
  167. HA_ALTER_INPLACE_NOT_SUPPORTED,
  168. HA_ALTER_INPLACE_EXCLUSIVE_LOCK,
  169. HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE,
  170. HA_ALTER_INPLACE_SHARED_LOCK,
  171. HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE,
  172. HA_ALTER_INPLACE_NO_LOCK,
  173. HA_ALTER_INPLACE_INSTANT
  174. };
  175. /* Bits in table_flags() to show what database can do */
  176. #define HA_NO_TRANSACTIONS (1 << 0) /* Doesn't support transactions */
  177. #define HA_PARTIAL_COLUMN_READ (1 << 1) /* read may not return all columns */
  178. /*
  179. Used to avoid scanning full tables on an index. If this flag is set then
  180. the handler always has a primary key (hidden if not defined) and this
  181. index is used for scanning rather than a full table scan in all
  182. situations. No separate data/index file.
  183. */
  184. #define HA_TABLE_SCAN_ON_INDEX (1 << 2)
  185. /// Not in use.
  186. #define HA_UNUSED3 (1 << 3)
  187. /*
  188. Can the storage engine handle spatial data.
  189. Used to check that no spatial attributes are declared unless
  190. the storage engine is capable of handling it.
  191. */
  192. #define HA_CAN_GEOMETRY (1 << 4)
  193. /*
  194. Reading keys in random order is as fast as reading keys in sort order
  195. (Used in records.cc to decide if we should use a record cache and by
  196. filesort to decide if we should sort key + data or key + pointer-to-row.
  197. For further explanation see intro to init_read_record.
  198. */
  199. #define HA_FAST_KEY_READ (1 << 5)
  200. /*
  201. Set the following flag if we on delete should force all key to be read
  202. and on update read all keys that changes
  203. */
  204. #define HA_REQUIRES_KEY_COLUMNS_FOR_DELETE (1 << 6)
  205. /*
  206. Is NULL values allowed in indexes.
  207. If this is not allowed then it is not possible to use an index on a
  208. NULLable field.
  209. */
  210. #define HA_NULL_IN_KEY (1 << 7)
  211. /*
  212. Tells that we can the position for the conflicting duplicate key
  213. record is stored in table->file->dupp_ref. (insert uses rnd_pos() on
  214. this to find the duplicated row)
  215. */
  216. #define HA_DUPLICATE_POS (1 << 8)
  217. #define HA_NO_BLOBS (1 << 9) /* Doesn't support blobs */
  218. /*
  219. Is the storage engine capable of defining an index of a prefix on
  220. a BLOB attribute.
  221. */
  222. #define HA_CAN_INDEX_BLOBS (1 << 10)
  223. /*
  224. Auto increment fields can be part of a multi-part key. For second part
  225. auto-increment keys, the auto_incrementing is done in handler.cc
  226. */
  227. #define HA_AUTO_PART_KEY (1 << 11)
  228. /*
  229. Can't define a table without primary key (and cannot handle a table
  230. with hidden primary key)
  231. */
  232. #define HA_REQUIRE_PRIMARY_KEY (1 << 12)
  233. /*
  234. Does the counter of records after the info call specify an exact
  235. value or not. If it does this flag is set.
  236. */
  237. #define HA_STATS_RECORDS_IS_EXACT (1 << 13)
  238. /// Not in use.
  239. #define HA_UNUSED14 (1 << 14)
  240. /*
  241. This parameter is set when the handler will also return the primary key
  242. when doing read-only-key on another index, i.e., if we get the primary
  243. key columns for free when we do an index read (usually, it also implies
  244. that HA_PRIMARY_KEY_REQUIRED_FOR_POSITION flag is set).
  245. */
  246. #define HA_PRIMARY_KEY_IN_READ_INDEX (1 << 15)
  247. /*
  248. If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, it means that to position()
  249. uses a primary key given by the record argument.
  250. Without primary key, we can't call position().
  251. If not set, the position is returned as the current rows position
  252. regardless of what argument is given.
  253. */
  254. #define HA_PRIMARY_KEY_REQUIRED_FOR_POSITION (1 << 16)
  255. #define HA_CAN_RTREEKEYS (1 << 17)
  256. /*
  257. Seems to be an old MyISAM feature that is no longer used. No handler
  258. has it defined but it is checked in init_read_record. Further investigation
  259. needed.
  260. */
  261. #define HA_NOT_DELETE_WITH_CACHE (1 << 18)
  262. /*
  263. The following is we need to a primary key to delete (and update) a row.
  264. If there is no primary key, all columns needs to be read on update and delete
  265. */
  266. #define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE (1 << 19)
  267. /*
  268. Indexes on prefixes of character fields are not allowed.
  269. */
  270. #define HA_NO_PREFIX_CHAR_KEYS (1 << 20)
  271. /*
  272. Does the storage engine support fulltext indexes.
  273. */
  274. #define HA_CAN_FULLTEXT (1 << 21)
  275. /*
  276. Can the HANDLER interface in the MySQL API be used towards this
  277. storage engine.
  278. */
  279. #define HA_CAN_SQL_HANDLER (1 << 22)
  280. /*
  281. Set if the storage engine does not support auto increment fields.
  282. */
  283. #define HA_NO_AUTO_INCREMENT (1 << 23)
  284. /*
  285. Supports CHECKSUM option in CREATE TABLE (MyISAM feature).
  286. */
  287. #define HA_HAS_CHECKSUM (1 << 24)
  288. /*
  289. Table data are stored in separate files (for lower_case_table_names).
  290. Should file names always be in lower case (used by engines that map
  291. table names to file names.
  292. */
  293. #define HA_FILE_BASED (1 << 26)
  294. #define HA_NO_VARCHAR (1 << 27)
  295. /*
  296. Is the storage engine capable of handling bit fields.
  297. */
  298. #define HA_CAN_BIT_FIELD (1 << 28)
  299. #define HA_ANY_INDEX_MAY_BE_UNIQUE (1 << 30)
  300. #define HA_NO_COPY_ON_ALTER (1LL << 31)
  301. #define HA_COUNT_ROWS_INSTANT (1LL << 32) /* records() gives exact count*/
  302. /* Has it's own method of binlog logging */
  303. #define HA_HAS_OWN_BINLOGGING (1LL << 33)
  304. /*
  305. Engine is capable of row-format and statement-format logging,
  306. respectively
  307. */
  308. #define HA_BINLOG_ROW_CAPABLE (1LL << 34)
  309. #define HA_BINLOG_STMT_CAPABLE (1LL << 35)
  310. /*
  311. When a multiple key conflict happens in a REPLACE command mysql
  312. expects the conflicts to be reported in the ascending order of
  313. key names.
  314. For e.g.
  315. CREATE TABLE t1 (a INT, UNIQUE (a), b INT NOT NULL, UNIQUE (b), c INT NOT
  316. NULL, INDEX(c));
  317. REPLACE INTO t1 VALUES (1,1,1),(2,2,2),(2,1,3);
  318. MySQL expects the conflict with 'a' to be reported before the conflict with
  319. 'b'.
  320. If the underlying storage engine does not report the conflicting keys in
  321. ascending order, it causes unexpected errors when the REPLACE command is
  322. executed.
  323. This flag helps the underlying SE to inform the server that the keys are not
  324. ordered.
  325. */
  326. #define HA_DUPLICATE_KEY_NOT_IN_ORDER (1LL << 36)
  327. /*
  328. Engine supports REPAIR TABLE. Used by CHECK TABLE FOR UPGRADE if an
  329. incompatible table is detected. If this flag is set, CHECK TABLE FOR UPGRADE
  330. will report ER_TABLE_NEEDS_UPGRADE, otherwise ER_TABLE_NEED_REBUILD.
  331. */
  332. #define HA_CAN_REPAIR (1LL << 37)
  333. /*
  334. Set of all binlog flags. Currently only contain the capabilities
  335. flags.
  336. */
  337. #define HA_BINLOG_FLAGS (HA_BINLOG_ROW_CAPABLE | HA_BINLOG_STMT_CAPABLE)
  338. /**
  339. The handler supports read before write removal optimization
  340. Read before write removal may be used for storage engines which support
  341. write without previous read of the row to be updated. Handler returning
  342. this flag must implement start_read_removal() and end_read_removal().
  343. The handler may return "fake" rows constructed from the key of the row
  344. asked for. This is used to optimize UPDATE and DELETE by reducing the
  345. number of round-trips between handler and storage engine.
  346. Example:
  347. UPDATE a=1 WHERE pk IN (@<keys@>)
  348. @verbatim
  349. mysql_update()
  350. {
  351. if (<conditions for starting read removal>)
  352. start_read_removal()
  353. -> handler returns true if read removal supported for this table/query
  354. while(read_record("pk=<key>"))
  355. -> handler returns fake row with column "pk" set to <key>
  356. ha_update_row()
  357. -> handler sends write "a=1" for row with "pk=<key>"
  358. end_read_removal()
  359. -> handler returns the number of rows actually written
  360. }
  361. @endverbatim
  362. @note This optimization in combination with batching may be used to
  363. remove even more round-trips.
  364. */
  365. #define HA_READ_BEFORE_WRITE_REMOVAL (1LL << 38)
  366. /*
  367. Engine supports extended fulltext API
  368. */
  369. #define HA_CAN_FULLTEXT_EXT (1LL << 39)
  370. /*
  371. Storage engine doesn't synchronize result set with expected table contents.
  372. Used by replication slave to check if it is possible to retrieve rows from
  373. the table when deciding whether to do a full table scan, index scan or hash
  374. scan while applying a row event.
  375. */
  376. #define HA_READ_OUT_OF_SYNC (1LL << 40)
  377. /*
  378. Storage engine supports table export using the
  379. FLUSH TABLE <table_list> FOR EXPORT statement.
  380. */
  381. #define HA_CAN_EXPORT (1LL << 41)
  382. /*
  383. The handler don't want accesses to this table to
  384. be const-table optimized
  385. */
  386. #define HA_BLOCK_CONST_TABLE (1LL << 42)
  387. /*
  388. Handler supports FULLTEXT hints
  389. */
  390. #define HA_CAN_FULLTEXT_HINTS (1LL << 43)
  391. /**
  392. Storage engine doesn't support LOCK TABLE ... READ LOCAL locks
  393. but doesn't want to use handler::store_lock() API for upgrading
  394. them to LOCK TABLE ... READ locks, for example, because it doesn't
  395. use THR_LOCK locks at all.
  396. */
  397. #define HA_NO_READ_LOCAL_LOCK (1LL << 44)
  398. /**
  399. A storage engine is compatible with the attachable transaction requirements
  400. means that
  401. - either SE detects the fact that THD::ha_data was reset and starts a new
  402. attachable transaction, closes attachable transaction on close_connection
  403. and resumes regular (outer) transaction when THD::ha_data is restored;
  404. - or SE completely ignores THD::ha_data and close_connection like MyISAM
  405. does.
  406. */
  407. #define HA_ATTACHABLE_TRX_COMPATIBLE (1LL << 45)
  408. /**
  409. Handler supports Generated Columns
  410. */
  411. #define HA_GENERATED_COLUMNS (1LL << 46)
  412. /**
  413. Supports index on virtual generated column
  414. */
  415. #define HA_CAN_INDEX_VIRTUAL_GENERATED_COLUMN (1LL << 47)
  416. /**
  417. Supports descending indexes
  418. */
  419. #define HA_DESCENDING_INDEX (1LL << 48)
  420. /**
  421. Supports partial update of BLOB columns.
  422. */
  423. #define HA_BLOB_PARTIAL_UPDATE (1LL << 49)
  424. /**
  425. If this isn't defined, only columns/indexes with Cartesian coordinate systems
  426. (projected SRS or SRID 0) is supported. Columns/indexes without SRID
  427. restriction is also supported if this isn't defined.
  428. */
  429. #define HA_SUPPORTS_GEOGRAPHIC_GEOMETRY_COLUMN (1LL << 50)
  430. /**
  431. Handler supports expressions as DEFAULT for a column.
  432. */
  433. #define HA_SUPPORTS_DEFAULT_EXPRESSION (1LL << 51)
  434. /**
  435. Handlers with this flag set do not support UPDATE operations.
  436. */
  437. #define HA_UPDATE_NOT_SUPPORTED (1LL << 52)
  438. /**
  439. Handlers with this flag set do not support DELETE operations.
  440. */
  441. #define HA_DELETE_NOT_SUPPORTED (1LL << 53)
  442. /**
  443. The storage engine does not support using indexes for access. Indexes can only
  444. be used for estimating cost.
  445. */
  446. #define HA_NO_INDEX_ACCESS (1LL << 54)
  447. /**
  448. Supports multi-valued index
  449. */
  450. #define HA_MULTI_VALUED_KEY_SUPPORT (1LL << 55)
  451. /*
  452. Bits in index_flags(index_number) for what you can do with index.
  453. If you do not implement indexes, just return zero here.
  454. */
  455. /*
  456. Does the index support read next, this is assumed in the server
  457. code and never checked so all indexes must support this.
  458. Note that the handler can be used even if it doesn't have any index.
  459. */
  460. #define HA_READ_NEXT 1 /* TODO really use this flag */
  461. /*
  462. Can the index be used to scan backwards (supports ::index_prev).
  463. */
  464. #define HA_READ_PREV 2
  465. /*
  466. Can the index deliver its record in index order. Typically true for
  467. all ordered indexes and not true for hash indexes. Used to set keymap
  468. part_of_sortkey.
  469. This keymap is only used to find indexes usable for resolving an ORDER BY
  470. in the query. Thus in most cases index_read will work just fine without
  471. order in result production. When this flag is set it is however safe to
  472. order all output started by index_read since most engines do this. With
  473. read_multi_range calls there is a specific flag setting order or not
  474. order so in those cases ordering of index output can be avoided.
  475. */
  476. #define HA_READ_ORDER 4
  477. /*
  478. Specify whether index can handle ranges, typically true for all
  479. ordered indexes and not true for hash indexes.
  480. Used by optimiser to check if ranges (as key >= 5) can be optimised
  481. by index.
  482. */
  483. #define HA_READ_RANGE 8
  484. /*
  485. Can't use part key searches. This is typically true for hash indexes
  486. and typically not true for ordered indexes.
  487. */
  488. #define HA_ONLY_WHOLE_INDEX 16
  489. /*
  490. Does the storage engine support index-only scans on this index.
  491. Enables use of HA_EXTRA_KEYREAD and HA_EXTRA_NO_KEYREAD
  492. Used to set Key_map keys_for_keyread and to check in optimiser for
  493. index-only scans. When doing a read under HA_EXTRA_KEYREAD the handler
  494. only have to fill in the columns the key covers. If
  495. HA_PRIMARY_KEY_IN_READ_INDEX is set then also the PRIMARY KEY columns
  496. must be updated in the row.
  497. */
  498. #define HA_KEYREAD_ONLY 64
  499. /*
  500. Index scan will not return records in rowid order. Not guaranteed to be
  501. set for unordered (e.g. HASH) indexes.
  502. */
  503. #define HA_KEY_SCAN_NOT_ROR 128
  504. #define HA_DO_INDEX_COND_PUSHDOWN 256 /* Supports Index Condition Pushdown */
  505. /* operations for disable/enable indexes */
  506. #define HA_KEY_SWITCH_NONUNIQ 0
  507. #define HA_KEY_SWITCH_ALL 1
  508. #define HA_KEY_SWITCH_NONUNIQ_SAVE 2
  509. #define HA_KEY_SWITCH_ALL_SAVE 3
  510. /*
  511. Use this instead of 0 as the initial value for the slot number of
  512. handlerton, so that we can distinguish uninitialized slot number
  513. from slot 0.
  514. */
  515. #define HA_SLOT_UNDEF ((uint)-1)
  516. /*
  517. Parameters for open() (in register form->filestat)
  518. HA_GET_INFO does an implicit HA_ABORT_IF_LOCKED
  519. */
  520. #define HA_OPEN_KEYFILE 1
  521. #define HA_OPEN_RNDFILE 2
  522. #define HA_GET_INDEX 4
  523. #define HA_GET_INFO 8 /* do a handler::info() after open */
  524. #define HA_READ_ONLY 16 /* File opened as readonly */
  525. /* Try readonly if can't open with read and write */
  526. #define HA_TRY_READ_ONLY 32
  527. #define HA_WAIT_IF_LOCKED 64 /* Wait if locked on open */
  528. #define HA_ABORT_IF_LOCKED 128 /* skip if locked on open.*/
  529. #define HA_BLOCK_LOCK 256 /* unlock when reading some records */
  530. #define HA_OPEN_TEMPORARY 512
  531. /* Some key definitions */
  532. #define HA_KEY_NULL_LENGTH 1
  533. #define HA_KEY_BLOB_LENGTH 2
  534. #define HA_LEX_CREATE_TMP_TABLE 1
  535. #define HA_LEX_CREATE_IF_NOT_EXISTS 2
  536. #define HA_LEX_CREATE_TABLE_LIKE 4
  537. #define HA_LEX_CREATE_INTERNAL_TMP_TABLE 8
  538. #define HA_MAX_REC_LENGTH 65535U
  539. /**
  540. Options for the START TRANSACTION statement.
  541. Note that READ ONLY and READ WRITE are logically mutually exclusive.
  542. This is enforced by the parser and depended upon by trans_begin().
  543. We need two flags instead of one in order to differentiate between
  544. situation when no READ WRITE/ONLY clause were given and thus transaction
  545. is implicitly READ WRITE and the case when READ WRITE clause was used
  546. explicitly.
  547. */
  548. // WITH CONSISTENT SNAPSHOT option
  549. static const uint MYSQL_START_TRANS_OPT_WITH_CONS_SNAPSHOT = 1;
  550. // READ ONLY option
  551. static const uint MYSQL_START_TRANS_OPT_READ_ONLY = 2;
  552. // READ WRITE option
  553. static const uint MYSQL_START_TRANS_OPT_READ_WRITE = 4;
  554. // HIGH PRIORITY option
  555. static const uint MYSQL_START_TRANS_OPT_HIGH_PRIORITY = 8;
  556. enum legacy_db_type {
  557. DB_TYPE_UNKNOWN = 0,
  558. DB_TYPE_DIAB_ISAM = 1,
  559. DB_TYPE_HASH,
  560. DB_TYPE_MISAM,
  561. DB_TYPE_PISAM,
  562. DB_TYPE_RMS_ISAM,
  563. DB_TYPE_HEAP,
  564. DB_TYPE_ISAM,
  565. DB_TYPE_MRG_ISAM,
  566. DB_TYPE_MYISAM,
  567. DB_TYPE_MRG_MYISAM,
  568. DB_TYPE_BERKELEY_DB,
  569. DB_TYPE_INNODB,
  570. DB_TYPE_GEMINI,
  571. DB_TYPE_NDBCLUSTER,
  572. DB_TYPE_EXAMPLE_DB,
  573. DB_TYPE_ARCHIVE_DB,
  574. DB_TYPE_CSV_DB,
  575. DB_TYPE_FEDERATED_DB,
  576. DB_TYPE_BLACKHOLE_DB,
  577. DB_TYPE_PARTITION_DB, // No longer used.
  578. DB_TYPE_BINLOG,
  579. DB_TYPE_SOLID,
  580. DB_TYPE_PBXT,
  581. DB_TYPE_TABLE_FUNCTION,
  582. DB_TYPE_MEMCACHE,
  583. DB_TYPE_FALCON,
  584. DB_TYPE_MARIA,
  585. /** Performance schema engine. */
  586. DB_TYPE_PERFORMANCE_SCHEMA,
  587. DB_TYPE_TEMPTABLE,
  588. DB_TYPE_FIRST_DYNAMIC = 42,
  589. DB_TYPE_DEFAULT = 127 // Must be last
  590. };
  591. enum row_type : int {
  592. ROW_TYPE_NOT_USED = -1,
  593. ROW_TYPE_DEFAULT,
  594. ROW_TYPE_FIXED,
  595. ROW_TYPE_DYNAMIC,
  596. ROW_TYPE_COMPRESSED,
  597. ROW_TYPE_REDUNDANT,
  598. ROW_TYPE_COMPACT,
  599. /** Unused. Reserved for future versions. */
  600. ROW_TYPE_PAGED
  601. };
  602. enum enum_binlog_func {
  603. BFN_RESET_LOGS = 1,
  604. BFN_RESET_SLAVE = 2,
  605. BFN_BINLOG_WAIT = 3,
  606. BFN_BINLOG_END = 4,
  607. BFN_BINLOG_PURGE_FILE = 5
  608. };
  609. enum enum_binlog_command {
  610. LOGCOM_CREATE_TABLE,
  611. LOGCOM_ALTER_TABLE,
  612. LOGCOM_RENAME_TABLE,
  613. LOGCOM_DROP_TABLE,
  614. LOGCOM_CREATE_DB,
  615. LOGCOM_ALTER_DB,
  616. LOGCOM_DROP_DB,
  617. LOGCOM_ACL_NOTIFY
  618. };
  619. enum class enum_sampling_method { SYSTEM };
  620. /* Bits in used_fields */
  621. #define HA_CREATE_USED_AUTO (1L << 0)
  622. #define HA_CREATE_USED_RAID (1L << 1) // RAID is no longer availble
  623. #define HA_CREATE_USED_UNION (1L << 2)
  624. #define HA_CREATE_USED_INSERT_METHOD (1L << 3)
  625. #define HA_CREATE_USED_MIN_ROWS (1L << 4)
  626. #define HA_CREATE_USED_MAX_ROWS (1L << 5)
  627. #define HA_CREATE_USED_AVG_ROW_LENGTH (1L << 6)
  628. #define HA_CREATE_USED_PACK_KEYS (1L << 7)
  629. #define HA_CREATE_USED_CHARSET (1L << 8)
  630. #define HA_CREATE_USED_DEFAULT_CHARSET (1L << 9)
  631. #define HA_CREATE_USED_DATADIR (1L << 10)
  632. #define HA_CREATE_USED_INDEXDIR (1L << 11)
  633. #define HA_CREATE_USED_ENGINE (1L << 12)
  634. #define HA_CREATE_USED_CHECKSUM (1L << 13)
  635. #define HA_CREATE_USED_DELAY_KEY_WRITE (1L << 14)
  636. #define HA_CREATE_USED_ROW_FORMAT (1L << 15)
  637. #define HA_CREATE_USED_COMMENT (1L << 16)
  638. #define HA_CREATE_USED_PASSWORD (1L << 17)
  639. #define HA_CREATE_USED_CONNECTION (1L << 18)
  640. #define HA_CREATE_USED_KEY_BLOCK_SIZE (1L << 19)
  641. /** Unused. Reserved for future versions. */
  642. #define HA_CREATE_USED_TRANSACTIONAL (1L << 20)
  643. /** Unused. Reserved for future versions. */
  644. #define HA_CREATE_USED_PAGE_CHECKSUM (1L << 21)
  645. /** This is set whenever STATS_PERSISTENT=0|1|default has been
  646. specified in CREATE/ALTER TABLE. See also HA_OPTION_STATS_PERSISTENT in
  647. include/my_base.h. It is possible to distinguish whether
  648. STATS_PERSISTENT=default has been specified or no STATS_PERSISTENT= is
  649. given at all. */
  650. #define HA_CREATE_USED_STATS_PERSISTENT (1L << 22)
  651. /**
  652. This is set whenever STATS_AUTO_RECALC=0|1|default has been
  653. specified in CREATE/ALTER TABLE. See enum_stats_auto_recalc.
  654. It is possible to distinguish whether STATS_AUTO_RECALC=default
  655. has been specified or no STATS_AUTO_RECALC= is given at all.
  656. */
  657. #define HA_CREATE_USED_STATS_AUTO_RECALC (1L << 23)
  658. /**
  659. This is set whenever STATS_SAMPLE_PAGES=N|default has been
  660. specified in CREATE/ALTER TABLE. It is possible to distinguish whether
  661. STATS_SAMPLE_PAGES=default has been specified or no STATS_SAMPLE_PAGES= is
  662. given at all.
  663. */
  664. #define HA_CREATE_USED_STATS_SAMPLE_PAGES (1L << 24)
  665. /**
  666. This is set whenever a 'TABLESPACE=...' phrase is used on CREATE TABLE
  667. */
  668. #define HA_CREATE_USED_TABLESPACE (1L << 25)
  669. /** COMPRESSION="zlib|lz4|none" used during table create. */
  670. #define HA_CREATE_USED_COMPRESS (1L << 26)
  671. /** ENCRYPTION="Y" used during table create. */
  672. #define HA_CREATE_USED_ENCRYPT (1L << 27)
  673. /**
  674. CREATE|ALTER SCHEMA|DATABASE|TABLE has an explicit COLLATE clause.
  675. Implies HA_CREATE_USED_DEFAULT_CHARSET.
  676. */
  677. #define HA_CREATE_USED_DEFAULT_COLLATE (1L << 28)
  678. /** SECONDARY_ENGINE used during table create. */
  679. #define HA_CREATE_USED_SECONDARY_ENGINE (1L << 29)
  680. /**
  681. CREATE|ALTER SCHEMA|DATABASE has an explicit ENCRYPTION clause.
  682. Implies HA_CREATE_USED_DEFAULT_ENCRYPTION.
  683. */
  684. #define HA_CREATE_USED_DEFAULT_ENCRYPTION (1L << 30)
  685. /*
  686. End of bits used in used_fields
  687. */
  688. /*
  689. Structure to hold list of database_name.table_name.
  690. This is used at both mysqld and storage engine layer.
  691. */
  692. struct st_handler_tablename {
  693. const char *db;
  694. const char *tablename;
  695. };
  696. #define MAXGTRIDSIZE 64
  697. #define MAXBQUALSIZE 64
  698. #define COMPATIBLE_DATA_YES 0
  699. #define COMPATIBLE_DATA_NO 1
  700. /*
  701. These structures are used to pass information from a set of SQL commands
  702. on add/drop/change tablespace definitions to the proper hton.
  703. */
  704. #define UNDEF_NODEGROUP 65535
  705. // FUTURE: Combine these two enums into one enum class
  706. enum ts_command_type {
  707. TS_CMD_NOT_DEFINED = -1,
  708. CREATE_TABLESPACE = 0,
  709. ALTER_TABLESPACE = 1,
  710. CREATE_LOGFILE_GROUP = 2,
  711. ALTER_LOGFILE_GROUP = 3,
  712. DROP_TABLESPACE = 4,
  713. DROP_LOGFILE_GROUP = 5,
  714. CHANGE_FILE_TABLESPACE = 6,
  715. ALTER_ACCESS_MODE_TABLESPACE = 7,
  716. CREATE_UNDO_TABLESPACE = 8,
  717. ALTER_UNDO_TABLESPACE = 9,
  718. DROP_UNDO_TABLESPACE = 10
  719. };
  720. enum ts_alter_tablespace_type {
  721. TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED = -1,
  722. ALTER_TABLESPACE_ADD_FILE = 1,
  723. ALTER_TABLESPACE_DROP_FILE = 2,
  724. ALTER_TABLESPACE_RENAME = 3,
  725. ALTER_TABLESPACE_OPTIONS = 4,
  726. ALTER_UNDO_TABLESPACE_SET_ACTIVE = 5,
  727. ALTER_UNDO_TABLESPACE_SET_INACTIVE = 6
  728. };
  729. /**
  730. Legacy struct for passing tablespace information to SEs.
  731. FUTURE: Pass all info through dd objects
  732. */
  733. class st_alter_tablespace {
  734. public:
  735. const char *tablespace_name = nullptr;
  736. const char *logfile_group_name = nullptr;
  737. ts_command_type ts_cmd_type = TS_CMD_NOT_DEFINED;
  738. enum ts_alter_tablespace_type ts_alter_tablespace_type =
  739. TS_ALTER_TABLESPACE_TYPE_NOT_DEFINED;
  740. const char *data_file_name = nullptr;
  741. const char *undo_file_name = nullptr;
  742. ulonglong extent_size = 1024 * 1024; // Default 1 MByte
  743. ulonglong undo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
  744. ulonglong redo_buffer_size = 8 * 1024 * 1024; // Default 8 MByte
  745. ulonglong initial_size = 128 * 1024 * 1024; // Default 128 MByte
  746. ulonglong autoextend_size = 0; // No autoextension as default
  747. ulonglong max_size = 0; // Max size == initial size => no extension
  748. ulonglong file_block_size = 0; // 0=default or must be a valid Page Size
  749. uint nodegroup_id = UNDEF_NODEGROUP;
  750. bool wait_until_completed = true;
  751. const char *ts_comment = nullptr;
  752. bool is_tablespace_command() {
  753. return ts_cmd_type == CREATE_TABLESPACE ||
  754. ts_cmd_type == ALTER_TABLESPACE || ts_cmd_type == DROP_TABLESPACE ||
  755. ts_cmd_type == CHANGE_FILE_TABLESPACE ||
  756. ts_cmd_type == ALTER_ACCESS_MODE_TABLESPACE;
  757. }
  758. /**
  759. Proper constructor even for all-public class simplifies initialization and
  760. allows members to be const.
  761. FUTURE: With constructor all members can be made const, and do not need
  762. default initializers.
  763. @param tablespace name of tabelspace (nullptr for logfile group statements)
  764. @param logfile_group name of logfile group or nullptr
  765. @param cmd main statement type
  766. @param alter_tablespace_cmd subcommand type for ALTER TABLESPACE
  767. @param datafile tablespace file for CREATE and ALTER ... ADD ...
  768. @param undofile only applies to logfile group statements. nullptr otherwise.
  769. @param opts options provided by parser
  770. */
  771. st_alter_tablespace(const char *tablespace, const char *logfile_group,
  772. ts_command_type cmd,
  773. enum ts_alter_tablespace_type alter_tablespace_cmd,
  774. const char *datafile, const char *undofile,
  775. const Tablespace_options &opts);
  776. };
  777. /*
  778. Make sure that the order of schema_tables and enum_schema_tables are the same.
  779. */
  780. enum enum_schema_tables : int {
  781. SCH_FIRST = 0,
  782. SCH_COLUMN_PRIVILEGES = SCH_FIRST,
  783. SCH_ENGINES,
  784. SCH_OPEN_TABLES,
  785. SCH_OPTIMIZER_TRACE,
  786. SCH_PLUGINS,
  787. SCH_PROCESSLIST,
  788. SCH_PROFILES,
  789. SCH_SCHEMA_PRIVILEGES,
  790. SCH_TABLESPACES,
  791. SCH_TABLE_PRIVILEGES,
  792. SCH_USER_PRIVILEGES,
  793. SCH_TMP_TABLE_COLUMNS,
  794. SCH_TMP_TABLE_KEYS,
  795. SCH_LAST = SCH_TMP_TABLE_KEYS
  796. };
  797. enum ha_stat_type { HA_ENGINE_STATUS, HA_ENGINE_LOGS, HA_ENGINE_MUTEX };
  798. enum ha_notification_type : int { HA_NOTIFY_PRE_EVENT, HA_NOTIFY_POST_EVENT };
  799. /** Clone start operation mode */
  800. enum Ha_clone_mode {
  801. /** Start a new clone operation */
  802. HA_CLONE_MODE_START,
  803. /** Re-start a clone operation after failure */
  804. HA_CLONE_MODE_RESTART,
  805. /** Add a new task to a running clone operation */
  806. HA_CLONE_MODE_ADD_TASK,
  807. /** Get version for transfer data format */
  808. HA_CLONE_MODE_VERSION,
  809. /** Max value for clone mode */
  810. HA_CLONE_MODE_MAX
  811. };
  812. /** Clone operation types. */
  813. enum Ha_clone_type : size_t {
  814. /** Caller must block all write operation to the SE. */
  815. HA_CLONE_BLOCKING,
  816. /** For transactional SE, archive redo to support concurrent dml */
  817. HA_CLONE_REDO,
  818. /** For transactional SE, track page changes to support concurrent dml */
  819. HA_CLONE_PAGE,
  820. /** For transactional SE, use both page tracking and redo to optimize
  821. clone with concurrent dml. Currently supported by Innodb. */
  822. HA_CLONE_HYBRID,
  823. /** SE supports multiple threads for clone */
  824. HA_CLONE_MULTI_TASK,
  825. /** SE supports restarting clone after network failure */
  826. HA_CLONE_RESTART,
  827. /** Maximum value of clone type */
  828. HA_CLONE_TYPE_MAX
  829. };
  830. using Ha_clone_flagset = std::bitset<HA_CLONE_TYPE_MAX>;
  831. /** File reference for clone */
  832. struct Ha_clone_file {
  833. /** File reference type */
  834. enum {
  835. /** File handle */
  836. FILE_HANDLE,
  837. /** File descriptor */
  838. FILE_DESC
  839. } type;
  840. /** File reference */
  841. union {
  842. /** File descriptor */
  843. int file_desc;
  844. /** File handle for windows */
  845. void *file_handle;
  846. };
  847. };
  848. /* Abstract callback interface to stream data back to the caller. */
  849. class Ha_clone_cbk {
  850. protected:
  851. /** Constructor to initialize members. */
  852. Ha_clone_cbk()
  853. : m_hton(),
  854. m_loc_idx(),
  855. m_client_buff_size(),
  856. m_data_desc(),
  857. m_desc_len(),
  858. m_src_name(),
  859. m_dest_name(),
  860. m_state_estimate(),
  861. m_flag() {}
  862. public:
  863. /** Callback providing data from current position of a
  864. file descriptor of specific length.
  865. @param[in] from_file source file to read from
  866. @param[in] len data length
  867. @return error code */
  868. virtual int file_cbk(Ha_clone_file from_file, uint len) = 0;
  869. /** Callback providing data in buffer of specific length.
  870. @param[in] from_buffer source buffer to read from
  871. @param[in] len data length
  872. @return error code */
  873. virtual int buffer_cbk(uchar *from_buffer, uint len) = 0;
  874. /** Callback providing a file descriptor to write data starting
  875. from current position.
  876. @param[in] to_file destination file to write data
  877. @return error code */
  878. virtual int apply_file_cbk(Ha_clone_file to_file) = 0;
  879. /** Callback to get data in buffer.
  880. @param[out] to_buffer data buffer
  881. @param[out] len data length
  882. @return error code */
  883. virtual int apply_buffer_cbk(uchar *&to_buffer, uint &len) = 0;
  884. /** virtual destructor. */
  885. virtual ~Ha_clone_cbk() {}
  886. /** Set current storage engine handlerton.
  887. @param[in] hton SE handlerton */
  888. void set_hton(handlerton *hton) { m_hton = hton; }
  889. /** Get current storage engine handlerton.
  890. @return SE handlerton */
  891. handlerton *get_hton() { return (m_hton); }
  892. /** Set caller's transfer buffer size. SE can adjust the data chunk size
  893. based on this parameter.
  894. @param[in] size buffer size in bytes */
  895. void set_client_buffer_size(uint size) { m_client_buff_size = size; }
  896. /** Get caller's transfer buffer size.
  897. @return buffer size in bytes */
  898. uint get_client_buffer_size() { return (m_client_buff_size); }
  899. /** Set current SE index.
  900. @param[in] idx SE index in locator array */
  901. void set_loc_index(uint idx) { m_loc_idx = idx; }
  902. /** Get current SE index.
  903. @return SE index in locator array */
  904. uint get_loc_index() { return (m_loc_idx); }
  905. /** Set data descriptor. SE specific descriptor for the
  906. data transferred by the callbacks.
  907. @param[in] desc serialized data descriptor
  908. @param[in] len length of the descriptor byte stream */
  909. void set_data_desc(const uchar *desc, uint len) {
  910. m_data_desc = desc;
  911. m_desc_len = len;
  912. }
  913. /** Get data descriptor. SE specific descriptor for the
  914. data transferred by the callbacks.
  915. @param[out] lenp length of the descriptor byte stream
  916. @return pointer to the serialized data descriptor */
  917. const uchar *get_data_desc(uint *lenp) {
  918. if (lenp != nullptr) {
  919. *lenp = m_desc_len;
  920. }
  921. return (m_data_desc);
  922. }
  923. /** Get SE source file name. Used for debug printing and error message.
  924. @return null terminated string for source file name */
  925. const char *get_source_name() { return (m_src_name); }
  926. /** Set SE source file name.
  927. @param[in] name null terminated string for source file name */
  928. void set_source_name(const char *name) { m_src_name = name; }
  929. /** Get SE destination file name. Used for debug printing and error message.
  930. @return null terminated string for destination file name */
  931. const char *get_dest_name() { return (m_dest_name); }
  932. /** Set SE destination file name.
  933. @param[in] name null terminated string for destination file name */
  934. void set_dest_name(const char *name) { m_dest_name = name; }
  935. /** Clear all flags set by SE */
  936. void clear_flags() { m_flag = 0; }
  937. /** Mark that ACK is needed for the data transfer before returning
  938. from callback. Set by SE. */
  939. void set_ack() { m_flag |= HA_CLONE_ACK; }
  940. /** Check if ACK is needed for the data transfer
  941. @return true if ACK is needed */
  942. bool is_ack_needed() const { return (m_flag & HA_CLONE_ACK); }
  943. /** Mark that the file descriptor is opened for read/write
  944. with OS buffer cache. For O_DIRECT, the flag is not set. */
  945. void set_os_buffer_cache() { m_flag |= HA_CLONE_FILE_CACHE; }
  946. /** Check if the file descriptor is opened for read/write with OS
  947. buffer cache. Currently clone avoids using zero copy (sendfile on linux),
  948. if SE is using O_DIRECT. This improves data copy performance.
  949. @return true if O_DIRECT is not used */
  950. bool is_os_buffer_cache() const { return (m_flag & HA_CLONE_FILE_CACHE); }
  951. /** Mark that the file can be transferred with zero copy. */
  952. void set_zero_copy() { m_flag |= HA_CLONE_ZERO_COPY; }
  953. /** Check if zero copy optimization is suggested. */
  954. bool is_zero_copy() const { return (m_flag & HA_CLONE_ZERO_COPY); }
  955. /** Mark that data needs secure transfer. */
  956. void set_secure() { m_flag |= HA_CLONE_SECURE; }
  957. /** Check if data needs secure transfer. */
  958. bool is_secure() const { return (m_flag & HA_CLONE_SECURE); }
  959. /** Set state information and notify state change.
  960. @param[in] estimate estimated bytes for current state. */
  961. void mark_state_change(uint64_t estimate) {
  962. m_flag |= HA_CLONE_STATE_CHANGE;
  963. m_state_estimate = estimate;
  964. }
  965. /** Check if SE notified state change. */
  966. bool is_state_change(uint64_t &estimate) {
  967. estimate = m_state_estimate;
  968. return (m_flag & HA_CLONE_STATE_CHANGE);
  969. }
  970. private:
  971. /** Handlerton for the SE */
  972. handlerton *m_hton;
  973. /** SE index in caller's locator array */
  974. uint m_loc_idx;
  975. /** Caller's transfer buffer size. */
  976. uint m_client_buff_size;
  977. /** SE's Serialized data descriptor */
  978. const uchar *m_data_desc;
  979. /** SE's Serialized descriptor length. */
  980. uint m_desc_len;
  981. /** Current source file name */
  982. const char *m_src_name;
  983. /** Current destination file name */
  984. const char *m_dest_name;
  985. /** Estimated bytes to be transferred. */
  986. uint64_t m_state_estimate;
  987. /** Flag storing data related options */
  988. int m_flag;
  989. /** Acknowledgement is needed for the data transfer. */
  990. const int HA_CLONE_ACK = 0x01;
  991. /** Data file is opened for read/write with OS buffer cache. */
  992. const int HA_CLONE_FILE_CACHE = 0x02;
  993. /** Data file can be transferred with zero copy. */
  994. const int HA_CLONE_ZERO_COPY = 0x04;
  995. /** Data needs to be transferred securely over SSL connection. */
  996. const int HA_CLONE_SECURE = 0x08;
  997. /** State change notification by SE. */
  998. const int HA_CLONE_STATE_CHANGE = 0x10;
  999. };
  1000. /**
  1001. Column type description for foreign key columns compatibility check.
  1002. Contains subset of information from dd::Column class. It is inconvenient
  1003. to use dd::Column class directly for such checks because it requires valid
  1004. dd::Table object and in some cases we want to produce Ha_fk_column_type
  1005. right from column description in Create_field format.
  1006. */
  1007. struct Ha_fk_column_type {
  1008. dd::enum_column_types type;
  1009. /*
  1010. Note that both dd::Column::char_length() and length here are really
  1011. in bytes.
  1012. */
  1013. size_t char_length;
  1014. const CHARSET_INFO *field_charset;
  1015. size_t elements_count;
  1016. uint numeric_scale;
  1017. bool is_unsigned;
  1018. };
  1019. /* handlerton methods */
  1020. /**
  1021. close_connection is only called if
  1022. thd->ha_data[xxx_hton.slot] is non-zero, so even if you don't need
  1023. this storage area - set it to something, so that MySQL would know
  1024. this storage engine was accessed in this connection
  1025. */
  1026. typedef int (*close_connection_t)(handlerton *hton, THD *thd);
  1027. /** Terminate connection/statement notification. */
  1028. typedef void (*kill_connection_t)(handlerton *hton, THD *thd);
  1029. /**
  1030. Shut down all storage engine background tasks that might access
  1031. the data dictionary, before the main shutdown.
  1032. */
  1033. typedef void (*pre_dd_shutdown_t)(handlerton *hton);
  1034. /**
  1035. sv points to a storage area, that was earlier passed
  1036. to the savepoint_set call
  1037. */
  1038. typedef int (*savepoint_rollback_t)(handlerton *hton, THD *thd, void *sv);
  1039. /**
  1040. sv points to an uninitialized storage area of requested size
  1041. (see savepoint_offset description)
  1042. */
  1043. typedef int (*savepoint_set_t)(handlerton *hton, THD *thd, void *sv);
  1044. /**
  1045. Check if storage engine allows to release metadata locks which were
  1046. acquired after the savepoint if rollback to savepoint is done.
  1047. @return true - If it is safe to release MDL locks.
  1048. false - If it is not.
  1049. */
  1050. typedef bool (*savepoint_rollback_can_release_mdl_t)(handlerton *hton,
  1051. THD *thd);
  1052. typedef int (*savepoint_release_t)(handlerton *hton, THD *thd, void *sv);
  1053. /**
  1054. 'all' is true if it's a real commit, that makes persistent changes
  1055. 'all' is false if it's not in fact a commit but an end of the
  1056. statement that is part of the transaction.
  1057. NOTE 'all' is also false in auto-commit mode where 'end of statement'
  1058. and 'real commit' mean the same event.
  1059. */
  1060. typedef int (*commit_t)(handlerton *hton, THD *thd, bool all);
  1061. typedef int (*rollback_t)(handlerton *hton, THD *thd, bool all);
  1062. typedef int (*prepare_t)(handlerton *hton, THD *thd, bool all);
  1063. typedef int (*recover_t)(handlerton *hton, XA_recover_txn *xid_list, uint len,
  1064. MEM_ROOT *mem_root);
  1065. /** X/Open XA distributed transaction status codes */
  1066. enum xa_status_code {
  1067. /**
  1068. normal execution
  1069. */
  1070. XA_OK = 0,
  1071. /**
  1072. asynchronous operation already outstanding
  1073. */
  1074. XAER_ASYNC = -2,
  1075. /**
  1076. a resource manager error occurred in the transaction branch
  1077. */
  1078. XAER_RMERR = -3,
  1079. /**
  1080. the XID is not valid
  1081. */
  1082. XAER_NOTA = -4,
  1083. /**
  1084. invalid arguments were given
  1085. */
  1086. XAER_INVAL = -5,
  1087. /**
  1088. routine invoked in an improper context
  1089. */
  1090. XAER_PROTO = -6,
  1091. /**
  1092. resource manager unavailable
  1093. */
  1094. XAER_RMFAIL = -7,
  1095. /**
  1096. the XID already exists
  1097. */
  1098. XAER_DUPID = -8,
  1099. /**
  1100. resource manager doing work outside transaction
  1101. */
  1102. XAER_OUTSIDE = -9
  1103. };
  1104. typedef xa_status_code (*commit_by_xid_t)(handlerton *hton, XID *xid);
  1105. typedef xa_status_code (*rollback_by_xid_t)(handlerton *hton, XID *xid);
  1106. /**
  1107. Create handler object for the table in the storage engine.
  1108. @param hton Handlerton object for the storage engine.
  1109. @param table TABLE_SHARE for the table, can be NULL if caller
  1110. didn't perform full-blown open of table definition.
  1111. @param partitioned Indicates whether table is partitioned.
  1112. @param mem_root Memory root to be used for allocating handler
  1113. object.
  1114. */
  1115. typedef handler *(*create_t)(handlerton *hton, TABLE_SHARE *table,
  1116. bool partitioned, MEM_ROOT *mem_root);
  1117. typedef void (*drop_database_t)(handlerton *hton, char *path);
  1118. typedef int (*panic_t)(handlerton *hton, enum ha_panic_function flag);
  1119. typedef int (*start_consistent_snapshot_t)(handlerton *hton, THD *thd);
  1120. /**
  1121. Flush the log(s) of storage engine(s).
  1122. @param hton Handlerton of storage engine.
  1123. @param binlog_group_flush true if we got invoked by binlog group
  1124. commit during flush stage, false in other cases.
  1125. @retval false Succeed
  1126. @retval true Error
  1127. */
  1128. typedef bool (*flush_logs_t)(handlerton *hton, bool binlog_group_flush);
  1129. typedef bool (*show_status_t)(handlerton *hton, THD *thd, stat_print_fn *print,
  1130. enum ha_stat_type stat);
  1131. /**
  1132. The flag values are defined in sql_partition.h.
  1133. If this function is set, then it implies that the handler supports
  1134. partitioned tables.
  1135. If this function exists, then handler::get_partition_handler must also be
  1136. implemented.
  1137. */
  1138. typedef uint (*partition_flags_t)();
  1139. /**
  1140. SE specific validation of the tablespace name.
  1141. This function will ask the relevant SE whether the submitted tablespace
  1142. name is valid.
  1143. @param ts_cmd Purpose of usage - is this tablespace DDL?
  1144. @param tablespace_name Name of the tablespace.
  1145. @return Tablespace name validity.
  1146. @retval == false: The tablespace name is invalid.
  1147. @retval == true: The tablespace name is valid.
  1148. */
  1149. typedef bool (*is_valid_tablespace_name_t)(ts_command_type ts_cmd,
  1150. const char *tablespace_name);
  1151. /**
  1152. Get the tablespace name from the SE for the given schema and table.
  1153. @param thd Thread context.
  1154. @param db_name Name of the relevant schema.
  1155. @param table_name Name of the relevant table.
  1156. @param [out] tablespace_name Name of the tablespace containing the table.
  1157. @return Operation status.
  1158. @retval == 0 Success.
  1159. @retval != 0 Error (handler error code returned).
  1160. */
  1161. typedef int (*get_tablespace_t)(THD *thd, LEX_CSTRING db_name,
  1162. LEX_CSTRING table_name,
  1163. LEX_CSTRING *tablespace_name);
  1164. /**
  1165. Create/drop or alter tablespace in the storage engine.
  1166. @param hton Hadlerton of the SE.
  1167. @param thd Thread context.
  1168. @param ts_info Description of tablespace and specific
  1169. operation on it.
  1170. @param old_ts_def dd::Tablespace object describing old version
  1171. of tablespace.
  1172. @param [in,out] new_ts_def dd::Tablespace object describing new version
  1173. of tablespace. Engines which support atomic DDL
  1174. can adjust this object. The updated information
  1175. will be saved to the data-dictionary.
  1176. @return Operation status.
  1177. @retval == 0 Success.
  1178. @retval != 0 Error (handler error code returned).
  1179. */
  1180. typedef int (*alter_tablespace_t)(handlerton *hton, THD *thd,
  1181. st_alter_tablespace *ts_info,
  1182. const dd::Tablespace *old_ts_def,
  1183. dd::Tablespace *new_ts_def);
  1184. /**
  1185. SE interface for getting tablespace extension.
  1186. @return Extension of tablespace datafile name.
  1187. */
  1188. typedef const char *(*get_tablespace_filename_ext_t)();
  1189. /**
  1190. Get the tablespace data from SE and insert it into Data dictionary
  1191. @param thd Thread context
  1192. @return Operation status.
  1193. @retval == 0 Success.
  1194. @retval != 0 Error (handler error code returned)
  1195. */
  1196. typedef int (*upgrade_tablespace_t)(THD *thd);
  1197. /**
  1198. Get the tablespace data from SE and insert it into Data dictionary
  1199. @param[in] tablespace tablespace object
  1200. @return Operation status.
  1201. @retval == 0 Success.
  1202. @retval != 0 Error (handler error code returned)
  1203. */
  1204. typedef bool (*upgrade_space_version_t)(dd::Tablespace *tablespace);
  1205. /**
  1206. Finish upgrade process inside storage engines.
  1207. This includes resetting flags to indicate upgrade process
  1208. and cleanup after upgrade.
  1209. @param thd Thread context
  1210. @return Operation status.
  1211. @retval == 0 Success.
  1212. @retval != 0 Error (handler error code returned)
  1213. */
  1214. typedef int (*finish_upgrade_t)(THD *thd, bool failed_upgrade);
  1215. /**
  1216. Upgrade logs after the checkpoint from where upgrade
  1217. process can only roll forward.
  1218. @param thd Thread context
  1219. @return Operation status.
  1220. @retval == 0 Success.
  1221. @retval != 0 Error (handler error code returned)
  1222. */
  1223. typedef int (*upgrade_logs_t)(THD *thd);
  1224. enum class Tablespace_type {
  1225. SPACE_TYPE_DICTIONARY,
  1226. SPACE_TYPE_SYSTEM,
  1227. SPACE_TYPE_UNDO,
  1228. SPACE_TYPE_TEMPORARY,
  1229. SPACE_TYPE_SHARED,
  1230. SPACE_TYPE_IMPLICIT
  1231. };
  1232. /**
  1233. Get the tablespace type from the SE.
  1234. @param[in] space tablespace object
  1235. @param[out] space_type type of space
  1236. @return Operation status.
  1237. @retval false on success and true for failure.
  1238. */
  1239. typedef bool (*get_tablespace_type_t)(const dd::Tablespace &space,
  1240. Tablespace_type *space_type);
  1241. /**
  1242. Get the tablespace type given the name, from the SE.
  1243. @param[in] tablespace_name tablespace name
  1244. @param[out] space_type type of space
  1245. @return Operation status.
  1246. @retval false on success and true for failure.
  1247. */
  1248. typedef bool (*get_tablespace_type_by_name_t)(const char *tablespace_name,
  1249. Tablespace_type *space_type);
  1250. typedef int (*fill_is_table_t)(handlerton *hton, THD *thd, TABLE_LIST *tables,
  1251. class Item *cond, enum enum_schema_tables);
  1252. typedef int (*binlog_func_t)(handlerton *hton, THD *thd, enum_binlog_func fn,
  1253. void *arg);
  1254. typedef void (*binlog_log_query_t)(handlerton *hton, THD *thd,
  1255. enum_binlog_command binlog_command,
  1256. const char *query, uint query_length,
  1257. const char *db, const char *table_name);
  1258. typedef int (*discover_t)(handlerton *hton, THD *thd, const char *db,
  1259. const char *name, uchar **frmblob, size_t *frmlen);
  1260. typedef int (*find_files_t)(handlerton *hton, THD *thd, const char *db,
  1261. const char *path, const char *wild, bool dir,
  1262. List<LEX_STRING> *files);
  1263. typedef int (*table_exists_in_engine_t)(handlerton *hton, THD *thd,
  1264. const char *db, const char *name);
  1265. typedef int (*make_pushed_join_t)(handlerton *hton, THD *thd,
  1266. const AQP::Join_plan *plan);
  1267. /**
  1268. Check if the given db.tablename is a system table for this SE.
  1269. @param db Database name to check.
  1270. @param table_name table name to check.
  1271. @param is_sql_layer_system_table if the supplied db.table_name is a SQL
  1272. layer system table.
  1273. @see example_is_supported_system_table in ha_example.cc
  1274. is_sql_layer_system_table is supplied to make more efficient
  1275. checks possible for SEs that support all SQL layer tables.
  1276. This interface is optional, so every SE need not implement it.
  1277. */
  1278. typedef bool (*is_supported_system_table_t)(const char *db,
  1279. const char *table_name,
  1280. bool is_sql_layer_system_table);
  1281. /**
  1282. Create SDI in a tablespace. This API should be used when upgrading
  1283. a tablespace with no SDI or after invoking sdi_drop().
  1284. @param[in] tablespace tablespace object
  1285. @retval false success
  1286. @retval true failure
  1287. */
  1288. typedef bool (*sdi_create_t)(dd::Tablespace *tablespace);
  1289. /**
  1290. Drop SDI in a tablespace. This API should be used only when
  1291. SDI is corrupted.
  1292. @param[in] tablespace tablespace object
  1293. @retval false success
  1294. @retval true failure
  1295. */
  1296. typedef bool (*sdi_drop_t)(dd::Tablespace *tablespace);
  1297. /**
  1298. Get the SDI keys in a tablespace into vector.
  1299. @param[in] tablespace tablespace object
  1300. @param[in,out] vector vector of SDI Keys
  1301. @retval false success
  1302. @retval true failure
  1303. */
  1304. typedef bool (*sdi_get_keys_t)(const dd::Tablespace &tablespace,
  1305. sdi_vector_t &vector);
  1306. /**
  1307. Retrieve SDI for a given SDI key.
  1308. Since the caller of this api will not know the SDI length, SDI retrieval
  1309. should be done in the following way.
  1310. i. Allocate initial memory of some size (Lets say 64KB)
  1311. ii. Pass the allocated memory to the below api.
  1312. iii. If passed buffer is sufficient, sdi_get_by_id() copies the sdi
  1313. to the buffer passed and returns success, else sdi_len is modified
  1314. with the actual length of the SDI (and returns false on failure).
  1315. For genuine errors, sdi_len is returned as UINT64_MAX
  1316. iv. If sdi_len != UINT64_MAX, retry the call after allocating the memory
  1317. of sdi_len
  1318. v. Free the memory after using SDI (responsibility of caller)
  1319. @param[in] tablespace tablespace object
  1320. @param[in] sdi_key SDI key to uniquely identify SDI obj
  1321. @param[in,out] sdi SDI retrieved from tablespace
  1322. A non-null pointer must be passed in
  1323. @param[in,out] sdi_len in: length of the memory allocated
  1324. out: actual length of SDI
  1325. @retval false success
  1326. @retval true failure
  1327. */
  1328. typedef bool (*sdi_get_t)(const dd::Tablespace &tablespace,
  1329. const sdi_key_t *sdi_key, void *sdi, uint64 *sdi_len);
  1330. /**
  1331. Insert/Update SDI for a given SDI key.
  1332. @param[in] hton handlerton object
  1333. @param[in] tablespace tablespace object
  1334. @param[in] sdi_key SDI key to uniquely identify SDI obj
  1335. @param[in] sdi SDI to write into the tablespace
  1336. @param[in] sdi_len length of SDI BLOB returned
  1337. @retval false success
  1338. @retval true failure, my_error() should be called
  1339. by SE
  1340. */
  1341. typedef bool (*sdi_set_t)(handlerton *hton, const dd::Tablespace &tablespace,
  1342. const dd::Table *table, const sdi_key_t *sdi_key,
  1343. const void *sdi, uint64 sdi_len);
  1344. /**
  1345. Delete SDI for a given SDI key.
  1346. @param[in] tablespace tablespace object
  1347. @param[in] sdi_key SDI key to uniquely identify SDI obj
  1348. @retval false success
  1349. @retval true failure, my_error() should be called
  1350. by SE
  1351. */
  1352. typedef bool (*sdi_delete_t)(const dd::Tablespace &tablespace,
  1353. const dd::Table *table, const sdi_key_t *sdi_key);
  1354. /**
  1355. Check if the DDSE is started in a way that leaves thd DD being read only.
  1356. @retval true The data dictionary can only be read.
  1357. @retval false The data dictionary can be read and written.
  1358. */
  1359. typedef bool (*is_dict_readonly_t)();
  1360. /**
  1361. Drop all temporary tables which have been left from previous server
  1362. run belonging to this SE. Used on server start-up.
  1363. @param[in] hton Handlerton for storage engine.
  1364. @param[in] thd Thread context.
  1365. @param[in,out] files List of files in directories for temporary files
  1366. which match tmp_file_prefix and thus can belong to
  1367. temporary tables (but not necessarily in this SE).
  1368. It is recommended to remove file from the list if
  1369. SE recognizes it as belonging to temporary table
  1370. in this SE and deletes it.
  1371. */
  1372. typedef bool (*rm_tmp_tables_t)(handlerton *hton, THD *thd,
  1373. List<LEX_STRING> *files);
  1374. /**
  1375. Retrieve cost constants to be used for this storage engine.
  1376. A storage engine that wants to provide its own cost constants to
  1377. be used in the optimizer cost model, should implement this function.
  1378. The server will call this function to get a cost constant object
  1379. that will be used for tables stored in this storage engine instead
  1380. of using the default cost constants.
  1381. Life cycle for the cost constant object: The storage engine must
  1382. allocate the cost constant object on the heap. After the function
  1383. returns, the server takes over the ownership of this object.
  1384. The server will eventually delete the object by calling delete.
  1385. @note In the initial version the storage_category parameter will
  1386. not be used. The only valid value this will have is DEFAULT_STORAGE_CLASS
  1387. (see declaration in opt_costconstants.h).
  1388. @param storage_category the storage type that the cost constants will
  1389. be used for
  1390. @return a pointer to the cost constant object, if NULL is returned
  1391. the default cost constants will be used
  1392. */
  1393. typedef SE_cost_constants *(*get_cost_constants_t)(uint storage_category);
  1394. /**
  1395. @param[in,out] thd pointer to THD
  1396. @param[in] new_trx_arg pointer to replacement transaction
  1397. @param[out] ptr_trx_arg double pointer to being replaced transaction
  1398. Associated with THD engine's native transaction is replaced
  1399. with @c new_trx_arg. The old value is returned through a buffer if non-null
  1400. pointer is provided with @c ptr_trx_arg.
  1401. The method is adapted by XA start and XA prepare handlers to
  1402. handle XA transaction that is logged as two parts by slave applier.
  1403. This interface concerns engines that are aware of XA transaction.
  1404. */
  1405. typedef void (*replace_native_transaction_in_thd_t)(THD *thd, void *new_trx_arg,
  1406. void **ptr_trx_arg);
  1407. /** Mode for initializing the data dictionary. */
  1408. enum dict_init_mode_t {
  1409. DICT_INIT_CREATE_FILES, ///< Create all required SE files
  1410. DICT_INIT_CHECK_FILES, ///< Verify existence of expected files
  1411. DICT_INIT_UPGRADE_57_FILES, ///< Used for upgrade from mysql-5.7
  1412. DICT_INIT_IGNORE_FILES ///< Don't care about files at all
  1413. };
  1414. /**
  1415. Initialize the SE for being used to store the DD tables. Create
  1416. the required files according to the dict_init_mode. Create strings
  1417. representing the required DDSE tables, i.e., tables that the DDSE
  1418. expects to exist in the DD, and add them to the appropriate out
  1419. parameter.
  1420. @note There are two variants of this function type, one is to be
  1421. used by the DDSE, and has a different type of output parameters
  1422. because the SQL layer needs more information about the DDSE tables
  1423. in order to support upgrade.
  1424. @param dict_init_mode How to initialize files
  1425. @param version Target DD version if a new
  1426. server is being installed.
  1427. 0 if restarting an existing
  1428. server.
  1429. @param [out] DDSE_tables List of SQL DDL statements
  1430. for creating DD tables that
  1431. are needed by the DDSE.
  1432. @param [out] DDSE_tablespaces List of meta data for predefined
  1433. tablespaces created by the DDSE.
  1434. @retval true An error occurred.
  1435. @retval false Success - no errors.
  1436. */
  1437. typedef bool (*dict_init_t)(dict_init_mode_t dict_init_mode, uint version,
  1438. List<const Plugin_table> *DDSE_tables,
  1439. List<const Plugin_tablespace> *DDSE_tablespaces);
  1440. typedef bool (*ddse_dict_init_t)(
  1441. dict_init_mode_t dict_init_mode, uint version,
  1442. List<const dd::Object_table> *DDSE_tables,
  1443. List<const Plugin_tablespace> *DDSE_tablespaces);
  1444. /**
  1445. Initialize the set of hard coded DD table ids.
  1446. */
  1447. typedef void (*dict_register_dd_table_id_t)(dd::Object_id hard_coded_tables);
  1448. /**
  1449. Invalidate an entry in the local dictionary cache.
  1450. Needed during bootstrap to make sure the contents in the DDSE
  1451. dictionary cache is in sync with the global DD.
  1452. @param schema_name Schema name.
  1453. @param table_name Table name.
  1454. */
  1455. typedef void (*dict_cache_reset_t)(const char *schema_name,
  1456. const char *table_name);
  1457. /**
  1458. Invalidate all table and tablespace entries in the local dictionary cache.
  1459. Needed for recovery during server restart.
  1460. */
  1461. typedef void (*dict_cache_reset_tables_and_tablespaces_t)();
  1462. /** Mode for data dictionary recovery. */
  1463. enum dict_recovery_mode_t {
  1464. DICT_RECOVERY_INITIALIZE_SERVER, ///< First start of a new server
  1465. DICT_RECOVERY_INITIALIZE_TABLESPACES, ///< First start, create tablespaces
  1466. DICT_RECOVERY_RESTART_SERVER ///< Restart of an existing server
  1467. };
  1468. /**
  1469. Do recovery in the DDSE as part of initializing the data dictionary.
  1470. The dict_recovery_mode indicates what kind of recovery should be
  1471. done.
  1472. @param dict_recovery_mode How to do recovery
  1473. @param version Target DD version if a new
  1474. server is being installed.
  1475. Actual DD version if restarting
  1476. an existing server.
  1477. @retval true An error occurred.
  1478. @retval false Success - no errors.
  1479. */
  1480. typedef bool (*dict_recover_t)(dict_recovery_mode_t dict_recovery_mode,
  1481. uint version);
  1482. /**
  1483. Get the server version id stored in the header of the
  1484. dictionary tablespace.
  1485. @param [out] version Version number from the DD
  1486. tablespace header.
  1487. @retval Operation outcome, false if no error, otherwise true.
  1488. */
  1489. typedef bool (*dict_get_server_version_t)(uint *version);
  1490. /**
  1491. Store the current server version number into the
  1492. header of the dictionary tablespace.
  1493. @retval Operation outcome, false if no error, otherwise true.
  1494. */
  1495. typedef bool (*dict_set_server_version_t)();
  1496. /**
  1497. Notify/get permission from storage engine before acquisition or after
  1498. release of exclusive metadata lock on object represented by key.
  1499. @param thd Thread context.
  1500. @param mdl_key MDL key identifying object on which exclusive
  1501. lock is to be acquired/was released.
  1502. @param notification_type Indicates whether this is pre-acquire or
  1503. post-release notification.
  1504. @param victimized 'true' if locking failed as we were selected
  1505. as a victim in order to avoid possible deadlocks.
  1506. @note Notification is done only for objects from TABLESPACE, SCHEMA,
  1507. TABLE, FUNCTION, PROCEDURE, TRIGGER and EVENT namespaces.
  1508. @note Problems during notification are to be reported as warnings, MDL
  1509. subsystem will report generic error if pre-acquire notification
  1510. fails/SE refuses lock acquisition.
  1511. @note Return value is ignored/error is not reported in case of
  1512. post-release notification.
  1513. @note In some cases post-release notification might happen even if
  1514. there were no prior pre-acquire notification. For example,
  1515. when SE was loaded after exclusive lock acquisition, or when
  1516. we need notify SEs which permitted lock acquisition that it
  1517. didn't happen because one of SEs didn't allow it (in such case
  1518. we will do post-release notification for all SEs for simplicity).
  1519. @return False - if notification was successful/lock can be acquired,
  1520. True - if it has failed/lock should not be acquired.
  1521. */
  1522. typedef bool (*notify_exclusive_mdl_t)(THD *thd, const MDL_key *mdl_key,
  1523. ha_notification_type notification_type,
  1524. bool *victimized);
  1525. /**
  1526. Notify/get permission from storage engine before or after execution of
  1527. ALTER TABLE operation on the table identified by the MDL key.
  1528. @param thd Thread context.
  1529. @param mdl_key MDL key identifying table which is going to be
  1530. or was ALTERed.
  1531. @param notification_type Indicates whether this is pre-ALTER TABLE or
  1532. post-ALTER TABLE notification.
  1533. @note This hook is necessary because for ALTER TABLE upgrade to X
  1534. metadata lock happens fairly late during the execution process,
  1535. so it can be expensive to abort ALTER TABLE operation at this
  1536. stage by returning failure from notify_exclusive_mdl() hook.
  1537. @note This hook follows the same error reporting convention as
  1538. @see notify_exclusive_mdl().
  1539. @note Similarly to notify_exclusive_mdl() in some cases post-ALTER
  1540. notification might happen even if there were no prior pre-ALTER
  1541. notification.
  1542. @note Post-ALTER notification can happen before post-release notification
  1543. for exclusive metadata lock acquired by this ALTER TABLE.
  1544. @return False - if notification was successful/ALTER TABLE can proceed.
  1545. True - if it has failed/ALTER TABLE should be aborted.
  1546. */
  1547. typedef bool (*notify_alter_table_t)(THD *thd, const MDL_key *mdl_key,
  1548. ha_notification_type notification_type);
  1549. /**
  1550. @brief
  1551. Initiate master key rotation
  1552. @returns false on success,
  1553. true on failure
  1554. */
  1555. typedef bool (*rotate_encryption_master_key_t)(void);
  1556. /**
  1557. @brief
  1558. Retrieve ha_statistics from SE.
  1559. @param db_name Name of schema
  1560. @param table_name Name of table
  1561. @param se_private_id SE private id of the table.
  1562. @param ts_se_private_data Tablespace SE private data.
  1563. @param tbl_se_private_data Table SE private data.
  1564. @param flags Type of statistics to retrieve.
  1565. @param[out] stats Contains statistics read from SE.
  1566. @note Handlers that implement this callback/API should adhere
  1567. to servers expectation that, the implementation would invoke
  1568. my_error() before returning 'true'/failure from this function.
  1569. @returns false on success,
  1570. true on failure
  1571. */
  1572. typedef bool (*get_table_statistics_t)(
  1573. const char *db_name, const char *table_name, dd::Object_id se_private_id,
  1574. const dd::Properties &ts_se_private_data,
  1575. const dd::Properties &tbl_se_private_data, uint flags,
  1576. ha_statistics *stats);
  1577. /**
  1578. @brief
  1579. Retrieve index column cardinality from SE.
  1580. @param db_name Name of schema
  1581. @param table_name Name of table
  1582. @param index_name Name of index
  1583. @param index_ordinal_position Position of index.
  1584. @param column_ordinal_position Position of column in index.
  1585. @param se_private_id SE private id of the table.
  1586. @param[out] cardinality cardinality being returned by SE.
  1587. @note Handlers that implement this callback/API should adhere
  1588. to servers expectation that, the implementation would invoke
  1589. my_error() before returning 'true'/failure from this function.
  1590. @returns false on success,
  1591. true on failure
  1592. */
  1593. typedef bool (*get_index_column_cardinality_t)(
  1594. const char *db_name, const char *table_name, const char *index_name,
  1595. uint index_ordinal_position, uint column_ordinal_position,
  1596. dd::Object_id se_private_id, ulonglong *cardinality);
  1597. /**
  1598. Retrieve ha_tablespace_statistics from SE.
  1599. @param tablespace_name Tablespace_name
  1600. @param ts_se_private_data Tablespace SE private data.
  1601. @param tbl_se_private_data Table SE private data.
  1602. @param[out] stats Contains tablespace
  1603. statistics read from SE.
  1604. @note Handlers that implement this callback/API should adhere
  1605. to servers expectation that, the implementation would invoke
  1606. my_error() before returning 'true'/failure from this function.
  1607. @returns false on success, true on failure
  1608. */
  1609. typedef bool (*get_tablespace_statistics_t)(
  1610. const char *tablespace_name, const char *file_name,
  1611. const dd::Properties &ts_se_private_data, ha_tablespace_statistics *stats);
  1612. /* Database physical clone interfaces */
  1613. /** Get capability flags for clone operation
  1614. @param[out] flags capability flag */
  1615. using Clone_capability_t = void (*)(Ha_clone_flagset &flags);
  1616. /** Begin copy from source database
  1617. @param[in] hton handlerton for SE
  1618. @param[in] thd server thread handle
  1619. @param[in,out] loc locator
  1620. @param[in,out] loc_len locator length
  1621. @param[out] task_id task identifier
  1622. @param[in] type clone type
  1623. @param[in] mode mode for starting clone
  1624. @return error code */
  1625. using Clone_begin_t = int (*)(handlerton *hton, THD *thd, const uchar *&loc,
  1626. uint &loc_len, uint &task_id, Ha_clone_type type,
  1627. Ha_clone_mode mode);
  1628. /** Copy data from source database in chunks via callback
  1629. @param[in] hton handlerton for SE
  1630. @param[in] thd server thread handle
  1631. @param[in] loc locator
  1632. @param[in] loc_len locator length in bytes
  1633. @param[in] task_id task identifier
  1634. @param[in] cbk callback interface for sending data
  1635. @return error code */
  1636. using Clone_copy_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
  1637. uint loc_len, uint task_id, Ha_clone_cbk *cbk);
  1638. /** Acknowledge data transfer to source database
  1639. @param[in] hton handlerton for SE
  1640. @param[in] thd server thread handle
  1641. @param[in] loc locator
  1642. @param[in] loc_len locator length in bytes
  1643. @param[in] task_id task identifier
  1644. @param[in] in_err inform any error occurred
  1645. @param[in] cbk callback interface
  1646. @return error code */
  1647. using Clone_ack_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
  1648. uint loc_len, uint task_id, int in_err,
  1649. Ha_clone_cbk *cbk);
  1650. /** End copy from source database
  1651. @param[in] hton handlerton for SE
  1652. @param[in] thd server thread handle
  1653. @param[in] loc locator
  1654. @param[in] loc_len locator length in bytes
  1655. @param[in] task_id task identifier
  1656. @param[in] in_err error code when ending after error
  1657. @return error code */
  1658. using Clone_end_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
  1659. uint loc_len, uint task_id, int in_err);
  1660. /** Begin apply to destination database
  1661. @param[in] hton handlerton for SE
  1662. @param[in] thd server thread handle
  1663. @param[in,out] loc locator
  1664. @param[in,out] loc_len locator length
  1665. @param[in] task_id task identifier
  1666. @param[in] mode mode for starting clone
  1667. @param[in] data_dir target data directory
  1668. @return error code */
  1669. using Clone_apply_begin_t = int (*)(handlerton *hton, THD *thd,
  1670. const uchar *&loc, uint &loc_len,
  1671. uint &task_id, Ha_clone_mode mode,
  1672. const char *data_dir);
  1673. /** Apply data to destination database in chunks via callback
  1674. @param[in] hton handlerton for SE
  1675. @param[in] thd server thread handle
  1676. @param[in] loc locator
  1677. @param[in] loc_len locator length in bytes
  1678. @param[in] task_id task identifier
  1679. @param[in] in_err inform any error occurred
  1680. @param[in] cbk callback interface for receiving data
  1681. @return error code */
  1682. using Clone_apply_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
  1683. uint loc_len, uint task_id, int in_err,
  1684. Ha_clone_cbk *cbk);
  1685. /** End apply to destination database
  1686. @param[in] hton handlerton for SE
  1687. @param[in] thd server thread handle
  1688. @param[in] loc locator
  1689. @param[in] loc_len locator length in bytes
  1690. @param[in] task_id task identifier
  1691. @param[in] in_err error code when ending after error
  1692. @return error code */
  1693. using Clone_apply_end_t = int (*)(handlerton *hton, THD *thd, const uchar *loc,
  1694. uint loc_len, uint task_id, int in_err);
  1695. struct Clone_interface_t {
  1696. /* Get clone capabilities of an SE */
  1697. Clone_capability_t clone_capability;
  1698. /* Interfaces to copy data. */
  1699. Clone_begin_t clone_begin;
  1700. Clone_copy_t clone_copy;
  1701. Clone_ack_t clone_ack;
  1702. Clone_end_t clone_end;
  1703. /* Interfaces to apply data. */
  1704. Clone_apply_begin_t clone_apply_begin;
  1705. Clone_apply_t clone_apply;
  1706. Clone_apply_end_t clone_apply_end;
  1707. };
  1708. /**
  1709. Perform post-commit/rollback cleanup after DDL statement (e.g. in
  1710. case of DROP TABLES really remove table files from disk).
  1711. @note This hook will be invoked after DDL commit or rollback only
  1712. for storage engines supporting atomic DDL.
  1713. @note Problems during execution of this method should be reported to
  1714. error log and as warnings/notes to user. Since this method is
  1715. called after successful commit of the statement we can't fail
  1716. statement with error.
  1717. */
  1718. typedef void (*post_ddl_t)(THD *thd);
  1719. /**
  1720. Perform SE-specific cleanup after recovery of transactions.
  1721. @note Particularly SEs supporting atomic DDL can use this call
  1722. to perform post-DDL actions for DDL statements which were
  1723. committed or rolled back during recovery stage.
  1724. */
  1725. typedef void (*post_recover_t)(void);
  1726. /**
  1727. Lock a handlerton (resource) log to collect log information.
  1728. */
  1729. typedef bool (*lock_hton_log_t)(handlerton *hton);
  1730. /**
  1731. Unlock a handlerton (resource) log after collecting log information.
  1732. */
  1733. typedef bool (*unlock_hton_log_t)(handlerton *hton);
  1734. /**
  1735. Collect a handlerton (resource) log information.
  1736. */
  1737. typedef bool (*collect_hton_log_info_t)(handlerton *hton, Json_dom *json);
  1738. /**
  1739. Check SE considers types of child and parent columns in foreign key
  1740. to be compatible.
  1741. @param child_column_type Child column type description.
  1742. @param parent_column_type Parent column type description.
  1743. @param check_charsets Indicates whether we need to check
  1744. that charsets of string columns
  1745. match. Which is true in most cases.
  1746. @returns True if types are compatible, False if not.
  1747. */
  1748. typedef bool (*check_fk_column_compat_t)(
  1749. const Ha_fk_column_type *child_column_type,
  1750. const Ha_fk_column_type *parent_column_type, bool check_charsets);
  1751. typedef bool (*is_reserved_db_name_t)(handlerton *hton, const char *name);
  1752. /**
  1753. Prepare the secondary engine for executing a statement. This function is
  1754. called right after the secondary engine TABLE objects have been opened by
  1755. open_secondary_engine_tables(), before the statement is optimized and
  1756. executed. Secondary engines will typically create a context object in this
  1757. function, which they can use to store state that is needed during the
  1758. optimization and execution phases.
  1759. @param thd thread context
  1760. @param lex the statement to execute
  1761. @return true on error, false on success
  1762. */
  1763. using prepare_secondary_engine_t = bool (*)(THD *thd, LEX *lex);
  1764. /**
  1765. Optimize a statement for execution on a secondary storage engine. This
  1766. function is called when the optimization of a statement has completed, just
  1767. before the statement is executed. Secondary engines can use this function to
  1768. apply engine-specific optimizations to the execution plan. They can also
  1769. reject executing the query by raising an error, in which case the query will
  1770. be reprepared and executed by the primary storage engine.
  1771. @param thd thread context
  1772. @param lex the statement being optimized
  1773. @return true on error, false on success
  1774. */
  1775. using optimize_secondary_engine_t = bool (*)(THD *thd, LEX *lex);
  1776. /**
  1777. Compares the cost of two join plans in the secondary storage engine. The cost
  1778. of the current candidate is compared with the cost of the best plan seen so
  1779. far.
  1780. @param thd thread context
  1781. @param join the JOIN to evaluate
  1782. @param table_order the ordering of the tables in the candidate plan
  1783. @param optimizer_cost the cost estimate calculated by the optimizer
  1784. @param[out] cheaper true if the candidate is the best plan seen so far for
  1785. this JOIN (must be true if it is the first plan seen),
  1786. false otherwise
  1787. @param[out] secondary_engine_cost the cost estimated by the secondary engine
  1788. @return false on success, or true if an error has been raised
  1789. */
  1790. using compare_secondary_engine_cost_t = bool (*)(
  1791. THD *thd, const JOIN &join, const Candidate_table_order &table_order,
  1792. double optimizer_cost, bool *cheaper, double *secondary_engine_cost);
  1793. // FIXME: Temporary workaround to enable storage engine plugins to use the
  1794. // before_commit hook. Remove after WL#11320 has been completed.
  1795. typedef void (*se_before_commit_t)(void *arg);
  1796. // FIXME: Temporary workaround to enable storage engine plugins to use the
  1797. // after_commit hook. Remove after WL#11320 has been completed.
  1798. typedef void (*se_after_commit_t)(void *arg);
  1799. // FIXME: Temporary workaround to enable storage engine plugins to use the
  1800. // before_rollback hook. Remove after WL#11320 has been completed.
  1801. typedef void (*se_before_rollback_t)(void *arg);
  1802. /*
  1803. Page Tracking : interfaces to handlerton functions which starts/stops page
  1804. tracking, and purges/fetches page tracking information.
  1805. */
  1806. /**
  1807. Start page tracking.
  1808. @param[out] start_id SE specific sequence number [LSN for InnoDB]
  1809. indicating when the tracking was started
  1810. @return Operation status.
  1811. @retval 0 Success
  1812. @retval other ER_* mysql error. Get error details from THD.
  1813. */
  1814. using page_track_start_t = int (*)(uint64_t *start_id);
  1815. /**
  1816. Stop page tracking.
  1817. @param[out] stop_id SE specific sequence number [LSN for InnoDB]
  1818. indicating when the tracking was stopped
  1819. @return Operation status.
  1820. @retval 0 Success
  1821. @retval other ER_* mysql error. Get error details from THD.
  1822. */
  1823. using page_track_stop_t = int (*)(uint64_t *stop_id);
  1824. /**
  1825. Purge page tracking data.
  1826. @param[in,out] purge_id SE specific sequence number [LSN for InnoDB]
  1827. initially indicating till where the data needs to be purged and finally
  1828. updated to until where it was actually purged
  1829. @return Operation status.
  1830. @retval 0 Success
  1831. @retval other ER_* mysql error. Get error details from THD.
  1832. */
  1833. using page_track_purge_t = int (*)(uint64_t *purge_id);
  1834. /**
  1835. Fetch tracked pages.
  1836. @param[in] cbk_func callback function return page IDs
  1837. @param[in] cbk_ctx caller's context for callback
  1838. @param[in,out] start_id SE specific sequence number [LSN for InnoDB] from
  1839. where the pages tracked would be returned.
  1840. @note The range might get expanded and the actual start_id used for the
  1841. querying will be updated.
  1842. @param[in,out] stop_id SE specific sequence number [LSN for InnoDB]
  1843. until where the pages tracked would be returned.
  1844. @note The range might get expanded and the actual stop_id used for the
  1845. querying will be updated.
  1846. @param[out] buffer allocated buffer to copy page IDs
  1847. @param[in] buffer_len length of buffer in bytes
  1848. @return Operation status.
  1849. @retval 0 Success
  1850. @retval other ER_* mysql error. Get error details from THD.
  1851. */
  1852. using page_track_get_page_ids_t = int (*)(Page_Track_Callback cbk_func,
  1853. void *cbk_ctx, uint64_t *start_id,
  1854. uint64_t *stop_id,
  1855. unsigned char *buffer,
  1856. size_t buffer_len);
  1857. /**
  1858. Fetch approximate number of tracked pages in the given range.
  1859. @param[in,out] start_id SE specific sequence number [LSN for InnoDB] from
  1860. where the pages tracked would be returned.
  1861. @note the range might get expanded and the actual start_id used for the
  1862. querying will be updated.
  1863. @param[in,out] stop_id SE specific sequence number [LSN for InnoDB]
  1864. until where the pages tracked would be returned.
  1865. @note the range might get expanded and the actual stop_id used for the
  1866. querying will be updated.
  1867. @param[out] num_pages number of pages tracked
  1868. @return Operation status.
  1869. @retval 0 Success
  1870. @retval other ER_* mysql error. Get error details from THD.
  1871. */
  1872. using page_track_get_num_page_ids_t = int (*)(uint64_t *start_id,
  1873. uint64_t *stop_id,
  1874. uint64_t *num_pages);
  1875. /** Fetch the status of the page tracking system.
  1876. @param[out] status vector of a pair of (ID, bool) where ID is the
  1877. start/stop point and bool is true if the ID is a start point else false */
  1878. using page_track_get_status_t =
  1879. void (*)(std::vector<std::pair<uint64_t, bool>> &status);
  1880. /** Page track interface */
  1881. struct Page_track_t {
  1882. page_track_start_t start;
  1883. page_track_stop_t stop;
  1884. page_track_purge_t purge;
  1885. page_track_get_page_ids_t get_page_ids;
  1886. page_track_get_num_page_ids_t get_num_page_ids;
  1887. page_track_get_status_t get_status;
  1888. };
  1889. /**
  1890. handlerton is a singleton structure - one instance per storage engine -
  1891. to provide access to storage engine functionality that works on the
  1892. "global" level (unlike handler class that works on a per-table basis).
  1893. usually handlerton instance is defined statically in ha_xxx.cc as
  1894. static handlerton { ... } xxx_hton;
  1895. savepoint_*, prepare, recover, and *_by_xid pointers can be 0.
  1896. */
  1897. struct handlerton {
  1898. /**
  1899. Historical marker for if the engine is available or not.
  1900. */
  1901. SHOW_COMP_OPTION state;
  1902. /**
  1903. Historical number used for frm file to determine the correct storage engine.
  1904. This is going away and new engines will just use "name" for this.
  1905. */
  1906. enum legacy_db_type db_type;
  1907. /**
  1908. Each storage engine has it's own memory area (actually a pointer)
  1909. in the thd, for storing per-connection information.
  1910. It is accessed as
  1911. thd->ha_data[xxx_hton.slot]
  1912. slot number is initialized by MySQL after xxx_init() is called.
  1913. */
  1914. uint slot;
  1915. /**
  1916. To store per-savepoint data storage engine is provided with an area
  1917. of a requested size (0 is ok here).
  1918. savepoint_offset must be initialized statically to the size of
  1919. the needed memory to store per-savepoint information.
  1920. After xxx_init it is changed to be an offset to savepoint storage
  1921. area and need not be used by storage engine.
  1922. see binlog_hton and binlog_savepoint_set/rollback for an example.
  1923. */
  1924. uint savepoint_offset;
  1925. /* handlerton methods */
  1926. close_connection_t close_connection;
  1927. kill_connection_t kill_connection;
  1928. pre_dd_shutdown_t pre_dd_shutdown;
  1929. savepoint_set_t savepoint_set;
  1930. savepoint_rollback_t savepoint_rollback;
  1931. savepoint_rollback_can_release_mdl_t savepoint_rollback_can_release_mdl;
  1932. savepoint_release_t savepoint_release;
  1933. commit_t commit;
  1934. rollback_t rollback;
  1935. prepare_t prepare;
  1936. recover_t recover;
  1937. commit_by_xid_t commit_by_xid;
  1938. rollback_by_xid_t rollback_by_xid;
  1939. create_t create;
  1940. drop_database_t drop_database;
  1941. panic_t panic;
  1942. start_consistent_snapshot_t start_consistent_snapshot;
  1943. flush_logs_t flush_logs;
  1944. show_status_t show_status;
  1945. partition_flags_t partition_flags;
  1946. is_valid_tablespace_name_t is_valid_tablespace_name;
  1947. get_tablespace_t get_tablespace;
  1948. alter_tablespace_t alter_tablespace;
  1949. get_tablespace_filename_ext_t get_tablespace_filename_ext;
  1950. upgrade_tablespace_t upgrade_tablespace;
  1951. upgrade_space_version_t upgrade_space_version;
  1952. get_tablespace_type_t get_tablespace_type;
  1953. get_tablespace_type_by_name_t get_tablespace_type_by_name;
  1954. upgrade_logs_t upgrade_logs;
  1955. finish_upgrade_t finish_upgrade;
  1956. fill_is_table_t fill_is_table;
  1957. dict_init_t dict_init;
  1958. ddse_dict_init_t ddse_dict_init;
  1959. dict_register_dd_table_id_t dict_register_dd_table_id;
  1960. dict_cache_reset_t dict_cache_reset;
  1961. dict_cache_reset_tables_and_tablespaces_t
  1962. dict_cache_reset_tables_and_tablespaces;
  1963. dict_recover_t dict_recover;
  1964. dict_get_server_version_t dict_get_server_version;
  1965. dict_set_server_version_t dict_set_server_version;
  1966. is_reserved_db_name_t is_reserved_db_name;
  1967. /** Global handler flags. */
  1968. uint32 flags;
  1969. /*
  1970. Those handlerton functions below are properly initialized at handler
  1971. init.
  1972. */
  1973. binlog_func_t binlog_func;
  1974. binlog_log_query_t binlog_log_query;
  1975. discover_t discover;
  1976. find_files_t find_files;
  1977. table_exists_in_engine_t table_exists_in_engine;
  1978. make_pushed_join_t make_pushed_join;
  1979. is_supported_system_table_t is_supported_system_table;
  1980. /*
  1981. APIs for retrieving Serialized Dictionary Information by tablespace id
  1982. */
  1983. sdi_create_t sdi_create;
  1984. sdi_drop_t sdi_drop;
  1985. sdi_get_keys_t sdi_get_keys;
  1986. sdi_get_t sdi_get;
  1987. sdi_set_t sdi_set;
  1988. sdi_delete_t sdi_delete;
  1989. /**
  1990. Null-ended array of file extentions that exist for the storage engine.
  1991. Used by frm_error() and the default handler::rename_table and delete_table
  1992. methods in handler.cc.
  1993. For engines that have two file name extentions (separate meta/index file
  1994. and data file), the order of elements is relevant. First element of engine
  1995. file name extentions array should be meta/index file extention. Second
  1996. element - data file extention. This order is assumed by
  1997. prepare_for_repair() when REPAIR TABLE ... USE_FRM is issued.
  1998. For engines that don't have files, file_extensions is NULL.
  1999. Currently, the following alternatives are used:
  2000. - file_extensions == NULL;
  2001. - file_extensions[0] != NULL, file_extensions[1] == NULL;
  2002. - file_extensions[0] != NULL, file_extensions[1] != NULL,
  2003. file_extensions[2] == NULL;
  2004. */
  2005. const char **file_extensions;
  2006. is_dict_readonly_t is_dict_readonly;
  2007. rm_tmp_tables_t rm_tmp_tables;
  2008. get_cost_constants_t get_cost_constants;
  2009. replace_native_transaction_in_thd_t replace_native_transaction_in_thd;
  2010. notify_exclusive_mdl_t notify_exclusive_mdl;
  2011. notify_alter_table_t notify_alter_table;
  2012. rotate_encryption_master_key_t rotate_encryption_master_key;
  2013. get_table_statistics_t get_table_statistics;
  2014. get_index_column_cardinality_t get_index_column_cardinality;
  2015. get_tablespace_statistics_t get_tablespace_statistics;
  2016. post_ddl_t post_ddl;
  2017. post_recover_t post_recover;
  2018. /** Clone data transfer interfaces */
  2019. Clone_interface_t clone_interface;
  2020. /** Flag for Engine License. */
  2021. uint32 license;
  2022. /** Location for engines to keep personal structures. */
  2023. void *data;
  2024. /*
  2025. Log_resource functions that must be supported by storage engines
  2026. with relevant log information to be collected.
  2027. */
  2028. lock_hton_log_t lock_hton_log;
  2029. unlock_hton_log_t unlock_hton_log;
  2030. collect_hton_log_info_t collect_hton_log_info;
  2031. /** Flags describing details of foreign key support by storage engine. */
  2032. uint32 foreign_keys_flags;
  2033. check_fk_column_compat_t check_fk_column_compat;
  2034. /**
  2035. Pointer to a function that prepares a secondary engine for executing a
  2036. statement.
  2037. @see prepare_secondary_engine_t for function signature.
  2038. */
  2039. prepare_secondary_engine_t prepare_secondary_engine;
  2040. /**
  2041. Pointer to a function that optimizes the current statement for
  2042. execution on the secondary storage engine represented by this
  2043. handlerton.
  2044. @see optimize_secondary_engine_t for function signature.
  2045. */
  2046. optimize_secondary_engine_t optimize_secondary_engine;
  2047. /**
  2048. Pointer to a function that estimates the cost of executing a join in a
  2049. secondary storage engine.
  2050. @see compare_secondary_engine_cost_t for function signature.
  2051. */
  2052. compare_secondary_engine_cost_t compare_secondary_engine_cost;
  2053. se_before_commit_t se_before_commit;
  2054. se_after_commit_t se_after_commit;
  2055. se_before_rollback_t se_before_rollback;
  2056. /** Page tracking interface */
  2057. Page_track_t page_track;
  2058. };
  2059. /* Possible flags of a handlerton (there can be 32 of them) */
  2060. #define HTON_NO_FLAGS 0
  2061. #define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0)
  2062. #define HTON_ALTER_NOT_SUPPORTED (1 << 1) // Engine does not support alter
  2063. #define HTON_CAN_RECREATE (1 << 2) // Delete all is used fro truncate
  2064. #define HTON_HIDDEN (1 << 3) // Engine does not appear in lists
  2065. /*
  2066. Bit 4 was occupied by BDB-specific HTON_FLUSH_AFTER_RENAME flag and is no
  2067. longer used.
  2068. */
  2069. #define HTON_NOT_USER_SELECTABLE (1 << 5)
  2070. #define HTON_TEMPORARY_NOT_SUPPORTED \
  2071. (1 << 6) // Having temporary tables not supported
  2072. #define HTON_SUPPORT_LOG_TABLES (1 << 7) // Engine supports log tables
  2073. #define HTON_NO_PARTITION (1 << 8) // You can not partition these tables
  2074. /*
  2075. This flag should be set when deciding that the engine does not allow row based
  2076. binary logging (RBL) optimizations.
  2077. Currently, setting this flag, means that table's read/write_set will be left
  2078. untouched when logging changes to tables in this engine. In practice this
  2079. means that the server will not mess around with table->write_set and/or
  2080. table->read_set when using RBL and deciding whether to log full or minimal
  2081. rows.
  2082. It's valuable for instance for virtual tables, eg: Performance Schema which
  2083. have no meaning for replication.
  2084. */
  2085. #define HTON_NO_BINLOG_ROW_OPT (1 << 9)
  2086. /**
  2087. Engine supports extended keys. The flag allows to
  2088. use 'extended key' feature if the engine is able to
  2089. do it (has primary key values in the secondary key).
  2090. Note that handler flag HA_PRIMARY_KEY_IN_READ_INDEX is
  2091. actually partial case of HTON_SUPPORTS_EXTENDED_KEYS.
  2092. */
  2093. #define HTON_SUPPORTS_EXTENDED_KEYS (1 << 10)
  2094. // Engine support foreign key constraint.
  2095. #define HTON_SUPPORTS_FOREIGN_KEYS (1 << 11)
  2096. /**
  2097. Engine supports atomic DDL. That is rollback of transaction for DDL
  2098. statement will also rollback all changes in SE, commit of transaction
  2099. of DDL statement will make it durable.
  2100. */
  2101. #define HTON_SUPPORTS_ATOMIC_DDL (1 << 12)
  2102. /* Engine supports packed keys. */
  2103. #define HTON_SUPPORTS_PACKED_KEYS (1 << 13)
  2104. /** Engine is a secondary storage engine. */
  2105. #define HTON_IS_SECONDARY_ENGINE (1 << 14)
  2106. /** Engine supports secondary storage engines. */
  2107. #define HTON_SUPPORTS_SECONDARY_ENGINE (1 << 15)
  2108. /** Engine supports table or tablespace encryption . */
  2109. #define HTON_SUPPORTS_TABLE_ENCRYPTION (1 << 16)
  2110. inline bool ddl_is_atomic(const handlerton *hton) {
  2111. return (hton->flags & HTON_SUPPORTS_ATOMIC_DDL) != 0;
  2112. }
  2113. /* Bits for handlerton::foreign_keys_flags bitmap. */
  2114. /**
  2115. Engine supports both unique and non-unique parent keys for
  2116. foreign keys which contain full foreign key as its prefix.
  2117. Storage engines which support foreign keys but do not have
  2118. this flag set are assumed to support only parent keys which
  2119. are primary/unique and contain exactly the same columns as
  2120. the foreign key, possibly, in different order.
  2121. */
  2122. static const uint32 HTON_FKS_WITH_PREFIX_PARENT_KEYS = (1 << 0);
  2123. /**
  2124. Storage engine supports hash keys as supporting keys for foreign
  2125. keys. Hash key should contain all foreign key columns and only
  2126. them (altough in any order).
  2127. Storage engines which support foreign keys but do not have this
  2128. flag set are assumed to not allow hash keys as supporting keys.
  2129. */
  2130. static const uint32 HTON_FKS_WITH_SUPPORTING_HASH_KEYS = (1 << 1);
  2131. /**
  2132. Storage engine supports non-hash keys which have common prefix
  2133. with the foreign key as supporting keys for it. If there are
  2134. several such keys, one which shares biggest prefix with FK is
  2135. chosen.
  2136. Storage engines which support foreign keys but do not have this
  2137. flag set are assumed to require that supporting key contains full
  2138. foreign key as its prefix.
  2139. */
  2140. static const uint32 HTON_FKS_WITH_ANY_PREFIX_SUPPORTING_KEYS = (1 << 2);
  2141. /**
  2142. Storage engine does not support using the same key for both parent
  2143. and supporting key, but requires the two to be different.
  2144. */
  2145. static const uint32 HTON_FKS_NEED_DIFFERENT_PARENT_AND_SUPPORTING_KEYS =
  2146. (1 << 3);
  2147. /**
  2148. Engine takes into account hidden part of key (coming from primary key)
  2149. when determines if it can serve as parent key for a foreign key.
  2150. Implies HTON_FKS_WITH_PREFIX_PARENT_KEYS and is related to
  2151. HTON_SUPPORTS_EXTENDED_KEYS.
  2152. */
  2153. static const uint32 HTON_FKS_WITH_EXTENDED_PARENT_KEYS = (1 << 4);
  2154. enum enum_tx_isolation : int {
  2155. ISO_READ_UNCOMMITTED,
  2156. ISO_READ_COMMITTED,
  2157. ISO_REPEATABLE_READ,
  2158. ISO_SERIALIZABLE
  2159. };
  2160. enum enum_stats_auto_recalc : int {
  2161. HA_STATS_AUTO_RECALC_DEFAULT = 0,
  2162. HA_STATS_AUTO_RECALC_ON,
  2163. HA_STATS_AUTO_RECALC_OFF
  2164. };
  2165. /* struct to hold information about the table that should be created */
  2166. struct HA_CREATE_INFO {
  2167. const CHARSET_INFO *table_charset{nullptr};
  2168. const CHARSET_INFO *default_table_charset{nullptr};
  2169. LEX_STRING connect_string{nullptr, 0};
  2170. const char *password{nullptr};
  2171. const char *tablespace{nullptr};
  2172. LEX_STRING comment{nullptr, 0};
  2173. /**
  2174. Algorithm (and possible options) to be used for InnoDB's transparent
  2175. page compression. If this attribute is set then it is hint to the
  2176. storage engine to try and compress the data using the specified algorithm
  2177. where possible. Note: this value is interpreted by the storage engine only.
  2178. and ignored by the Server layer. */
  2179. LEX_STRING compress{nullptr, 0};
  2180. /**
  2181. This attibute is used for InnoDB's transparent page encryption.
  2182. If this attribute is set then it is hint to the storage engine to encrypt
  2183. the data. Note: this value is interpreted by the storage engine only.
  2184. and ignored by the Server layer. */
  2185. LEX_STRING encrypt_type{nullptr, 0};
  2186. /**
  2187. * Secondary engine of the table.
  2188. * Is nullptr if no secondary engine defined.
  2189. */
  2190. LEX_CSTRING secondary_engine{nullptr, 0};
  2191. const char *data_file_name{nullptr};
  2192. const char *index_file_name{nullptr};
  2193. const char *alias{nullptr};
  2194. ulonglong max_rows{0};
  2195. ulonglong min_rows{0};
  2196. ulonglong auto_increment_value{0};
  2197. ulong table_options{0};
  2198. ulong avg_row_length{0};
  2199. ulong used_fields{0};
  2200. ulong key_block_size{0};
  2201. uint stats_sample_pages{0}; /* number of pages to sample during
  2202. stats estimation, if used, otherwise 0. */
  2203. enum_stats_auto_recalc stats_auto_recalc{HA_STATS_AUTO_RECALC_DEFAULT};
  2204. SQL_I_List<TABLE_LIST> merge_list;
  2205. handlerton *db_type{nullptr};
  2206. /**
  2207. Row type of the table definition.
  2208. Defaults to ROW_TYPE_DEFAULT for all non-ALTER statements.
  2209. For ALTER TABLE defaults to ROW_TYPE_NOT_USED (means "keep the current").
  2210. Can be changed either explicitly by the parser.
  2211. If nothing specified inherits the value of the original table (if present).
  2212. */
  2213. enum row_type row_type = ROW_TYPE_DEFAULT;
  2214. uint null_bits{0}; /* NULL bits at start of record */
  2215. uint options{0}; /* OR of HA_CREATE_ options */
  2216. uint merge_insert_method{0};
  2217. ha_storage_media storage_media{HA_SM_DEFAULT}; /* DEFAULT, DISK or MEMORY */
  2218. /*
  2219. A flag to indicate if this table should be marked as a hidden table in
  2220. the data dictionary. One use case is to mark the temporary tables
  2221. created by ALTER to be marked as hidden.
  2222. */
  2223. bool m_hidden{false};
  2224. /**
  2225. Fill HA_CREATE_INFO to be used by ALTER as well as upgrade code.
  2226. This function separates code from mysql_prepare_alter_table() to be
  2227. used by upgrade code as well to reduce code duplication.
  2228. For ALTER code path, this lets new create options override the old
  2229. ones.
  2230. @param[in] share TABLE_SHARE object
  2231. @param[in] used_fields If a given create option is not flagged, old
  2232. value be copied from the TABLE_SHARE.
  2233. */
  2234. void init_create_options_from_share(const TABLE_SHARE *share,
  2235. uint used_fields);
  2236. };
  2237. /**
  2238. Structure describing changes to an index to be caused by ALTER TABLE.
  2239. */
  2240. struct KEY_PAIR {
  2241. /**
  2242. Pointer to KEY object describing old version of index in
  2243. TABLE::key_info array for TABLE instance representing old
  2244. version of table.
  2245. */
  2246. KEY *old_key;
  2247. /**
  2248. Pointer to KEY object describing new version of index in
  2249. Alter_inplace_info::key_info_buffer array.
  2250. */
  2251. KEY *new_key;
  2252. };
  2253. /**
  2254. In-place alter handler context.
  2255. This is a superclass intended to be subclassed by individual handlers
  2256. in order to store handler unique context between in-place alter API calls.
  2257. The handler is responsible for creating the object. This can be done
  2258. as early as during check_if_supported_inplace_alter().
  2259. The SQL layer is responsible for destroying the object.
  2260. @see Alter_inplace_info
  2261. */
  2262. class inplace_alter_handler_ctx {
  2263. public:
  2264. inplace_alter_handler_ctx() {}
  2265. virtual void set_shared_data(
  2266. const inplace_alter_handler_ctx *ctx MY_ATTRIBUTE((unused))) {}
  2267. virtual ~inplace_alter_handler_ctx() {}
  2268. };
  2269. /**
  2270. Class describing changes to be done by ALTER TABLE.
  2271. Instance of this class is passed to storage engine in order
  2272. to determine if this ALTER TABLE can be done using in-place
  2273. algorithm. It is also used for executing the ALTER TABLE
  2274. using in-place algorithm.
  2275. */
  2276. class Alter_inplace_info {
  2277. public:
  2278. /**
  2279. Bits to show in detail what operations the storage engine is
  2280. to execute.
  2281. All these operations are supported as in-place operations by the
  2282. SQL layer. This means that operations that by their nature must
  2283. be performed by copying the table to a temporary table, will not
  2284. have their own flags here (e.g. ALTER TABLE FORCE, ALTER TABLE
  2285. ENGINE).
  2286. We generally try to specify handler flags only if there are real
  2287. changes. But in cases when it is cumbersome to determine if some
  2288. attribute has really changed we might choose to set flag
  2289. pessimistically, for example, relying on parser output only.
  2290. */
  2291. typedef ulonglong HA_ALTER_FLAGS;
  2292. // Add non-unique, non-primary index
  2293. static const HA_ALTER_FLAGS ADD_INDEX = 1ULL << 0;
  2294. // Drop non-unique, non-primary index
  2295. static const HA_ALTER_FLAGS DROP_INDEX = 1ULL << 1;
  2296. // Add unique, non-primary index
  2297. static const HA_ALTER_FLAGS ADD_UNIQUE_INDEX = 1ULL << 2;
  2298. // Drop unique, non-primary index
  2299. static const HA_ALTER_FLAGS DROP_UNIQUE_INDEX = 1ULL << 3;
  2300. // Add primary index
  2301. static const HA_ALTER_FLAGS ADD_PK_INDEX = 1ULL << 4;
  2302. // Drop primary index
  2303. static const HA_ALTER_FLAGS DROP_PK_INDEX = 1ULL << 5;
  2304. // Add column
  2305. // Virtual generated column
  2306. static const HA_ALTER_FLAGS ADD_VIRTUAL_COLUMN = 1ULL << 6;
  2307. // Stored base (non-generated) column
  2308. static const HA_ALTER_FLAGS ADD_STORED_BASE_COLUMN = 1ULL << 7;
  2309. // Stored generated column
  2310. static const HA_ALTER_FLAGS ADD_STORED_GENERATED_COLUMN = 1ULL << 8;
  2311. // Add generic column (convience constant).
  2312. static const HA_ALTER_FLAGS ADD_COLUMN =
  2313. ADD_VIRTUAL_COLUMN | ADD_STORED_BASE_COLUMN | ADD_STORED_GENERATED_COLUMN;
  2314. // Drop column
  2315. static const HA_ALTER_FLAGS DROP_VIRTUAL_COLUMN = 1ULL << 9;
  2316. static const HA_ALTER_FLAGS DROP_STORED_COLUMN = 1ULL << 10;
  2317. static const HA_ALTER_FLAGS DROP_COLUMN =
  2318. DROP_VIRTUAL_COLUMN | DROP_STORED_COLUMN;
  2319. // Rename column
  2320. static const HA_ALTER_FLAGS ALTER_COLUMN_NAME = 1ULL << 11;
  2321. // Change column datatype
  2322. static const HA_ALTER_FLAGS ALTER_VIRTUAL_COLUMN_TYPE = 1ULL << 12;
  2323. static const HA_ALTER_FLAGS ALTER_STORED_COLUMN_TYPE = 1ULL << 13;
  2324. /**
  2325. Change column datatype in such way that new type has compatible
  2326. packed representation with old type, so it is theoretically
  2327. possible to perform change by only updating data dictionary
  2328. without changing table rows.
  2329. */
  2330. static const HA_ALTER_FLAGS ALTER_COLUMN_EQUAL_PACK_LENGTH = 1ULL << 14;
  2331. /// A virtual column has changed its position
  2332. static const HA_ALTER_FLAGS ALTER_VIRTUAL_COLUMN_ORDER = 1ULL << 15;
  2333. /// A stored column has changed its position (disregarding virtual columns)
  2334. static const HA_ALTER_FLAGS ALTER_STORED_COLUMN_ORDER = 1ULL << 16;
  2335. // Change column from NOT NULL to NULL
  2336. static const HA_ALTER_FLAGS ALTER_COLUMN_NULLABLE = 1ULL << 17;
  2337. // Change column from NULL to NOT NULL
  2338. static const HA_ALTER_FLAGS ALTER_COLUMN_NOT_NULLABLE = 1ULL << 18;
  2339. // Set or remove default column value
  2340. static const HA_ALTER_FLAGS ALTER_COLUMN_DEFAULT = 1ULL << 19;
  2341. // Change column generation expression
  2342. static const HA_ALTER_FLAGS ALTER_VIRTUAL_GCOL_EXPR = 1ULL << 20;
  2343. static const HA_ALTER_FLAGS ALTER_STORED_GCOL_EXPR = 1ULL << 21;
  2344. // Add foreign key
  2345. static const HA_ALTER_FLAGS ADD_FOREIGN_KEY = 1ULL << 22;
  2346. // Drop foreign key
  2347. static const HA_ALTER_FLAGS DROP_FOREIGN_KEY = 1ULL << 23;
  2348. // table_options changed, see HA_CREATE_INFO::used_fields for details.
  2349. static const HA_ALTER_FLAGS CHANGE_CREATE_OPTION = 1ULL << 24;
  2350. // Table is renamed
  2351. static const HA_ALTER_FLAGS ALTER_RENAME = 1ULL << 25;
  2352. // Change the storage type of column
  2353. static const HA_ALTER_FLAGS ALTER_COLUMN_STORAGE_TYPE = 1ULL << 26;
  2354. // Change the column format of column
  2355. static const HA_ALTER_FLAGS ALTER_COLUMN_COLUMN_FORMAT = 1ULL << 27;
  2356. // Add partition
  2357. static const HA_ALTER_FLAGS ADD_PARTITION = 1ULL << 28;
  2358. // Drop partition
  2359. static const HA_ALTER_FLAGS DROP_PARTITION = 1ULL << 29;
  2360. // Changing partition options
  2361. static const HA_ALTER_FLAGS ALTER_PARTITION = 1ULL << 30;
  2362. // Coalesce partition
  2363. static const HA_ALTER_FLAGS COALESCE_PARTITION = 1ULL << 31;
  2364. // Reorganize partition ... into
  2365. static const HA_ALTER_FLAGS REORGANIZE_PARTITION = 1ULL << 32;
  2366. // Reorganize partition
  2367. static const HA_ALTER_FLAGS ALTER_TABLE_REORG = 1ULL << 33;
  2368. // Remove partitioning
  2369. static const HA_ALTER_FLAGS ALTER_REMOVE_PARTITIONING = 1ULL << 34;
  2370. // Partition operation with ALL keyword
  2371. static const HA_ALTER_FLAGS ALTER_ALL_PARTITION = 1ULL << 35;
  2372. /**
  2373. Rename index. Note that we set this flag only if there are no other
  2374. changes to the index being renamed. Also for simplicity we don't
  2375. detect renaming of indexes which is done by dropping index and then
  2376. re-creating index with identical definition under different name.
  2377. */
  2378. static const HA_ALTER_FLAGS RENAME_INDEX = 1ULL << 36;
  2379. /**
  2380. Recreate the table for ALTER TABLE FORCE, ALTER TABLE ENGINE
  2381. and OPTIMIZE TABLE operations.
  2382. */
  2383. static const HA_ALTER_FLAGS RECREATE_TABLE = 1ULL << 37;
  2384. // Add spatial index
  2385. static const HA_ALTER_FLAGS ADD_SPATIAL_INDEX = 1ULL << 38;
  2386. // Alter index comment
  2387. static const HA_ALTER_FLAGS ALTER_INDEX_COMMENT = 1ULL << 39;
  2388. // New/changed virtual generated column require validation
  2389. static const HA_ALTER_FLAGS VALIDATE_VIRTUAL_COLUMN = 1ULL << 40;
  2390. /**
  2391. Change index option in a way which is likely not to require index
  2392. recreation. For example, change COMMENT or KEY::is_algorithm_explicit
  2393. flag (without change of index algorithm itself).
  2394. */
  2395. static const HA_ALTER_FLAGS CHANGE_INDEX_OPTION = 1LL << 41;
  2396. // Rebuild partition
  2397. static const HA_ALTER_FLAGS ALTER_REBUILD_PARTITION = 1ULL << 42;
  2398. /**
  2399. Change in index length such that it does not require index rebuild.
  2400. For example, change in index length due to column expansion like
  2401. varchar(X) changed to varchar(X + N).
  2402. */
  2403. static const HA_ALTER_FLAGS ALTER_COLUMN_INDEX_LENGTH = 1ULL << 43;
  2404. /**
  2405. Change to one of columns on which virtual generated column depends,
  2406. so its values require re-evaluation.
  2407. */
  2408. static const HA_ALTER_FLAGS VIRTUAL_GCOL_REEVAL = 1ULL << 44;
  2409. /**
  2410. Change to one of columns on which stored generated column depends,
  2411. so its values require re-evaluation.
  2412. */
  2413. static const HA_ALTER_FLAGS STORED_GCOL_REEVAL = 1ULL << 45;
  2414. // Add check constraint.
  2415. static const HA_ALTER_FLAGS ADD_CHECK_CONSTRAINT = 1ULL << 46;
  2416. // Drop check constraint.
  2417. static const HA_ALTER_FLAGS DROP_CHECK_CONSTRAINT = 1ULL << 47;
  2418. // Suspend check constraint.
  2419. static const HA_ALTER_FLAGS SUSPEND_CHECK_CONSTRAINT = 1ULL << 48;
  2420. /**
  2421. Create options (like MAX_ROWS) for the new version of table.
  2422. @note The referenced instance of HA_CREATE_INFO object was already
  2423. used to create new .FRM file for table being altered. So it
  2424. has been processed by mysql_prepare_create_table() already.
  2425. For example, this means that it has HA_OPTION_PACK_RECORD
  2426. flag in HA_CREATE_INFO::table_options member correctly set.
  2427. */
  2428. HA_CREATE_INFO *create_info;
  2429. /**
  2430. Alter options, fields and keys for the new version of table.
  2431. @note The referenced instance of Alter_info object was already
  2432. used to create new .FRM file for table being altered. So it
  2433. has been processed by mysql_prepare_create_table() already.
  2434. In particular, this means that in Create_field objects for
  2435. fields which were present in some form in the old version
  2436. of table, Create_field::field member points to corresponding
  2437. Field instance for old version of table.
  2438. */
  2439. Alter_info *alter_info;
  2440. /**
  2441. Indicates whether operation should fail if table is non-empty.
  2442. Storage engines should not suggest/allow execution of such operations
  2443. using INSTANT algorithm since check whether table is empty done from
  2444. SQL-layer is not "instant". Also SEs might choose different algorithm for
  2445. ALTER TABLE execution knowing that it will be allowed to proceed only if
  2446. table is empty.
  2447. Unlike for Alter_table_ctx::error_if_not_empty, we use bool for this flag
  2448. and not bitmap, since SEs are really interested in the fact that ALTER
  2449. will fail if table is not empty and not in exact reason behind this fact,
  2450. and because we want to avoid extra dependency between Alter_table_ctx and
  2451. Alter_inplace_info.
  2452. */
  2453. bool error_if_not_empty;
  2454. /**
  2455. Array of KEYs for new version of table - including KEYs to be added.
  2456. @note Currently this array is produced as result of
  2457. mysql_prepare_create_table() call.
  2458. This means that it follows different convention for
  2459. KEY_PART_INFO::fieldnr values than objects in TABLE::key_info
  2460. array.
  2461. @todo This is mainly due to the fact that we need to keep compatibility
  2462. with removed handler::add_index() call. We plan to switch to
  2463. TABLE::key_info numbering later.
  2464. KEYs are sorted - see sort_keys().
  2465. */
  2466. KEY *key_info_buffer;
  2467. /** Size of key_info_buffer array. */
  2468. uint key_count;
  2469. /** Size of index_drop_buffer array. */
  2470. uint index_drop_count;
  2471. /**
  2472. Array of pointers to KEYs to be dropped belonging to the TABLE instance
  2473. for the old version of the table.
  2474. */
  2475. KEY **index_drop_buffer;
  2476. /** Size of index_add_buffer array. */
  2477. uint index_add_count;
  2478. /**
  2479. Array of indexes into key_info_buffer for KEYs to be added,
  2480. sorted in increasing order.
  2481. */
  2482. uint *index_add_buffer;
  2483. /** Size of index_rename_buffer array. */
  2484. uint index_rename_count;
  2485. /** Size of index_rename_buffer array. */
  2486. uint index_altered_visibility_count;
  2487. /**
  2488. Array of KEY_PAIR objects describing indexes being renamed.
  2489. For each index renamed it contains object with KEY_PAIR::old_key
  2490. pointing to KEY object belonging to the TABLE instance for old
  2491. version of table representing old version of index and with
  2492. KEY_PAIR::new_key pointing to KEY object for new version of
  2493. index in key_info_buffer member.
  2494. */
  2495. KEY_PAIR *index_rename_buffer;
  2496. KEY_PAIR *index_altered_visibility_buffer;
  2497. /** Number of virtual columns to be added. */
  2498. uint virtual_column_add_count;
  2499. /** number of virtual columns to be dropped. */
  2500. uint virtual_column_drop_count;
  2501. /**
  2502. Context information to allow handlers to keep context between in-place
  2503. alter API calls.
  2504. @see inplace_alter_handler_ctx for information about object lifecycle.
  2505. */
  2506. inplace_alter_handler_ctx *handler_ctx;
  2507. /**
  2508. If the table uses several handlers, like ha_partition uses one handler
  2509. per partition, this contains a Null terminated array of ctx pointers
  2510. that should all be committed together.
  2511. Or NULL if only handler_ctx should be committed.
  2512. Set to NULL if the low level handler::commit_inplace_alter_table uses it,
  2513. to signal to the main handler that everything was committed as atomically.
  2514. @see inplace_alter_handler_ctx for information about object lifecycle.
  2515. */
  2516. inplace_alter_handler_ctx **group_commit_ctx;
  2517. /**
  2518. Flags describing in detail which operations the storage engine is to
  2519. execute.
  2520. */
  2521. HA_ALTER_FLAGS handler_flags;
  2522. /**
  2523. Partition_info taking into account the partition changes to be performed.
  2524. Contains all partitions which are present in the old version of the table
  2525. with partitions to be dropped or changed marked as such + all partitions
  2526. to be added in the new version of table marked as such.
  2527. */
  2528. partition_info *modified_part_info;
  2529. /** true for online operation (LOCK=NONE) */
  2530. bool online;
  2531. /**
  2532. Can be set by handler along with handler_ctx. The difference is that
  2533. this flag can be used to store SE-specific in-place ALTER context in cases
  2534. when constructing full-blown inplace_alter_handler_ctx descendant is
  2535. inconvenient.
  2536. */
  2537. uint handler_trivial_ctx;
  2538. /**
  2539. Can be set by handler to describe why a given operation cannot be done
  2540. in-place (HA_ALTER_INPLACE_NOT_SUPPORTED) or why it cannot be done
  2541. online (HA_ALTER_INPLACE_NO_LOCK or HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE)
  2542. If set, it will be used with ER_ALTER_OPERATION_NOT_SUPPORTED_REASON if
  2543. results from handler::check_if_supported_inplace_alter() doesn't match
  2544. requirements set by user. If not set, the more generic
  2545. ER_ALTER_OPERATION_NOT_SUPPORTED will be used.
  2546. Please set to a properly localized string, for example using
  2547. my_get_err_msg(), so that the error message as a whole is localized.
  2548. */
  2549. const char *unsupported_reason;
  2550. Alter_inplace_info(HA_CREATE_INFO *create_info_arg,
  2551. Alter_info *alter_info_arg, bool error_if_not_empty_arg,
  2552. KEY *key_info_arg, uint key_count_arg,
  2553. partition_info *modified_part_info_arg)
  2554. : create_info(create_info_arg),
  2555. alter_info(alter_info_arg),
  2556. error_if_not_empty(error_if_not_empty_arg),
  2557. key_info_buffer(key_info_arg),
  2558. key_count(key_count_arg),
  2559. index_drop_count(0),
  2560. index_drop_buffer(NULL),
  2561. index_add_count(0),
  2562. index_add_buffer(NULL),
  2563. index_rename_count(0),
  2564. index_altered_visibility_count(0),
  2565. index_rename_buffer(NULL),
  2566. virtual_column_add_count(0),
  2567. virtual_column_drop_count(0),
  2568. handler_ctx(NULL),
  2569. group_commit_ctx(NULL),
  2570. handler_flags(0),
  2571. modified_part_info(modified_part_info_arg),
  2572. online(false),
  2573. handler_trivial_ctx(0),
  2574. unsupported_reason(NULL) {}
  2575. ~Alter_inplace_info() { destroy(handler_ctx); }
  2576. /**
  2577. Used after check_if_supported_inplace_alter() to report
  2578. error if the result does not match the LOCK/ALGORITHM
  2579. requirements set by the user.
  2580. @param not_supported Part of statement that was not supported.
  2581. @param try_instead Suggestion as to what the user should
  2582. replace not_supported with.
  2583. */
  2584. void report_unsupported_error(const char *not_supported,
  2585. const char *try_instead);
  2586. /** Add old and new version of key to array of indexes to be renamed. */
  2587. void add_renamed_key(KEY *old_key, KEY *new_key) {
  2588. KEY_PAIR *key_pair = index_rename_buffer + index_rename_count++;
  2589. key_pair->old_key = old_key;
  2590. key_pair->new_key = new_key;
  2591. DBUG_PRINT("info",
  2592. ("index renamed: '%s' to '%s'", old_key->name, new_key->name));
  2593. }
  2594. void add_altered_index_visibility(KEY *old_key, KEY *new_key) {
  2595. KEY_PAIR *key_pair =
  2596. index_altered_visibility_buffer + index_altered_visibility_count++;
  2597. key_pair->old_key = old_key;
  2598. key_pair->new_key = new_key;
  2599. DBUG_PRINT("info", ("index had visibility altered: %i to %i",
  2600. old_key->is_visible, new_key->is_visible));
  2601. }
  2602. /**
  2603. Add old and new version of modified key to arrays of indexes to
  2604. be dropped and added (correspondingly).
  2605. */
  2606. void add_modified_key(KEY *old_key, KEY *new_key) {
  2607. index_drop_buffer[index_drop_count++] = old_key;
  2608. index_add_buffer[index_add_count++] = (uint)(new_key - key_info_buffer);
  2609. DBUG_PRINT("info", ("index changed: '%s'", old_key->name));
  2610. }
  2611. /** Drop key to array of indexes to be dropped. */
  2612. void add_dropped_key(KEY *old_key) {
  2613. index_drop_buffer[index_drop_count++] = old_key;
  2614. DBUG_PRINT("info", ("index dropped: '%s'", old_key->name));
  2615. }
  2616. /** Add key to array of indexes to be added. */
  2617. void add_added_key(KEY *new_key) {
  2618. index_add_buffer[index_add_count++] = (uint)(new_key - key_info_buffer);
  2619. DBUG_PRINT("info", ("index added: '%s'", new_key->name));
  2620. }
  2621. };
  2622. struct HA_CHECK_OPT {
  2623. HA_CHECK_OPT() {} /* Remove gcc warning */
  2624. uint flags; /* isam layer flags (e.g. for myisamchk) */
  2625. uint sql_flags; /* sql layer flags - for something myisamchk cannot do */
  2626. KEY_CACHE *key_cache; /* new key cache when changing key cache */
  2627. void init();
  2628. };
  2629. /*
  2630. This is a buffer area that the handler can use to store rows.
  2631. 'end_of_used_area' should be kept updated after calls to
  2632. read-functions so that other parts of the code can use the
  2633. remaining area (until next read calls is issued).
  2634. */
  2635. struct HANDLER_BUFFER {
  2636. uchar *buffer; /* Buffer one can start using */
  2637. uchar *buffer_end; /* End of buffer */
  2638. uchar *end_of_used_area; /* End of area that was used by handler */
  2639. };
  2640. typedef void *range_seq_t;
  2641. struct RANGE_SEQ_IF {
  2642. /*
  2643. Initialize the traversal of range sequence
  2644. SYNOPSIS
  2645. init()
  2646. init_params The seq_init_param parameter
  2647. n_ranges The number of ranges obtained
  2648. flags A combination of HA_MRR_SINGLE_POINT, HA_MRR_FIXED_KEY
  2649. RETURN
  2650. An opaque value to be used as RANGE_SEQ_IF::next() parameter
  2651. */
  2652. range_seq_t (*init)(void *init_params, uint n_ranges, uint flags);
  2653. /*
  2654. Get the next range in the range sequence
  2655. SYNOPSIS
  2656. next()
  2657. seq The value returned by RANGE_SEQ_IF::init()
  2658. range OUT Information about the next range
  2659. RETURN
  2660. 0 - Ok, the range structure filled with info about the next range
  2661. 1 - No more ranges
  2662. */
  2663. uint (*next)(range_seq_t seq, KEY_MULTI_RANGE *range);
  2664. /*
  2665. Check whether range_info orders to skip the next record
  2666. SYNOPSIS
  2667. skip_record()
  2668. seq The value returned by RANGE_SEQ_IF::init()
  2669. range_info Information about the next range
  2670. (Ignored if MRR_NO_ASSOCIATION is set)
  2671. rowid Rowid of the record to be checked (ignored if set to 0)
  2672. RETURN
  2673. 1 - Record with this range_info and/or this rowid shall be filtered
  2674. out from the stream of records returned by ha_multi_range_read_next()
  2675. 0 - The record shall be left in the stream
  2676. */
  2677. bool (*skip_record)(range_seq_t seq, char *range_info, uchar *rowid);
  2678. /*
  2679. Check if the record combination matches the index condition
  2680. SYNOPSIS
  2681. skip_index_tuple()
  2682. seq The value returned by RANGE_SEQ_IF::init()
  2683. range_info Information about the next range
  2684. RETURN
  2685. 0 - The record combination satisfies the index condition
  2686. 1 - Otherwise
  2687. */
  2688. bool (*skip_index_tuple)(range_seq_t seq, char *range_info);
  2689. };
  2690. /**
  2691. Used to store optimizer cost estimates.
  2692. The class consists of PODs only: default operator=, copy constructor
  2693. and destructor are used.
  2694. */
  2695. class Cost_estimate {
  2696. private:
  2697. double io_cost; ///< cost of I/O operations
  2698. double cpu_cost; ///< cost of CPU operations
  2699. double import_cost; ///< cost of remote operations
  2700. double mem_cost; ///< memory used (bytes)
  2701. public:
  2702. Cost_estimate() : io_cost(0), cpu_cost(0), import_cost(0), mem_cost(0) {}
  2703. /// Returns sum of time-consuming costs, i.e., not counting memory cost
  2704. double total_cost() const { return io_cost + cpu_cost + import_cost; }
  2705. double get_io_cost() const { return io_cost; }
  2706. double get_cpu_cost() const { return cpu_cost; }
  2707. double get_import_cost() const { return import_cost; }
  2708. double get_mem_cost() const { return mem_cost; }
  2709. /**
  2710. Whether or not all costs in the object are zero
  2711. @return true if all costs are zero, false otherwise
  2712. */
  2713. bool is_zero() const {
  2714. return !(io_cost || cpu_cost || import_cost || mem_cost);
  2715. }
  2716. /**
  2717. Whether or not the total cost is the maximal double
  2718. @return true if total cost is the maximal double, false otherwise
  2719. */
  2720. bool is_max_cost() const { return io_cost == DBL_MAX; }
  2721. /// Reset all costs to zero
  2722. void reset() { io_cost = cpu_cost = import_cost = mem_cost = 0; }
  2723. /// Set current cost to the maximal double
  2724. void set_max_cost() {
  2725. reset();
  2726. io_cost = DBL_MAX;
  2727. }
  2728. /// Multiply io, cpu and import costs by parameter
  2729. void multiply(double m) {
  2730. DBUG_ASSERT(!is_max_cost());
  2731. io_cost *= m;
  2732. cpu_cost *= m;
  2733. import_cost *= m;
  2734. /* Don't multiply mem_cost */
  2735. }
  2736. Cost_estimate &operator+=(const Cost_estimate &other) {
  2737. DBUG_ASSERT(!is_max_cost() && !other.is_max_cost());
  2738. io_cost += other.io_cost;
  2739. cpu_cost += other.cpu_cost;
  2740. import_cost += other.import_cost;
  2741. mem_cost += other.mem_cost;
  2742. return *this;
  2743. }
  2744. Cost_estimate operator+(const Cost_estimate &other) {
  2745. Cost_estimate result = *this;
  2746. result += other;
  2747. return result;
  2748. }
  2749. Cost_estimate operator-(const Cost_estimate &other) {
  2750. Cost_estimate result;
  2751. DBUG_ASSERT(!other.is_max_cost());
  2752. result.io_cost = io_cost - other.io_cost;
  2753. result.cpu_cost = cpu_cost - other.cpu_cost;
  2754. result.import_cost = import_cost - other.import_cost;
  2755. result.mem_cost = mem_cost - other.mem_cost;
  2756. return result;
  2757. }
  2758. bool operator>(const Cost_estimate &other) const {
  2759. return total_cost() > other.total_cost() ? true : false;
  2760. }
  2761. bool operator<(const Cost_estimate &other) const {
  2762. return other > *this ? true : false;
  2763. }
  2764. /// Add to IO cost
  2765. void add_io(double add_io_cost) {
  2766. DBUG_ASSERT(!is_max_cost());
  2767. io_cost += add_io_cost;
  2768. }
  2769. /// Add to CPU cost
  2770. void add_cpu(double add_cpu_cost) {
  2771. DBUG_ASSERT(!is_max_cost());
  2772. cpu_cost += add_cpu_cost;
  2773. }
  2774. /// Add to import cost
  2775. void add_import(double add_import_cost) {
  2776. DBUG_ASSERT(!is_max_cost());
  2777. import_cost += add_import_cost;
  2778. }
  2779. /// Add to memory cost
  2780. void add_mem(double add_mem_cost) {
  2781. DBUG_ASSERT(!is_max_cost());
  2782. mem_cost += add_mem_cost;
  2783. }
  2784. };
  2785. void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted,
  2786. Cost_estimate *cost);
  2787. /*
  2788. The below two are not used (and not handled) in this milestone of this WL
  2789. entry because there seems to be no use for them at this stage of
  2790. implementation.
  2791. */
  2792. #define HA_MRR_SINGLE_POINT 1
  2793. #define HA_MRR_FIXED_KEY 2
  2794. /*
  2795. Indicates that RANGE_SEQ_IF::next(&range) doesn't need to fill in the
  2796. 'range' parameter.
  2797. */
  2798. #define HA_MRR_NO_ASSOCIATION 4
  2799. /*
  2800. The MRR user will provide ranges in key order, and MRR implementation
  2801. must return rows in key order.
  2802. Passing this flag to multi_read_range_init() may cause the
  2803. default MRR handler to be used even if HA_MRR_USE_DEFAULT_IMPL
  2804. was not specified.
  2805. (If the native MRR impl. can not provide SORTED result)
  2806. */
  2807. #define HA_MRR_SORTED 8
  2808. /* MRR implementation doesn't have to retrieve full records */
  2809. #define HA_MRR_INDEX_ONLY 16
  2810. /*
  2811. The passed memory buffer is of maximum possible size, the caller can't
  2812. assume larger buffer.
  2813. */
  2814. #define HA_MRR_LIMITS 32
  2815. /*
  2816. Flag set <=> default MRR implementation is used
  2817. (The choice is made by **_info[_const]() function which may set this
  2818. flag. SQL layer remembers the flag value and then passes it to
  2819. multi_read_range_init().
  2820. */
  2821. #define HA_MRR_USE_DEFAULT_IMPL 64
  2822. /*
  2823. Used only as parameter to multi_range_read_info():
  2824. Flag set <=> the caller guarantees that the bounds of the scanned ranges
  2825. will not have NULL values.
  2826. */
  2827. #define HA_MRR_NO_NULL_ENDPOINTS 128
  2828. /*
  2829. Set by the MRR implementation to signal that it will natively
  2830. produced sorted result if multi_range_read_init() is called with
  2831. the HA_MRR_SORTED flag - Else multi_range_read_init(HA_MRR_SORTED)
  2832. will revert to use the default MRR implementation.
  2833. */
  2834. #define HA_MRR_SUPPORT_SORTED 256
  2835. class ha_statistics {
  2836. public:
  2837. ulonglong data_file_length; /* Length off data file */
  2838. ulonglong max_data_file_length; /* Length off data file */
  2839. ulonglong index_file_length;
  2840. ulonglong max_index_file_length;
  2841. ulonglong delete_length; /* Free bytes */
  2842. ulonglong auto_increment_value;
  2843. /*
  2844. The number of records in the table.
  2845. 0 - means the table has exactly 0 rows
  2846. other - if (table_flags() & HA_STATS_RECORDS_IS_EXACT)
  2847. the value is the exact number of records in the table
  2848. else
  2849. it is an estimate
  2850. */
  2851. ha_rows records;
  2852. ha_rows deleted; /* Deleted records */
  2853. ulong mean_rec_length; /* physical reclength */
  2854. /* TODO: create_time should be retrieved from the new DD. Remove this. */
  2855. time_t create_time; /* When table was created */
  2856. ulong check_time;
  2857. ulong update_time;
  2858. uint block_size; /* index block size */
  2859. /*
  2860. number of buffer bytes that native mrr implementation needs,
  2861. */
  2862. uint mrr_length_per_rec;
  2863. /**
  2864. Estimate for how much of the table that is availabe in a memory
  2865. buffer. Valid range is [0..1]. If it has the special value
  2866. IN_MEMORY_ESTIMATE_UNKNOWN (defined in structs.h), it means that
  2867. the storage engine has not supplied any value for it.
  2868. */
  2869. double table_in_mem_estimate;
  2870. ha_statistics()
  2871. : data_file_length(0),
  2872. max_data_file_length(0),
  2873. index_file_length(0),
  2874. delete_length(0),
  2875. auto_increment_value(0),
  2876. records(0),
  2877. deleted(0),
  2878. mean_rec_length(0),
  2879. create_time(0),
  2880. check_time(0),
  2881. update_time(0),
  2882. block_size(0),
  2883. table_in_mem_estimate(IN_MEMORY_ESTIMATE_UNKNOWN) {}
  2884. };
  2885. /**
  2886. Calculates length of key.
  2887. Given a key index and a map of key parts return length of buffer used by key
  2888. parts.
  2889. @param table Table containing the key
  2890. @param key Key index
  2891. @param keypart_map which key parts that is used
  2892. @return Length of used key parts.
  2893. */
  2894. uint calculate_key_len(TABLE *table, uint key, key_part_map keypart_map);
  2895. /*
  2896. bitmap with first N+1 bits set
  2897. (keypart_map for a key prefix of [0..N] keyparts)
  2898. */
  2899. #define make_keypart_map(N) (((key_part_map)2 << (N)) - 1)
  2900. /*
  2901. bitmap with first N bits set
  2902. (keypart_map for a key prefix of [0..N-1] keyparts)
  2903. */
  2904. #define make_prev_keypart_map(N) (((key_part_map)1 << (N)) - 1)
  2905. /** Base class to be used by handlers different shares */
  2906. class Handler_share {
  2907. public:
  2908. Handler_share() {}
  2909. virtual ~Handler_share() {}
  2910. };
  2911. /**
  2912. Wrapper for struct ft_hints.
  2913. */
  2914. class Ft_hints {
  2915. private:
  2916. struct ft_hints hints;
  2917. public:
  2918. Ft_hints(uint ft_flags) {
  2919. hints.flags = ft_flags;
  2920. hints.op_type = FT_OP_UNDEFINED;
  2921. hints.op_value = 0.0;
  2922. hints.limit = HA_POS_ERROR;
  2923. }
  2924. /**
  2925. Set comparison operation type and and value for master MATCH function.
  2926. @param type comparison operation type
  2927. @param value comparison operation value
  2928. */
  2929. void set_hint_op(enum ft_operation type, double value) {
  2930. hints.op_type = type;
  2931. hints.op_value = value;
  2932. }
  2933. /**
  2934. Set Ft_hints flag.
  2935. @param ft_flag Ft_hints flag
  2936. */
  2937. void set_hint_flag(uint ft_flag) { hints.flags |= ft_flag; }
  2938. /**
  2939. Set Ft_hints limit.
  2940. @param ft_limit limit
  2941. */
  2942. void set_hint_limit(ha_rows ft_limit) { hints.limit = ft_limit; }
  2943. /**
  2944. Get Ft_hints limit.
  2945. @return Ft_hints limit
  2946. */
  2947. ha_rows get_limit() { return hints.limit; }
  2948. /**
  2949. Get Ft_hints operation value.
  2950. @return operation value
  2951. */
  2952. double get_op_value() { return hints.op_value; }
  2953. /**
  2954. Get Ft_hints operation type.
  2955. @return operation type
  2956. */
  2957. enum ft_operation get_op_type() { return hints.op_type; }
  2958. /**
  2959. Get Ft_hints flags.
  2960. @return Ft_hints flags
  2961. */
  2962. uint get_flags() { return hints.flags; }
  2963. /**
  2964. Get ft_hints struct.
  2965. @return pointer to ft_hints struct
  2966. */
  2967. struct ft_hints *get_hints() {
  2968. return &hints;
  2969. }
  2970. };
  2971. /**
  2972. The handler class is the interface for dynamically loadable
  2973. storage engines. Do not add ifdefs and take care when adding or
  2974. changing virtual functions to avoid vtable confusion
  2975. Functions in this class accept and return table columns data. Two data
  2976. representation formats are used:
  2977. 1. TableRecordFormat - Used to pass [partial] table records to/from
  2978. storage engine
  2979. 2. KeyTupleFormat - used to pass index search tuples (aka "keys") to
  2980. storage engine. See opt_range.cc for description of this format.
  2981. TableRecordFormat
  2982. =================
  2983. [Warning: this description is work in progress and may be incomplete]
  2984. The table record is stored in a fixed-size buffer:
  2985. record: null_bytes, column1_data, column2_data, ...
  2986. The offsets of the parts of the buffer are also fixed: every column has
  2987. an offset to its column{i}_data, and if it is nullable it also has its own
  2988. bit in null_bytes.
  2989. The record buffer only includes data about columns that are marked in the
  2990. relevant column set (table->read_set and/or table->write_set, depending on
  2991. the situation).
  2992. <not-sure>It could be that it is required that null bits of non-present
  2993. columns are set to 1</not-sure>
  2994. VARIOUS EXCEPTIONS AND SPECIAL CASES
  2995. If the table has no nullable columns, then null_bytes is still
  2996. present, its length is one byte <not-sure> which must be set to 0xFF
  2997. at all times. </not-sure>
  2998. If the table has columns of type BIT, then certain bits from those columns
  2999. may be stored in null_bytes as well. Grep around for Field_bit for
  3000. details.
  3001. For blob columns (see Field_blob), the record buffer stores length of the
  3002. data, following by memory pointer to the blob data. The pointer is owned
  3003. by the storage engine and is valid until the next operation.
  3004. If a blob column has NULL value, then its length and blob data pointer
  3005. must be set to 0.
  3006. Overview of main modules of the handler API
  3007. ===========================================
  3008. The overview below was copied from the storage/partition/ha_partition.h when
  3009. support for non-native partitioning was removed.
  3010. -------------------------------------------------------------------------
  3011. MODULE create/delete handler object
  3012. -------------------------------------------------------------------------
  3013. Object create/delete method. Normally called when a table object
  3014. exists.
  3015. -------------------------------------------------------------------------
  3016. MODULE meta data changes
  3017. -------------------------------------------------------------------------
  3018. Meta data routines to CREATE, DROP, RENAME table are often used at
  3019. ALTER TABLE (update_create_info used from ALTER TABLE and SHOW ..).
  3020. Methods:
  3021. delete_table()
  3022. rename_table()
  3023. create()
  3024. update_create_info()
  3025. -------------------------------------------------------------------------
  3026. MODULE open/close object
  3027. -------------------------------------------------------------------------
  3028. Open and close handler object to ensure all underlying files and
  3029. objects allocated and deallocated for query handling is handled
  3030. properly.
  3031. A handler object is opened as part of its initialisation and before
  3032. being used for normal queries (not before meta-data changes always.
  3033. If the object was opened it will also be closed before being deleted.
  3034. Methods:
  3035. open()
  3036. close()
  3037. -------------------------------------------------------------------------
  3038. MODULE start/end statement
  3039. -------------------------------------------------------------------------
  3040. This module contains methods that are used to understand start/end of
  3041. statements, transaction boundaries, and aid for proper concurrency
  3042. control.
  3043. Methods:
  3044. store_lock()
  3045. external_lock()
  3046. start_stmt()
  3047. lock_count()
  3048. unlock_row()
  3049. was_semi_consistent_read()
  3050. try_semi_consistent_read()
  3051. -------------------------------------------------------------------------
  3052. MODULE change record
  3053. -------------------------------------------------------------------------
  3054. This part of the handler interface is used to change the records
  3055. after INSERT, DELETE, UPDATE, REPLACE method calls but also other
  3056. special meta-data operations as ALTER TABLE, LOAD DATA, TRUNCATE.
  3057. These methods are used for insert (write_row), update (update_row)
  3058. and delete (delete_row). All methods to change data always work on
  3059. one row at a time. update_row and delete_row also contains the old
  3060. row.
  3061. delete_all_rows will delete all rows in the table in one call as a
  3062. special optimization for DELETE from table;
  3063. Bulk inserts are supported if all underlying handlers support it.
  3064. start_bulk_insert and end_bulk_insert is called before and after a
  3065. number of calls to write_row.
  3066. Methods:
  3067. write_row()
  3068. update_row()
  3069. delete_row()
  3070. delete_all_rows()
  3071. start_bulk_insert()
  3072. end_bulk_insert()
  3073. -------------------------------------------------------------------------
  3074. MODULE full table scan
  3075. -------------------------------------------------------------------------
  3076. This module is used for the most basic access method for any table
  3077. handler. This is to fetch all data through a full table scan. No
  3078. indexes are needed to implement this part.
  3079. It contains one method to start the scan (rnd_init) that can also be
  3080. called multiple times (typical in a nested loop join). Then proceeding
  3081. to the next record (rnd_next) and closing the scan (rnd_end).
  3082. To remember a record for later access there is a method (position)
  3083. and there is a method used to retrieve the record based on the stored
  3084. position.
  3085. The position can be a file position, a primary key, a ROWID dependent
  3086. on the handler below.
  3087. All functions that retrieve records and are callable through the
  3088. handler interface must indicate whether a record is present after the call
  3089. or not. Record found is indicated by returning 0 and setting table status
  3090. to "has row". Record not found is indicated by returning a non-zero value
  3091. and setting table status to "no row".
  3092. @see TABLE::set_found_row() and TABLE::set_no_row().
  3093. By enforcing these rules in the handler interface, storage handler functions
  3094. need not set any status in struct TABLE. These notes also apply to module
  3095. index scan, documented below.
  3096. Methods:
  3097. rnd_init()
  3098. rnd_end()
  3099. rnd_next()
  3100. rnd_pos()
  3101. rnd_pos_by_record()
  3102. position()
  3103. -------------------------------------------------------------------------
  3104. MODULE index scan
  3105. -------------------------------------------------------------------------
  3106. This part of the handler interface is used to perform access through
  3107. indexes. The interface is defined as a scan interface but the handler
  3108. can also use key lookup if the index is a unique index or a primary
  3109. key index.
  3110. Index scans are mostly useful for SELECT queries but are an important
  3111. part also of UPDATE, DELETE, REPLACE and CREATE TABLE table AS SELECT
  3112. and so forth.
  3113. Naturally an index is needed for an index scan and indexes can either
  3114. be ordered, hash based. Some ordered indexes can return data in order
  3115. but not necessarily all of them.
  3116. There are many flags that define the behavior of indexes in the
  3117. various handlers. These methods are found in the optimizer module.
  3118. index_read is called to start a scan of an index. The find_flag defines
  3119. the semantics of the scan. These flags are defined in
  3120. include/my_base.h
  3121. index_read_idx is the same but also initializes index before calling doing
  3122. the same thing as index_read. Thus it is similar to index_init followed
  3123. by index_read. This is also how we implement it.
  3124. index_read/index_read_idx does also return the first row. Thus for
  3125. key lookups, the index_read will be the only call to the handler in
  3126. the index scan.
  3127. index_init initializes an index before using it and index_end does
  3128. any end processing needed.
  3129. Methods:
  3130. index_read_map()
  3131. index_init()
  3132. index_end()
  3133. index_read_idx_map()
  3134. index_next()
  3135. index_prev()
  3136. index_first()
  3137. index_last()
  3138. index_next_same()
  3139. index_read_last_map()
  3140. read_range_first()
  3141. read_range_next()
  3142. -------------------------------------------------------------------------
  3143. MODULE information calls
  3144. -------------------------------------------------------------------------
  3145. This calls are used to inform the handler of specifics of the ongoing
  3146. scans and other actions. Most of these are used for optimisation
  3147. purposes.
  3148. Methods:
  3149. info()
  3150. get_dynamic_partition_info
  3151. extra()
  3152. extra_opt()
  3153. reset()
  3154. -------------------------------------------------------------------------
  3155. MODULE optimizer support
  3156. -------------------------------------------------------------------------
  3157. NOTE:
  3158. One important part of the public handler interface that is not depicted in
  3159. the methods is the attribute records which is defined in the base class.
  3160. This is looked upon directly and is set by calling info(HA_STATUS_INFO) ?
  3161. Methods:
  3162. min_rows_for_estimate()
  3163. get_biggest_used_partition()
  3164. scan_time()
  3165. read_time()
  3166. records_in_range()
  3167. estimate_rows_upper_bound()
  3168. records()
  3169. -------------------------------------------------------------------------
  3170. MODULE print messages
  3171. -------------------------------------------------------------------------
  3172. This module contains various methods that returns text messages for
  3173. table types, index type and error messages.
  3174. Methods:
  3175. table_type()
  3176. get_row_type()
  3177. print_error()
  3178. get_error_message()
  3179. -------------------------------------------------------------------------
  3180. MODULE handler characteristics
  3181. -------------------------------------------------------------------------
  3182. This module contains a number of methods defining limitations and
  3183. characteristics of the handler (see also documentation regarding the
  3184. individual flags).
  3185. Methods:
  3186. table_flags()
  3187. index_flags()
  3188. min_of_the_max_uint()
  3189. max_supported_record_length()
  3190. max_supported_keys()
  3191. max_supported_key_parts()
  3192. max_supported_key_length()
  3193. max_supported_key_part_length()
  3194. low_byte_first()
  3195. extra_rec_buf_length()
  3196. min_record_length(uint options)
  3197. primary_key_is_clustered()
  3198. ha_key_alg get_default_index_algorithm()
  3199. is_index_algorithm_supported()
  3200. -------------------------------------------------------------------------
  3201. MODULE compare records
  3202. -------------------------------------------------------------------------
  3203. cmp_ref checks if two references are the same. For most handlers this is
  3204. a simple memcmp of the reference. However some handlers use primary key
  3205. as reference and this can be the same even if memcmp says they are
  3206. different. This is due to character sets and end spaces and so forth.
  3207. Methods:
  3208. cmp_ref()
  3209. -------------------------------------------------------------------------
  3210. MODULE auto increment
  3211. -------------------------------------------------------------------------
  3212. This module is used to handle the support of auto increments.
  3213. This variable in the handler is used as part of the handler interface
  3214. It is maintained by the parent handler object and should not be
  3215. touched by child handler objects (see handler.cc for its use).
  3216. Methods:
  3217. get_auto_increment()
  3218. release_auto_increment()
  3219. -------------------------------------------------------------------------
  3220. MODULE initialize handler for HANDLER call
  3221. -------------------------------------------------------------------------
  3222. This method is a special InnoDB method called before a HANDLER query.
  3223. Methods:
  3224. init_table_handle_for_HANDLER()
  3225. -------------------------------------------------------------------------
  3226. MODULE foreign key support
  3227. -------------------------------------------------------------------------
  3228. The following methods are used to implement foreign keys as supported by
  3229. InnoDB and NDB.
  3230. get_foreign_key_create_info is used by SHOW CREATE TABLE to get a textual
  3231. description of how the CREATE TABLE part to define FOREIGN KEY's is done.
  3232. free_foreign_key_create_info is used to free the memory area that provided
  3233. this description.
  3234. Methods:
  3235. get_parent_foreign_key_list()
  3236. get_foreign_key_create_info()
  3237. free_foreign_key_create_info()
  3238. get_foreign_key_list()
  3239. referenced_by_foreign_key()
  3240. -------------------------------------------------------------------------
  3241. MODULE fulltext index
  3242. -------------------------------------------------------------------------
  3243. Fulltext index support.
  3244. Methods:
  3245. ft_init_ext_with_hints()
  3246. ft_init()
  3247. ft_init_ext()
  3248. ft_read()
  3249. -------------------------------------------------------------------------
  3250. MODULE in-place ALTER TABLE
  3251. -------------------------------------------------------------------------
  3252. Methods for in-place ALTER TABLE support (implemented by InnoDB and NDB).
  3253. Methods:
  3254. check_if_supported_inplace_alter()
  3255. prepare_inplace_alter_table()
  3256. inplace_alter_table()
  3257. commit_inplace_alter_table()
  3258. notify_table_changed()
  3259. -------------------------------------------------------------------------
  3260. MODULE tablespace support
  3261. -------------------------------------------------------------------------
  3262. Methods:
  3263. discard_or_import_tablespace()
  3264. -------------------------------------------------------------------------
  3265. MODULE administrative DDL
  3266. -------------------------------------------------------------------------
  3267. Methods:
  3268. optimize()
  3269. analyze()
  3270. check()
  3271. repair()
  3272. check_and_repair()
  3273. auto_repair()
  3274. is_crashed()
  3275. check_for_upgrade()
  3276. checksum()
  3277. assign_to_keycache()
  3278. -------------------------------------------------------------------------
  3279. MODULE enable/disable indexes
  3280. -------------------------------------------------------------------------
  3281. Enable/Disable Indexes are only supported by HEAP and MyISAM.
  3282. Methods:
  3283. disable_indexes()
  3284. enable_indexes()
  3285. indexes_are_disabled()
  3286. -------------------------------------------------------------------------
  3287. MODULE append_create_info
  3288. -------------------------------------------------------------------------
  3289. Only used by MyISAM MERGE tables.
  3290. Methods:
  3291. append_create_info()
  3292. -------------------------------------------------------------------------
  3293. MODULE partitioning specific handler API
  3294. -------------------------------------------------------------------------
  3295. Methods:
  3296. get_partition_handler()
  3297. */
  3298. class handler {
  3299. friend class Partition_handler;
  3300. public:
  3301. typedef ulonglong Table_flags;
  3302. protected:
  3303. TABLE_SHARE *table_share; /* The table definition */
  3304. TABLE *table; /* The current open table */
  3305. Table_flags cached_table_flags; /* Set on init() and open() */
  3306. ha_rows estimation_rows_to_insert;
  3307. public:
  3308. handlerton *ht; /* storage engine of this handler */
  3309. /** Pointer to current row */
  3310. uchar *ref;
  3311. /** Pointer to duplicate row */
  3312. uchar *dup_ref;
  3313. ha_statistics stats;
  3314. /* MultiRangeRead-related members: */
  3315. range_seq_t mrr_iter; /* Interator to traverse the range sequence */
  3316. RANGE_SEQ_IF mrr_funcs; /* Range sequence traversal functions */
  3317. HANDLER_BUFFER *multi_range_buffer; /* MRR buffer info */
  3318. uint ranges_in_seq; /* Total number of ranges in the traversed sequence */
  3319. /* true <=> source MRR ranges and the output are ordered */
  3320. bool mrr_is_output_sorted;
  3321. /* true <=> we're currently traversing a range in mrr_cur_range. */
  3322. bool mrr_have_range;
  3323. /* Current range (the one we're now returning rows from) */
  3324. KEY_MULTI_RANGE mrr_cur_range;
  3325. /*
  3326. The direction of the current range or index scan. This is used by
  3327. the ICP implementation to determine if it has reached the end
  3328. of the current range.
  3329. */
  3330. enum enum_range_scan_direction { RANGE_SCAN_ASC, RANGE_SCAN_DESC };
  3331. private:
  3332. Record_buffer *m_record_buffer = nullptr; ///< Buffer for multi-row reads.
  3333. /*
  3334. Storage space for the end range value. Should only be accessed using
  3335. the end_range pointer. The content is invalid when end_range is NULL.
  3336. */
  3337. key_range save_end_range;
  3338. enum_range_scan_direction range_scan_direction;
  3339. int key_compare_result_on_equal;
  3340. /**
  3341. Pointer to the handler of the table in the primary storage engine,
  3342. if this handler represents a table in a secondary storage engine.
  3343. */
  3344. handler *m_primary_handler{nullptr};
  3345. protected:
  3346. KEY_PART_INFO *range_key_part;
  3347. bool eq_range;
  3348. /*
  3349. true <=> the engine guarantees that returned records are within the range
  3350. being scanned.
  3351. */
  3352. bool in_range_check_pushed_down;
  3353. public:
  3354. /**
  3355. End value for a range scan. If this is NULL the range scan has no
  3356. end value. Should also be NULL when there is no ongoing range scan.
  3357. Used by the read_range() functions and also evaluated by pushed
  3358. index conditions.
  3359. */
  3360. key_range *end_range;
  3361. /**
  3362. Flag which tells if #end_range contains a virtual generated column.
  3363. The content is invalid when #end_range is @c nullptr.
  3364. */
  3365. bool m_virt_gcol_in_end_range = false;
  3366. uint errkey; /* Last dup key */
  3367. uint key_used_on_scan;
  3368. uint active_index;
  3369. /** Length of ref (1-8 or the clustered key length) */
  3370. uint ref_length;
  3371. FT_INFO *ft_handler;
  3372. enum { NONE = 0, INDEX, RND, SAMPLING } inited;
  3373. bool implicit_emptied; /* Can be !=0 only if HEAP */
  3374. const Item *pushed_cond;
  3375. Item *pushed_idx_cond;
  3376. uint pushed_idx_cond_keyno; /* The index which the above condition is for */
  3377. /**
  3378. next_insert_id is the next value which should be inserted into the
  3379. auto_increment column: in a inserting-multi-row statement (like INSERT
  3380. SELECT), for the first row where the autoinc value is not specified by the
  3381. statement, get_auto_increment() called and asked to generate a value,
  3382. next_insert_id is set to the next value, then for all other rows
  3383. next_insert_id is used (and increased each time) without calling
  3384. get_auto_increment().
  3385. */
  3386. ulonglong next_insert_id;
  3387. /**
  3388. insert id for the current row (*autogenerated*; if not
  3389. autogenerated, it's 0).
  3390. At first successful insertion, this variable is stored into
  3391. THD::first_successful_insert_id_in_cur_stmt.
  3392. */
  3393. ulonglong insert_id_for_cur_row;
  3394. /**
  3395. Interval returned by get_auto_increment() and being consumed by the
  3396. inserter.
  3397. */
  3398. Discrete_interval auto_inc_interval_for_cur_row;
  3399. /**
  3400. Number of reserved auto-increment intervals. Serves as a heuristic
  3401. when we have no estimation of how many records the statement will insert:
  3402. the more intervals we have reserved, the bigger the next one. Reset in
  3403. handler::ha_release_auto_increment().
  3404. */
  3405. uint auto_inc_intervals_count;
  3406. /**
  3407. Instrumented table associated with this handler.
  3408. */
  3409. PSI_table *m_psi;
  3410. std::mt19937 m_random_number_engine;
  3411. double m_sampling_percentage;
  3412. private:
  3413. /** Internal state of the batch instrumentation. */
  3414. enum batch_mode_t {
  3415. /** Batch mode not used. */
  3416. PSI_BATCH_MODE_NONE,
  3417. /** Batch mode used, before first table io. */
  3418. PSI_BATCH_MODE_STARTING,
  3419. /** Batch mode used, after first table io. */
  3420. PSI_BATCH_MODE_STARTED
  3421. };
  3422. /**
  3423. Batch mode state.
  3424. @sa start_psi_batch_mode.
  3425. @sa end_psi_batch_mode.
  3426. */
  3427. batch_mode_t m_psi_batch_mode;
  3428. /**
  3429. The number of rows in the batch.
  3430. @sa start_psi_batch_mode.
  3431. @sa end_psi_batch_mode.
  3432. */
  3433. ulonglong m_psi_numrows;
  3434. /**
  3435. The current event in a batch.
  3436. @sa start_psi_batch_mode.
  3437. @sa end_psi_batch_mode.
  3438. */
  3439. PSI_table_locker *m_psi_locker;
  3440. /**
  3441. Storage for the event in a batch.
  3442. @sa start_psi_batch_mode.
  3443. @sa end_psi_batch_mode.
  3444. */
  3445. PSI_table_locker_state m_psi_locker_state;
  3446. public:
  3447. void unbind_psi();
  3448. void rebind_psi();
  3449. /**
  3450. Put the handler in 'batch' mode when collecting
  3451. table io instrumented events.
  3452. When operating in batch mode:
  3453. - a single start event is generated in the performance schema.
  3454. - all table io performed between @c start_psi_batch_mode
  3455. and @c end_psi_batch_mode is not instrumented:
  3456. the number of rows affected is counted instead in @c m_psi_numrows.
  3457. - a single end event is generated in the performance schema
  3458. when the batch mode ends with @c end_psi_batch_mode.
  3459. */
  3460. void start_psi_batch_mode();
  3461. /** End a batch started with @c start_psi_batch_mode. */
  3462. void end_psi_batch_mode();
  3463. /**
  3464. If a PSI batch was started, turn if off.
  3465. @returns true if it was started.
  3466. */
  3467. bool end_psi_batch_mode_if_started() {
  3468. bool rc = m_psi_batch_mode;
  3469. if (rc) end_psi_batch_mode();
  3470. return rc;
  3471. }
  3472. private:
  3473. /**
  3474. The lock type set by when calling::ha_external_lock(). This is
  3475. propagated down to the storage engine. The reason for also storing
  3476. it here, is that when doing MRR we need to create/clone a second handler
  3477. object. This cloned handler object needs to know about the lock_type used.
  3478. */
  3479. int m_lock_type;
  3480. /**
  3481. Pointer where to store/retrieve the Handler_share pointer.
  3482. For non partitioned handlers this is &TABLE_SHARE::ha_share.
  3483. */
  3484. Handler_share **ha_share;
  3485. /**
  3486. Some non-virtual ha_* functions, responsible for reading rows,
  3487. like ha_rnd_pos(), must ensure that virtual generated columns are
  3488. calculated before they return. For that, they should set this
  3489. member to true at their start, and check it before they return: if
  3490. the member is still true, it means they should calculate; if it's
  3491. false, it means the calculation has been done by some called
  3492. lower-level function and does not need to be re-done (which is why
  3493. we need this status flag: to avoid redundant calculations, for
  3494. performance).
  3495. Note that when updating generated fields, the NULL row status in
  3496. the underlying TABLE objects matter, so be sure to reset them if needed!
  3497. */
  3498. bool m_update_generated_read_fields;
  3499. /* Filter row ids to weed out duplicates when multi-valued index is used */
  3500. Unique_on_insert *m_unique;
  3501. public:
  3502. handler(handlerton *ht_arg, TABLE_SHARE *share_arg)
  3503. : table_share(share_arg),
  3504. table(0),
  3505. estimation_rows_to_insert(0),
  3506. ht(ht_arg),
  3507. ref(0),
  3508. range_scan_direction(RANGE_SCAN_ASC),
  3509. in_range_check_pushed_down(false),
  3510. end_range(NULL),
  3511. key_used_on_scan(MAX_KEY),
  3512. active_index(MAX_KEY),
  3513. ref_length(sizeof(my_off_t)),
  3514. ft_handler(0),
  3515. inited(NONE),
  3516. implicit_emptied(0),
  3517. pushed_cond(0),
  3518. pushed_idx_cond(NULL),
  3519. pushed_idx_cond_keyno(MAX_KEY),
  3520. next_insert_id(0),
  3521. insert_id_for_cur_row(0),
  3522. auto_inc_intervals_count(0),
  3523. m_psi(NULL),
  3524. m_psi_batch_mode(PSI_BATCH_MODE_NONE),
  3525. m_psi_numrows(0),
  3526. m_psi_locker(NULL),
  3527. m_lock_type(F_UNLCK),
  3528. ha_share(NULL),
  3529. m_update_generated_read_fields(false),
  3530. m_unique(nullptr) {
  3531. DBUG_PRINT("info", ("handler created F_UNLCK %d F_RDLCK %d F_WRLCK %d",
  3532. F_UNLCK, F_RDLCK, F_WRLCK));
  3533. }
  3534. virtual ~handler(void) {
  3535. DBUG_ASSERT(m_psi == NULL);
  3536. DBUG_ASSERT(m_psi_batch_mode == PSI_BATCH_MODE_NONE);
  3537. DBUG_ASSERT(m_psi_locker == NULL);
  3538. DBUG_ASSERT(m_lock_type == F_UNLCK);
  3539. DBUG_ASSERT(inited == NONE);
  3540. }
  3541. /*
  3542. @todo reorganize functions, make proper public/protected/private qualifiers
  3543. */
  3544. virtual handler *clone(const char *name, MEM_ROOT *mem_root);
  3545. /** This is called after create to allow us to set up cached variables */
  3546. void init() { cached_table_flags = table_flags(); }
  3547. /* ha_ methods: public wrappers for private virtual API */
  3548. /**
  3549. Set a record buffer that the storage engine can use for multi-row reads.
  3550. The buffer has to be provided prior to the first read from an index or a
  3551. table.
  3552. @param buffer the buffer to use for multi-row reads
  3553. */
  3554. void ha_set_record_buffer(Record_buffer *buffer) { m_record_buffer = buffer; }
  3555. /**
  3556. Get the record buffer that was set with ha_set_record_buffer().
  3557. @return the buffer to use for multi-row reads, or nullptr if there is none
  3558. */
  3559. Record_buffer *ha_get_record_buffer() const { return m_record_buffer; }
  3560. /**
  3561. Does this handler want to get a Record_buffer for multi-row reads
  3562. via the ha_set_record_buffer() function? And if so, what is the
  3563. maximum number of records to allocate space for in the buffer?
  3564. Storage engines that support using a Record_buffer should override
  3565. handler::is_record_buffer_wanted().
  3566. @param[out] max_rows gets set to the maximum number of records to
  3567. allocate space for in the buffer if the function
  3568. returns true
  3569. @retval true if the handler would like a Record_buffer
  3570. @retval false if the handler does not want a Record_buffer
  3571. */
  3572. bool ha_is_record_buffer_wanted(ha_rows *const max_rows) const {
  3573. return is_record_buffer_wanted(max_rows);
  3574. }
  3575. int ha_open(TABLE *table, const char *name, int mode, int test_if_locked,
  3576. const dd::Table *table_def);
  3577. int ha_close(void);
  3578. int ha_index_init(uint idx, bool sorted);
  3579. int ha_index_end();
  3580. int ha_rnd_init(bool scan);
  3581. int ha_rnd_end();
  3582. int ha_rnd_next(uchar *buf);
  3583. // See the comment on m_update_generated_read_fields.
  3584. int ha_rnd_pos(uchar *buf, uchar *pos);
  3585. int ha_index_read_map(uchar *buf, const uchar *key, key_part_map keypart_map,
  3586. enum ha_rkey_function find_flag);
  3587. int ha_index_read_last_map(uchar *buf, const uchar *key,
  3588. key_part_map keypart_map);
  3589. int ha_index_read_idx_map(uchar *buf, uint index, const uchar *key,
  3590. key_part_map keypart_map,
  3591. enum ha_rkey_function find_flag);
  3592. int ha_index_next(uchar *buf);
  3593. int ha_index_prev(uchar *buf);
  3594. int ha_index_first(uchar *buf);
  3595. int ha_index_last(uchar *buf);
  3596. int ha_index_next_same(uchar *buf, const uchar *key, uint keylen);
  3597. int ha_reset();
  3598. /* this is necessary in many places, e.g. in HANDLER command */
  3599. int ha_index_or_rnd_end() {
  3600. return inited == INDEX ? ha_index_end() : inited == RND ? ha_rnd_end() : 0;
  3601. }
  3602. /**
  3603. The cached_table_flags is set at ha_open and ha_external_lock
  3604. */
  3605. Table_flags ha_table_flags() const { return cached_table_flags; }
  3606. /**
  3607. These functions represent the public interface to *users* of the
  3608. handler class, hence they are *not* virtual. For the inheritance
  3609. interface, see the (private) functions write_row(), update_row(),
  3610. and delete_row() below.
  3611. */
  3612. int ha_external_lock(THD *thd, int lock_type);
  3613. int ha_write_row(uchar *buf);
  3614. /**
  3615. Update the current row.
  3616. @param old_data the old contents of the row
  3617. @param new_data the new contents of the row
  3618. @return error status (zero on success, HA_ERR_* error code on error)
  3619. */
  3620. int ha_update_row(const uchar *old_data, uchar *new_data);
  3621. int ha_delete_row(const uchar *buf);
  3622. void ha_release_auto_increment();
  3623. int ha_check_for_upgrade(HA_CHECK_OPT *check_opt);
  3624. /** to be actually called to get 'check()' functionality*/
  3625. int ha_check(THD *thd, HA_CHECK_OPT *check_opt);
  3626. int ha_repair(THD *thd, HA_CHECK_OPT *check_opt);
  3627. void ha_start_bulk_insert(ha_rows rows);
  3628. int ha_end_bulk_insert();
  3629. int ha_bulk_update_row(const uchar *old_data, uchar *new_data,
  3630. uint *dup_key_found);
  3631. int ha_delete_all_rows();
  3632. int ha_truncate(dd::Table *table_def);
  3633. int ha_optimize(THD *thd, HA_CHECK_OPT *check_opt);
  3634. int ha_analyze(THD *thd, HA_CHECK_OPT *check_opt);
  3635. bool ha_check_and_repair(THD *thd);
  3636. int ha_disable_indexes(uint mode);
  3637. int ha_enable_indexes(uint mode);
  3638. int ha_discard_or_import_tablespace(bool discard, dd::Table *table_def);
  3639. int ha_rename_table(const char *from, const char *to,
  3640. const dd::Table *from_table_def, dd::Table *to_table_def);
  3641. int ha_delete_table(const char *name, const dd::Table *table_def);
  3642. void ha_drop_table(const char *name);
  3643. int ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info,
  3644. dd::Table *table_def);
  3645. int ha_prepare_load_table(const TABLE &table);
  3646. int ha_load_table(const TABLE &table);
  3647. int ha_unload_table(const char *db_name, const char *table_name,
  3648. bool error_if_not_loaded);
  3649. /**
  3650. Initializes a parallel scan. It creates a parallel_scan_ctx that has to
  3651. be used across all parallel_scan methods. Also, gets the number of
  3652. threads that would be spawned for parallel scan.
  3653. @param[out] scan_ctx The parallel scan context.
  3654. @param[out] num_threads Number of threads used for the scan.
  3655. @return error code
  3656. @retval 0 on success
  3657. */
  3658. virtual int parallel_scan_init(void *&scan_ctx MY_ATTRIBUTE((unused)),
  3659. size_t &num_threads MY_ATTRIBUTE((unused))) {
  3660. return (0);
  3661. }
  3662. /**
  3663. This callback is called by each parallel load thread at the beginning of
  3664. the parallel load for the adapter scan.
  3665. @param cookie The cookie for this thread
  3666. @param ncols Number of columns in each row
  3667. @param row_len The size of a row in bytes
  3668. @param col_offsets An array of size ncols, where each element represents
  3669. the offset of a column in the row data. The memory of
  3670. this array belongs to the caller and will be free-ed
  3671. after the pload_end_cbk call.
  3672. @param null_byte_offsets An array of size ncols, where each element
  3673. represents the offset of a column in the row data. The
  3674. memory of this array belongs to the caller and will be
  3675. free-ed after the pload_end_cbk call.
  3676. @param null_bitmasks An array of size ncols, where each element
  3677. represents the bitmask required to get the null bit. The
  3678. memory of this array belongs to the caller and will be
  3679. free-ed after the pload_end_cbk call.
  3680. */
  3681. using Load_init_cbk = std::function<bool(
  3682. void *cookie, ulong ncols, ulong row_len, const ulong *col_offsets,
  3683. const ulong *null_byte_offsets, const ulong *null_bitmasks)>;
  3684. /**
  3685. This callback is called by each parallel load thread when processing
  3686. of rows is required for the adapter scan.
  3687. @param[in] cookie The cookie for this thread
  3688. @param[in] nrows The nrows that are available
  3689. @param[in] rowdata The mysql-in-memory row data buffer. This is a memory
  3690. buffer for nrows records. The length of each record
  3691. is fixed and communicated via Load_init_cbk
  3692. @returns true if there is an error, false otherwise.
  3693. */
  3694. using Load_cbk = std::function<bool(void *cookie, uint nrows, void *rowdata)>;
  3695. /**
  3696. This callback is called by each parallel load thread when processing
  3697. of rows has ended for the adapter scan.
  3698. @param[in] cookie The cookie for this thread
  3699. */
  3700. using Load_end_cbk = std::function<void(void *cookie)>;
  3701. /**
  3702. Run the parallel read of data.
  3703. @param[in] scan_ctx Scan context of the parallel read.
  3704. @param[in,out] thread_ctxs Caller thread contexts.
  3705. @param[in] init_fn Callback called by each parallel load
  3706. thread at the beginning of the parallel load.
  3707. @param[in] load_fn Callback called by each parallel load
  3708. thread when processing of rows is required.
  3709. @param[in] end_fn Callback called by each parallel load
  3710. thread when processing of rows has ended.
  3711. @return error code
  3712. @retval 0 on success
  3713. */
  3714. virtual int parallel_scan(void *scan_ctx MY_ATTRIBUTE((unused)),
  3715. void **thread_ctxs MY_ATTRIBUTE((unused)),
  3716. Load_init_cbk init_fn MY_ATTRIBUTE((unused)),
  3717. Load_cbk load_fn MY_ATTRIBUTE((unused)),
  3718. Load_end_cbk end_fn MY_ATTRIBUTE((unused))) {
  3719. return (0);
  3720. }
  3721. /**
  3722. End of the parallel scan.
  3723. @param[in] scan_ctx A scan context created by parallel_scan_init.
  3724. @return error code
  3725. @retval 0 on success
  3726. */
  3727. virtual int parallel_scan_end(void *scan_ctx MY_ATTRIBUTE((unused))) {
  3728. return (0);
  3729. }
  3730. /**
  3731. Submit a dd::Table object representing a core DD table having
  3732. hardcoded data to be filled in by the DDSE. This function can be
  3733. used for retrieving the hard coded SE private data for the
  3734. mysql.dd_properties table, before creating or opening it, or for
  3735. retrieving the hard coded SE private data for a core table,
  3736. before creating or opening them.
  3737. @param dd_table [in,out] A dd::Table object representing
  3738. a core DD table.
  3739. @param reset Reset counters.
  3740. @retval true An error occurred.
  3741. @retval false Success - no errors.
  3742. */
  3743. bool ha_get_se_private_data(dd::Table *dd_table, bool reset);
  3744. void adjust_next_insert_id_after_explicit_value(ulonglong nr);
  3745. int update_auto_increment();
  3746. virtual void print_error(int error, myf errflag);
  3747. virtual bool get_error_message(int error, String *buf);
  3748. uint get_dup_key(int error);
  3749. /**
  3750. Retrieves the names of the table and the key for which there was a
  3751. duplicate entry in the case of HA_ERR_FOREIGN_DUPLICATE_KEY.
  3752. If any of the table or key name is not available this method will return
  3753. false and will not change any of child_table_name or child_key_name.
  3754. @param [out] child_table_name Table name
  3755. @param [in] child_table_name_len Table name buffer size
  3756. @param [out] child_key_name Key name
  3757. @param [in] child_key_name_len Key name buffer size
  3758. @retval true table and key names were available
  3759. and were written into the corresponding
  3760. out parameters.
  3761. @retval false table and key names were not available,
  3762. the out parameters were not touched.
  3763. */
  3764. virtual bool get_foreign_dup_key(char *child_table_name,
  3765. uint child_table_name_len,
  3766. char *child_key_name,
  3767. uint child_key_name_len);
  3768. /**
  3769. Change the internal TABLE_SHARE pointer.
  3770. @param table_arg TABLE object
  3771. @param share New share to use
  3772. @note Is used in error handling in ha_delete_table.
  3773. */
  3774. virtual void change_table_ptr(TABLE *table_arg, TABLE_SHARE *share) {
  3775. table = table_arg;
  3776. table_share = share;
  3777. }
  3778. const TABLE_SHARE *get_table_share() const { return table_share; }
  3779. /* Estimates calculation */
  3780. /**
  3781. @deprecated This function is deprecated and will be removed in a future
  3782. version. Use table_scan_cost() instead.
  3783. */
  3784. virtual double scan_time() {
  3785. return ulonglong2double(stats.data_file_length) / IO_SIZE + 2;
  3786. }
  3787. /**
  3788. The cost of reading a set of ranges from the table using an index
  3789. to access it.
  3790. @deprecated This function is deprecated and will be removed in a future
  3791. version. Use read_cost() instead.
  3792. @param index The index number.
  3793. @param ranges The number of ranges to be read.
  3794. @param rows Total number of rows to be read.
  3795. This method can be used to calculate the total cost of scanning a table
  3796. using an index by calling it using read_time(index, 1, table_size).
  3797. */
  3798. virtual double read_time(uint index MY_ATTRIBUTE((unused)), uint ranges,
  3799. ha_rows rows) {
  3800. return rows2double(ranges + rows);
  3801. }
  3802. /**
  3803. @deprecated This function is deprecated and will be removed in a future
  3804. version. Use index_scan_cost() instead.
  3805. */
  3806. virtual double index_only_read_time(uint keynr, double records);
  3807. /**
  3808. Cost estimate for doing a complete table scan.
  3809. @note For this version it is recommended that storage engines continue
  3810. to override scan_time() instead of this function.
  3811. @returns the estimated cost
  3812. */
  3813. virtual Cost_estimate table_scan_cost();
  3814. /**
  3815. Cost estimate for reading a number of ranges from an index.
  3816. The cost estimate will only include the cost of reading data that
  3817. is contained in the index. If the records need to be read, use
  3818. read_cost() instead.
  3819. @note The ranges parameter is currently ignored and is not taken
  3820. into account in the cost estimate.
  3821. @note For this version it is recommended that storage engines continue
  3822. to override index_only_read_time() instead of this function.
  3823. @param index the index number
  3824. @param ranges the number of ranges to be read
  3825. @param rows total number of rows to be read
  3826. @returns the estimated cost
  3827. */
  3828. virtual Cost_estimate index_scan_cost(uint index, double ranges, double rows);
  3829. /**
  3830. Cost estimate for reading a set of ranges from the table using an index
  3831. to access it.
  3832. @note For this version it is recommended that storage engines continue
  3833. to override read_time() instead of this function.
  3834. @param index the index number
  3835. @param ranges the number of ranges to be read
  3836. @param rows total number of rows to be read
  3837. @returns the estimated cost
  3838. */
  3839. virtual Cost_estimate read_cost(uint index, double ranges, double rows);
  3840. /**
  3841. Return an estimate on the amount of memory the storage engine will
  3842. use for caching data in memory. If this is unknown or the storage
  3843. engine does not cache data in memory -1 is returned.
  3844. */
  3845. virtual longlong get_memory_buffer_size() const { return -1; }
  3846. /**
  3847. Return an estimate of how much of the table that is currently stored
  3848. in main memory.
  3849. This estimate should be the fraction of the table that currently
  3850. is available in a main memory buffer. The estimate should be in the
  3851. range from 0.0 (nothing in memory) to 1.0 (entire table in memory).
  3852. @return The fraction of the table in main memory buffer
  3853. */
  3854. double table_in_memory_estimate() const;
  3855. /**
  3856. Return an estimate of how much of the index that is currently stored
  3857. in main memory.
  3858. This estimate should be the fraction of the index that currently
  3859. is available in a main memory buffer. The estimate should be in the
  3860. range from 0.0 (nothing in memory) to 1.0 (entire index in memory).
  3861. @param keyno the index to get an estimate for
  3862. @return The fraction of the index in main memory buffer
  3863. */
  3864. double index_in_memory_estimate(uint keyno) const;
  3865. int ha_sample_init(double sampling_percentage, int sampling_seed,
  3866. enum_sampling_method sampling_method);
  3867. int ha_sample_next(uchar *buf);
  3868. int ha_sample_end();
  3869. private:
  3870. int check_collation_compatibility();
  3871. /**
  3872. Make a guestimate for how much of a table or index is in a memory
  3873. buffer in the case where the storage engine has not provided any
  3874. estimate for this.
  3875. @param table_index_size size of the table or index
  3876. @return The fraction of the table or index in main memory buffer
  3877. */
  3878. double estimate_in_memory_buffer(ulonglong table_index_size) const;
  3879. public:
  3880. virtual ha_rows multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
  3881. void *seq_init_param,
  3882. uint n_ranges, uint *bufsz,
  3883. uint *flags, Cost_estimate *cost);
  3884. virtual ha_rows multi_range_read_info(uint keyno, uint n_ranges, uint keys,
  3885. uint *bufsz, uint *flags,
  3886. Cost_estimate *cost);
  3887. virtual int multi_range_read_init(RANGE_SEQ_IF *seq, void *seq_init_param,
  3888. uint n_ranges, uint mode,
  3889. HANDLER_BUFFER *buf);
  3890. int ha_multi_range_read_next(char **range_info);
  3891. int ha_read_range_first(const key_range *start_key, const key_range *end_key,
  3892. bool eq_range, bool sorted);
  3893. int ha_read_range_next();
  3894. bool has_transactions() {
  3895. return (ha_table_flags() & HA_NO_TRANSACTIONS) == 0;
  3896. }
  3897. virtual uint extra_rec_buf_length() const { return 0; }
  3898. /**
  3899. @brief Determine whether an error can be ignored or not.
  3900. @details This method is used to analyze the error to see whether the
  3901. error is ignorable or not. Such errors will be reported as warnings
  3902. instead of errors for IGNORE statements. This means that the statement
  3903. will not abort, but instead continue to the next row.
  3904. HA_ERR_FOUND_DUP_UNIQUE is a special case in MyISAM that means the
  3905. same thing as HA_ERR_FOUND_DUP_KEY, but can in some cases lead to
  3906. a slightly different error message.
  3907. @param error error code received from the handler interface (HA_ERR_...)
  3908. @return whether the error is ignorablel or not
  3909. @retval true the error is ignorable
  3910. @retval false the error is not ignorable
  3911. */
  3912. virtual bool is_ignorable_error(int error);
  3913. /**
  3914. @brief Determine whether an error is fatal or not.
  3915. @details This method is used to analyze the error to see whether the
  3916. error is fatal or not. A fatal error is an error that will not be
  3917. possible to handle with SP handlers and will not be subject to
  3918. retry attempts on the slave.
  3919. @param error error code received from the handler interface (HA_ERR_...)
  3920. @return whether the error is fatal or not
  3921. @retval true the error is fatal
  3922. @retval false the error is not fatal
  3923. */
  3924. virtual bool is_fatal_error(int error);
  3925. protected:
  3926. virtual int multi_range_read_next(char **range_info);
  3927. /**
  3928. Number of rows in table. If HA_COUNT_ROWS_INSTANT is set, count is
  3929. available instantly. Else do a table scan.
  3930. @param num_rows [out] num_rows number of rows in table.
  3931. @retval 0 for OK, one of the HA_xxx values in case of error.
  3932. */
  3933. virtual int records(ha_rows *num_rows);
  3934. /**
  3935. Number of rows in table counted using the secondary index chosen by
  3936. optimizer. See comments in optimize_aggregated_query() .
  3937. @param num_rows [out] Number of rows in table.
  3938. @param index Index chosen by optimizer for counting.
  3939. @retval 0 for OK, one of the HA_xxx values in case of error.
  3940. */
  3941. virtual int records_from_index(ha_rows *num_rows, uint index);
  3942. private:
  3943. /**
  3944. Function will handle the error code from call to records() and
  3945. records_from_index().
  3946. @param error return code from records() and records_from_index().
  3947. @param num_rows Check if it contains HA_POS_ERROR in case error < 0.
  3948. @retval 0 for OK, one of the HA_xxx values in case of error.
  3949. */
  3950. int handle_records_error(int error, ha_rows *num_rows);
  3951. public:
  3952. /**
  3953. Wrapper function to call records() in storage engine.
  3954. @param num_rows [out] Number of rows in table.
  3955. @retval 0 for OK, one of the HA_xxx values in case of error.
  3956. */
  3957. int ha_records(ha_rows *num_rows) {
  3958. return handle_records_error(records(num_rows), num_rows);
  3959. }
  3960. /**
  3961. Wrapper function to call records_from_index() in storage engine.
  3962. @param num_rows [out] Number of rows in table.
  3963. @param index Index chosen by optimizer for counting.
  3964. @retval 0 for OK, one of the HA_xxx values in case of error.
  3965. */
  3966. int ha_records(ha_rows *num_rows, uint index) {
  3967. return handle_records_error(records_from_index(num_rows, index), num_rows);
  3968. }
  3969. /**
  3970. Return upper bound of current number of records in the table
  3971. (max. of how many records one will retrieve when doing a full table scan)
  3972. If upper bound is not known, HA_POS_ERROR should be returned as a max
  3973. possible upper bound.
  3974. */
  3975. virtual ha_rows estimate_rows_upper_bound() {
  3976. return stats.records + EXTRA_RECORDS;
  3977. }
  3978. /**
  3979. Get real row type for the table created based on one specified by user,
  3980. CREATE TABLE options and SE capabilities.
  3981. */
  3982. virtual enum row_type get_real_row_type(
  3983. const HA_CREATE_INFO *create_info) const {
  3984. return (create_info->table_options & HA_OPTION_COMPRESS_RECORD)
  3985. ? ROW_TYPE_COMPRESSED
  3986. : ((create_info->table_options & HA_OPTION_PACK_RECORD)
  3987. ? ROW_TYPE_DYNAMIC
  3988. : ROW_TYPE_FIXED);
  3989. }
  3990. /**
  3991. Get default key algorithm for SE. It is used when user has not provided
  3992. algorithm explicitly or when algorithm specified is not supported by SE.
  3993. */
  3994. virtual enum ha_key_alg get_default_index_algorithm() const {
  3995. return HA_KEY_ALG_SE_SPECIFIC;
  3996. }
  3997. /**
  3998. Check if SE supports specific key algorithm.
  3999. @note This method is never used for FULLTEXT or SPATIAL keys.
  4000. We rely on handler::ha_table_flags() to check if such keys
  4001. are supported.
  4002. */
  4003. virtual bool is_index_algorithm_supported(enum ha_key_alg key_alg) const {
  4004. return key_alg == HA_KEY_ALG_SE_SPECIFIC;
  4005. }
  4006. /**
  4007. Signal that the table->read_set and table->write_set table maps changed
  4008. The handler is allowed to set additional bits in the above map in this
  4009. call. Normally the handler should ignore all calls until we have done
  4010. a ha_rnd_init() or ha_index_init(), write_row(), update_row or delete_row()
  4011. as there may be several calls to this routine.
  4012. */
  4013. virtual void column_bitmaps_signal();
  4014. uint get_index(void) const { return active_index; }
  4015. /**
  4016. @retval 0 Bulk update used by handler
  4017. @retval 1 Bulk update not used, normal operation used
  4018. */
  4019. virtual bool start_bulk_update() { return 1; }
  4020. /**
  4021. @retval 0 Bulk delete used by handler
  4022. @retval 1 Bulk delete not used, normal operation used
  4023. */
  4024. virtual bool start_bulk_delete() { return 1; }
  4025. /**
  4026. After this call all outstanding updates must be performed. The number
  4027. of duplicate key errors are reported in the duplicate key parameter.
  4028. It is allowed to continue to the batched update after this call, the
  4029. handler has to wait until end_bulk_update with changing state.
  4030. @param dup_key_found Number of duplicate keys found
  4031. @retval 0 Success
  4032. @retval >0 Error code
  4033. */
  4034. virtual int exec_bulk_update(uint *dup_key_found MY_ATTRIBUTE((unused))) {
  4035. DBUG_ASSERT(false);
  4036. return HA_ERR_WRONG_COMMAND;
  4037. }
  4038. /**
  4039. Perform any needed clean-up, no outstanding updates are there at the
  4040. moment.
  4041. */
  4042. virtual void end_bulk_update() { return; }
  4043. /**
  4044. Execute all outstanding deletes and close down the bulk delete.
  4045. @retval 0 Success
  4046. @retval >0 Error code
  4047. */
  4048. virtual int end_bulk_delete() {
  4049. DBUG_ASSERT(false);
  4050. return HA_ERR_WRONG_COMMAND;
  4051. }
  4052. protected:
  4053. /**
  4054. @brief
  4055. Positions an index cursor to the index specified in the handle
  4056. ('active_index'). Fetches the row if available. If the key value is null,
  4057. begin at the first key of the index.
  4058. @returns 0 if success (found a record); non-zero if no record.
  4059. */
  4060. virtual int index_read_map(uchar *buf, const uchar *key,
  4061. key_part_map keypart_map,
  4062. enum ha_rkey_function find_flag) {
  4063. uint key_len = calculate_key_len(table, active_index, keypart_map);
  4064. return index_read(buf, key, key_len, find_flag);
  4065. }
  4066. /**
  4067. Positions an index cursor to the index specified in argument. Fetches
  4068. the row if available. If the key value is null, begin at the first key of
  4069. the index.
  4070. @sa index_read_map()
  4071. */
  4072. virtual int index_read_idx_map(uchar *buf, uint index, const uchar *key,
  4073. key_part_map keypart_map,
  4074. enum ha_rkey_function find_flag);
  4075. /*
  4076. These methods are used to jump to next or previous entry in the index
  4077. scan. There are also methods to jump to first and last entry.
  4078. */
  4079. /// @see index_read_map().
  4080. virtual int index_next(uchar *) { return HA_ERR_WRONG_COMMAND; }
  4081. /// @see index_read_map().
  4082. virtual int index_prev(uchar *) { return HA_ERR_WRONG_COMMAND; }
  4083. /// @see index_read_map().
  4084. virtual int index_first(uchar *) { return HA_ERR_WRONG_COMMAND; }
  4085. /// @see index_read_map().
  4086. virtual int index_last(uchar *) { return HA_ERR_WRONG_COMMAND; }
  4087. /// @see index_read_map().
  4088. virtual int index_next_same(uchar *buf, const uchar *key, uint keylen);
  4089. /**
  4090. The following functions works like index_read, but it find the last
  4091. row with the current key value or prefix.
  4092. @see index_read_map().
  4093. */
  4094. virtual int index_read_last_map(uchar *buf, const uchar *key,
  4095. key_part_map keypart_map) {
  4096. uint key_len = calculate_key_len(table, active_index, keypart_map);
  4097. return index_read_last(buf, key, key_len);
  4098. }
  4099. virtual int read_range_first(const key_range *start_key,
  4100. const key_range *end_key, bool eq_range,
  4101. bool sorted);
  4102. virtual int read_range_next();
  4103. public:
  4104. /**
  4105. Set the end position for a range scan. This is used for checking
  4106. for when to end the range scan and by the ICP code to determine
  4107. that the next record is within the current range.
  4108. @param range The end value for the range scan
  4109. @param direction Direction of the range scan
  4110. */
  4111. void set_end_range(const key_range *range,
  4112. enum_range_scan_direction direction);
  4113. int compare_key(key_range *range);
  4114. int compare_key_icp(const key_range *range) const;
  4115. int compare_key_in_buffer(const uchar *buf) const;
  4116. virtual int ft_init() { return HA_ERR_WRONG_COMMAND; }
  4117. void ft_end() { ft_handler = NULL; }
  4118. virtual FT_INFO *ft_init_ext(uint flags MY_ATTRIBUTE((unused)),
  4119. uint inx MY_ATTRIBUTE((unused)),
  4120. String *key MY_ATTRIBUTE((unused))) {
  4121. return NULL;
  4122. }
  4123. virtual FT_INFO *ft_init_ext_with_hints(uint inx, String *key,
  4124. Ft_hints *hints) {
  4125. return ft_init_ext(hints->get_flags(), inx, key);
  4126. }
  4127. int ha_ft_read(uchar *buf);
  4128. int ha_read_first_row(uchar *buf, uint primary_key);
  4129. protected:
  4130. /// @see index_read_map().
  4131. virtual int rnd_next(uchar *buf) = 0;
  4132. /// @see index_read_map().
  4133. virtual int rnd_pos(uchar *buf, uchar *pos) = 0;
  4134. virtual int ft_read(uchar *) { return HA_ERR_WRONG_COMMAND; }
  4135. public:
  4136. /**
  4137. This function only works for handlers having
  4138. HA_PRIMARY_KEY_REQUIRED_FOR_POSITION set.
  4139. It will return the row with the PK given in the record argument.
  4140. */
  4141. virtual int rnd_pos_by_record(uchar *record) {
  4142. int error;
  4143. DBUG_ASSERT(table_flags() & HA_PRIMARY_KEY_REQUIRED_FOR_POSITION);
  4144. error = ha_rnd_init(false);
  4145. if (error != 0) return error;
  4146. position(record);
  4147. error = ha_rnd_pos(record, ref);
  4148. ha_rnd_end();
  4149. return error;
  4150. }
  4151. /**
  4152. Find number of records in a range.
  4153. Given a starting key, and an ending key estimate the number of rows that
  4154. will exist between the two. max_key may be empty which in case determine
  4155. if start_key matches any rows. Used by optimizer to calculate cost of
  4156. using a particular index.
  4157. @param inx Index number
  4158. @param min_key Start of range
  4159. @param max_key End of range
  4160. @return Number of rows in range.
  4161. */
  4162. virtual ha_rows records_in_range(uint inx MY_ATTRIBUTE((unused)),
  4163. key_range *min_key MY_ATTRIBUTE((unused)),
  4164. key_range *max_key MY_ATTRIBUTE((unused))) {
  4165. return (ha_rows)10;
  4166. }
  4167. /*
  4168. If HA_PRIMARY_KEY_REQUIRED_FOR_POSITION is set, then it sets ref
  4169. (reference to the row, aka position, with the primary key given in
  4170. the record).
  4171. Otherwise it set ref to the current row.
  4172. */
  4173. virtual void position(const uchar *record) = 0;
  4174. /**
  4175. General method to gather info from handler
  4176. ::info() is used to return information to the optimizer.
  4177. SHOW also makes use of this data Another note, if your handler
  4178. doesn't proved exact record count, you will probably want to
  4179. have the following in your code:
  4180. if (records < 2)
  4181. records = 2;
  4182. The reason is that the server will optimize for cases of only a single
  4183. record. If in a table scan you don't know the number of records
  4184. it will probably be better to set records to two so you can return
  4185. as many records as you need.
  4186. Along with records a few more variables you may wish to set are:
  4187. records
  4188. deleted
  4189. data_file_length
  4190. index_file_length
  4191. delete_length
  4192. check_time
  4193. Take a look at the public variables in handler.h for more information.
  4194. See also my_base.h for a full description.
  4195. @param flag Specifies what info is requested
  4196. */
  4197. virtual int info(uint flag) = 0;
  4198. virtual uint32 calculate_key_hash_value(
  4199. Field **field_array MY_ATTRIBUTE((unused))) {
  4200. DBUG_ASSERT(0);
  4201. return 0;
  4202. }
  4203. /**
  4204. Request storage engine to do an extra operation: enable,disable or run some
  4205. functionality.
  4206. @param operation the operation to perform
  4207. @returns
  4208. 0 on success
  4209. error otherwise
  4210. */
  4211. int ha_extra(enum ha_extra_function operation);
  4212. private:
  4213. /**
  4214. Storage engine specific implementation of ha_extra()
  4215. @param operation the operation to perform
  4216. @returns
  4217. 0 on success
  4218. error otherwise
  4219. */
  4220. virtual int extra(enum ha_extra_function operation MY_ATTRIBUTE((unused))) {
  4221. return 0;
  4222. }
  4223. public:
  4224. virtual int extra_opt(enum ha_extra_function operation,
  4225. ulong cache_size MY_ATTRIBUTE((unused))) {
  4226. return extra(operation);
  4227. }
  4228. /**
  4229. Start read (before write) removal on the current table.
  4230. @see HA_READ_BEFORE_WRITE_REMOVAL
  4231. */
  4232. virtual bool start_read_removal(void) {
  4233. DBUG_ASSERT(0);
  4234. return false;
  4235. }
  4236. /**
  4237. End read (before write) removal and return the number of rows
  4238. really written
  4239. @see HA_READ_BEFORE_WRITE_REMOVAL
  4240. */
  4241. virtual ha_rows end_read_removal(void) {
  4242. DBUG_ASSERT(0);
  4243. return (ha_rows)0;
  4244. }
  4245. /**
  4246. Normally, when running UPDATE or DELETE queries, we need to wait for other
  4247. transactions to release their locks on a given row before we can read it and
  4248. potentially update it. However, in READ UNCOMMITTED and READ COMMITTED, we
  4249. can ignore these locks if we don't intend to modify the row (e.g., because
  4250. it failed a WHERE). This is signaled through enabling “semi-consistent
  4251. read”, by calling try_semi_consistent_read(true) (and then setting it back
  4252. to false after finishing the query).
  4253. If semi-consistent read is enabled, and we are in READ UNCOMMITTED or READ
  4254. COMMITTED, the storage engine is permitted to return rows that are locked
  4255. and thus un-updatable. If the optimizer doesn't want the row, e.g., because
  4256. it got filtered out, it can call unlock_row() as usual. However, if it
  4257. intends to update the row, it needs to call was_semi_consistent_read()
  4258. before doing so. If was_semi_consistent_read() returns false, the row was
  4259. never locked to begin with and can be updated as usual. However, if it
  4260. returns 1, it was read optimistically, must be discarded (ie., do not try to
  4261. update the row) and must be re-read with locking enabled. The next read call
  4262. after was_semi_consistent_read() will automatically re-read the same row,
  4263. this time with locking enabled.
  4264. Thus, typical use in an UPDATE scenario would look like this:
  4265. file->try_semi_consistent_read(true);
  4266. file->ha_rnd_init(true);
  4267. while (file->ha_rnd_next(table->record[0]) == 0) {
  4268. if (row is filtered...) {
  4269. file->unlock_row();
  4270. continue;
  4271. }
  4272. if (file->was_semi_consistent_read()) {
  4273. // Discard the row; next ha_rnd_next() will read it again with
  4274. // locking.
  4275. continue;
  4276. }
  4277. // Process row here.
  4278. }
  4279. file->ha_rnd_end();
  4280. file->try_semi_consistent_read(false);
  4281. If the transaction isolation level is REPEATABLE READ or SERIALIZABLE,
  4282. enabling this flag has no effect.
  4283. */
  4284. virtual bool was_semi_consistent_read() { return false; }
  4285. /**
  4286. Tell the engine whether it should avoid unnecessary lock waits.
  4287. If yes, in an UPDATE or DELETE, if the row under the cursor was locked
  4288. by another transaction, the engine may try an optimistic read of
  4289. the last committed row value under the cursor.
  4290. */
  4291. virtual void try_semi_consistent_read(bool) {}
  4292. /**
  4293. Unlock last accessed row.
  4294. Record currently processed was not in the result set of the statement
  4295. and is thus unlocked. Used for UPDATE and DELETE queries.
  4296. */
  4297. virtual void unlock_row() {}
  4298. /**
  4299. Start a statement when table is locked
  4300. This method is called instead of external lock when the table is locked
  4301. before the statement is executed.
  4302. @param thd Thread object.
  4303. @param lock_type Type of external lock.
  4304. @retval >0 Error code.
  4305. @retval 0 Success.
  4306. */
  4307. virtual int start_stmt(THD *thd MY_ATTRIBUTE((unused)),
  4308. thr_lock_type lock_type MY_ATTRIBUTE((unused))) {
  4309. return 0;
  4310. }
  4311. virtual void get_auto_increment(ulonglong offset, ulonglong increment,
  4312. ulonglong nb_desired_values,
  4313. ulonglong *first_value,
  4314. ulonglong *nb_reserved_values);
  4315. void set_next_insert_id(ulonglong id) {
  4316. DBUG_PRINT("info", ("auto_increment: next value %lu", (ulong)id));
  4317. next_insert_id = id;
  4318. }
  4319. void restore_auto_increment(ulonglong prev_insert_id) {
  4320. /*
  4321. Insertion of a row failed, re-use the lastly generated auto_increment
  4322. id, for the next row. This is achieved by resetting next_insert_id to
  4323. what it was before the failed insertion (that old value is provided by
  4324. the caller). If that value was 0, it was the first row of the INSERT;
  4325. then if insert_id_for_cur_row contains 0 it means no id was generated
  4326. for this first row, so no id was generated since the INSERT started, so
  4327. we should set next_insert_id to 0; if insert_id_for_cur_row is not 0, it
  4328. is the generated id of the first and failed row, so we use it.
  4329. */
  4330. next_insert_id =
  4331. (prev_insert_id > 0) ? prev_insert_id : insert_id_for_cur_row;
  4332. }
  4333. /**
  4334. Update create info as part of ALTER TABLE.
  4335. Forward this handler call to the storage engine foreach
  4336. partition handler. The data_file_name for each partition may
  4337. need to be reset if the tablespace was moved. Use a dummy
  4338. HA_CREATE_INFO structure and transfer necessary data.
  4339. @param create_info Create info from ALTER TABLE.
  4340. */
  4341. virtual void update_create_info(
  4342. HA_CREATE_INFO *create_info MY_ATTRIBUTE((unused))) {}
  4343. virtual int assign_to_keycache(THD *, HA_CHECK_OPT *) {
  4344. return HA_ADMIN_NOT_IMPLEMENTED;
  4345. }
  4346. virtual int preload_keys(THD *, HA_CHECK_OPT *) {
  4347. return HA_ADMIN_NOT_IMPLEMENTED;
  4348. }
  4349. /* end of the list of admin commands */
  4350. /**
  4351. Check if indexes are disabled.
  4352. @retval 0 Indexes are enabled.
  4353. @retval != 0 Indexes are disabled.
  4354. */
  4355. virtual int indexes_are_disabled(void) { return 0; }
  4356. virtual void append_create_info(String *packet MY_ATTRIBUTE((unused))) {}
  4357. /**
  4358. If index == MAX_KEY then a check for table is made and if index <
  4359. MAX_KEY then a check is made if the table has foreign keys and if
  4360. a foreign key uses this index (and thus the index cannot be dropped).
  4361. @param index Index to check if foreign key uses it
  4362. @retval true Foreign key defined on table or index
  4363. @retval false No foreign key defined
  4364. */
  4365. virtual bool is_fk_defined_on_table_or_index(
  4366. uint index MY_ATTRIBUTE((unused))) {
  4367. return false;
  4368. }
  4369. virtual char *get_foreign_key_create_info() {
  4370. return (NULL);
  4371. } /* gets foreign key create string from InnoDB */
  4372. /**
  4373. Get the list of foreign keys in this table.
  4374. @remark Returns the set of foreign keys where this table is the
  4375. dependent or child table.
  4376. @param thd The thread handle.
  4377. @param [out] f_key_list The list of foreign keys.
  4378. @return The handler error code or zero for success.
  4379. */
  4380. virtual int get_foreign_key_list(THD *thd MY_ATTRIBUTE((unused)),
  4381. List<FOREIGN_KEY_INFO> *f_key_list
  4382. MY_ATTRIBUTE((unused))) {
  4383. return 0;
  4384. }
  4385. /**
  4386. Get the list of foreign keys referencing this table.
  4387. @remark Returns the set of foreign keys where this table is the
  4388. referenced or parent table.
  4389. @param thd The thread handle.
  4390. @param [out] f_key_list The list of foreign keys.
  4391. @return The handler error code or zero for success.
  4392. */
  4393. virtual int get_parent_foreign_key_list(THD *thd MY_ATTRIBUTE((unused)),
  4394. List<FOREIGN_KEY_INFO> *f_key_list
  4395. MY_ATTRIBUTE((unused))) {
  4396. return 0;
  4397. }
  4398. /**
  4399. Get the list of tables which are direct or indirect parents in foreign
  4400. key with cascading actions for this table.
  4401. @remarks Returns the set of parent tables connected by FK clause that
  4402. can modify the given table.
  4403. @param thd The thread handle.
  4404. @param[out] fk_table_list List of parent tables (including indirect
  4405. parents). Elements of the list as well as buffers for database and schema
  4406. names are allocated from the current memory root.
  4407. @return The handler error code or zero for success
  4408. */
  4409. virtual int get_cascade_foreign_key_table_list(
  4410. THD *thd MY_ATTRIBUTE((unused)),
  4411. List<st_handler_tablename> *fk_table_list MY_ATTRIBUTE((unused))) {
  4412. return 0;
  4413. }
  4414. virtual uint referenced_by_foreign_key() { return 0; }
  4415. virtual void init_table_handle_for_HANDLER() {
  4416. return;
  4417. } /* prepare InnoDB for HANDLER */
  4418. virtual void free_foreign_key_create_info(char *) {}
  4419. /** The following can be called without an open handler */
  4420. virtual const char *table_type() const = 0;
  4421. virtual ulong index_flags(uint idx, uint part, bool all_parts) const = 0;
  4422. uint max_record_length() const {
  4423. return std::min(HA_MAX_REC_LENGTH, max_supported_record_length());
  4424. }
  4425. uint max_keys() const {
  4426. return std::min<uint>(MAX_KEY, max_supported_keys());
  4427. }
  4428. uint max_key_parts() const {
  4429. return std::min(MAX_REF_PARTS, max_supported_key_parts());
  4430. }
  4431. uint max_key_length() const {
  4432. return std::min(MAX_KEY_LENGTH, max_supported_key_length());
  4433. }
  4434. uint max_key_part_length(HA_CREATE_INFO *create_info) const {
  4435. return std::min(MAX_KEY_LENGTH, max_supported_key_part_length(create_info));
  4436. }
  4437. virtual uint max_supported_record_length() const { return HA_MAX_REC_LENGTH; }
  4438. virtual uint max_supported_keys() const { return 0; }
  4439. virtual uint max_supported_key_parts() const { return MAX_REF_PARTS; }
  4440. virtual uint max_supported_key_length() const { return MAX_KEY_LENGTH; }
  4441. virtual uint max_supported_key_part_length(
  4442. HA_CREATE_INFO *create_info MY_ATTRIBUTE((unused))) const {
  4443. return 255;
  4444. }
  4445. virtual uint min_record_length(uint options MY_ATTRIBUTE((unused))) const {
  4446. return 1;
  4447. }
  4448. virtual bool low_byte_first() const { return 1; }
  4449. virtual ha_checksum checksum() const { return 0; }
  4450. /**
  4451. Check if the table is crashed.
  4452. @retval true Crashed
  4453. @retval false Not crashed
  4454. */
  4455. virtual bool is_crashed() const { return 0; }
  4456. /**
  4457. Check if the table can be automatically repaired.
  4458. @retval true Can be auto repaired
  4459. @retval false Cannot be auto repaired
  4460. */
  4461. virtual bool auto_repair() const { return 0; }
  4462. /**
  4463. Get number of lock objects returned in store_lock.
  4464. Returns the number of store locks needed in call to store lock.
  4465. We return number of partitions we will lock multiplied with number of
  4466. locks needed by each partition. Assists the above functions in allocating
  4467. sufficient space for lock structures.
  4468. @returns Number of locks returned in call to store_lock.
  4469. @note lock_count() can return > 1 if the table is MERGE or partitioned.
  4470. */
  4471. virtual uint lock_count(void) const { return 1; }
  4472. /**
  4473. Is not invoked for non-transactional temporary tables.
  4474. @note store_lock() can return more than one lock if the table is MERGE
  4475. or partitioned.
  4476. @note that one can NOT rely on table->in_use in store_lock(). It may
  4477. refer to a different thread if called from mysql_lock_abort_for_thread().
  4478. @note If the table is MERGE, store_lock() can return less locks
  4479. than lock_count() claimed. This can happen when the MERGE children
  4480. are not attached when this is called from another thread.
  4481. The idea with handler::store_lock() is the following:
  4482. The statement decided which locks we should need for the table
  4483. for updates/deletes/inserts we get WRITE locks, for SELECT... we get
  4484. read locks.
  4485. Before adding the lock into the table lock handler (see thr_lock.c)
  4486. mysqld calls store lock with the requested locks. Store lock can now
  4487. modify a write lock to a read lock (or some other lock), ignore the
  4488. lock (if we don't want to use MySQL table locks at all) or add locks
  4489. for many tables (like we do when we are using a MERGE handler).
  4490. In some exceptional cases MySQL may send a request for a TL_IGNORE;
  4491. This means that we are requesting the same lock as last time and this
  4492. should also be ignored.
  4493. Called from lock.cc by get_lock_data().
  4494. */
  4495. virtual THR_LOCK_DATA **store_lock(THD *thd, THR_LOCK_DATA **to,
  4496. enum thr_lock_type lock_type) = 0;
  4497. /**
  4498. Check if the primary key is clustered or not.
  4499. @retval true Primary key (if there is one) is a clustered
  4500. key covering all fields
  4501. @retval false otherwise
  4502. */
  4503. virtual bool primary_key_is_clustered() const { return false; }
  4504. /**
  4505. Compare two positions.
  4506. @param ref1 First position.
  4507. @param ref2 Second position.
  4508. @retval <0 ref1 < ref2.
  4509. @retval 0 Equal.
  4510. @retval >0 ref1 > ref2.
  4511. */
  4512. virtual int cmp_ref(const uchar *ref1, const uchar *ref2) const {
  4513. return memcmp(ref1, ref2, ref_length);
  4514. }
  4515. /*
  4516. Condition pushdown to storage engines
  4517. */
  4518. /**
  4519. Push condition down to the table handler.
  4520. @param cond Condition to be pushed. The condition tree
  4521. must not be modified by the caller.
  4522. @param other_tbls_ok Are other tables than than 'this' allowed to
  4523. be referred by the condition terms being pushed.
  4524. @return
  4525. The 'remainder' condition that caller must use to filter out records.
  4526. NULL means the handler will not return rows that do not match the
  4527. passed condition.
  4528. @note
  4529. handler->ha_reset() call discard any pushed conditions.
  4530. Calls to rnd_init/rnd_end, index_init/index_end etc do not affect the
  4531. pushed conditions.
  4532. */
  4533. virtual const Item *cond_push(const Item *cond,
  4534. bool other_tbls_ok MY_ATTRIBUTE((unused))) {
  4535. DBUG_ASSERT(pushed_cond == NULL);
  4536. return cond;
  4537. }
  4538. /**
  4539. Push down an index condition to the handler.
  4540. The server will use this method to push down a condition it wants
  4541. the handler to evaluate when retrieving records using a specified
  4542. index. The pushed index condition will only refer to fields from
  4543. this handler that is contained in the index (but it may also refer
  4544. to fields in other handlers). Before the handler evaluates the
  4545. condition it must read the content of the index entry into the
  4546. record buffer.
  4547. The handler is free to decide if and how much of the condition it
  4548. will take responsibility for evaluating. Based on this evaluation
  4549. it should return the part of the condition it will not evaluate.
  4550. If it decides to evaluate the entire condition it should return
  4551. NULL. If it decides not to evaluate any part of the condition it
  4552. should return a pointer to the same condition as given as argument.
  4553. @param keyno the index number to evaluate the condition on
  4554. @param idx_cond the condition to be evaluated by the handler
  4555. @return The part of the pushed condition that the handler decides
  4556. not to evaluate
  4557. */
  4558. virtual Item *idx_cond_push(uint keyno MY_ATTRIBUTE((unused)),
  4559. Item *idx_cond) {
  4560. return idx_cond;
  4561. }
  4562. /** Reset information about pushed index conditions */
  4563. virtual void cancel_pushed_idx_cond() {
  4564. pushed_idx_cond = NULL;
  4565. pushed_idx_cond_keyno = MAX_KEY;
  4566. in_range_check_pushed_down = false;
  4567. }
  4568. /**
  4569. Reports number of tables included in pushed join which this
  4570. handler instance is part of. ==0 -> Not pushed
  4571. */
  4572. virtual uint number_of_pushed_joins() const { return 0; }
  4573. /**
  4574. If this handler instance is part of a pushed join sequence
  4575. returned TABLE instance being root of the pushed query?
  4576. */
  4577. virtual const TABLE *member_of_pushed_join() const { return NULL; }
  4578. /**
  4579. If this handler instance is a child in a pushed join sequence
  4580. returned TABLE instance being my parent?
  4581. */
  4582. virtual const TABLE *parent_of_pushed_join() const { return NULL; }
  4583. int ha_index_read_pushed(uchar *buf, const uchar *key,
  4584. key_part_map keypart_map);
  4585. int ha_index_next_pushed(uchar *buf);
  4586. protected:
  4587. virtual int index_read_pushed(uchar *, const uchar *, key_part_map) {
  4588. return HA_ERR_WRONG_COMMAND;
  4589. }
  4590. virtual int index_next_pushed(uchar *) { return HA_ERR_WRONG_COMMAND; }
  4591. public:
  4592. /**
  4593. Part of old, deprecated in-place ALTER API.
  4594. */
  4595. virtual bool check_if_incompatible_data(
  4596. HA_CREATE_INFO *create_info MY_ATTRIBUTE((unused)),
  4597. uint table_changes MY_ATTRIBUTE((unused))) {
  4598. return COMPATIBLE_DATA_NO;
  4599. }
  4600. /* On-line/in-place/instant ALTER TABLE interface. */
  4601. /*
  4602. Here is an outline of on-line/in-place ALTER TABLE execution through
  4603. this interface.
  4604. Phase 1 : Initialization
  4605. ========================
  4606. During this phase we determine which algorithm should be used
  4607. for execution of ALTER TABLE and what level concurrency it will
  4608. require.
  4609. *) This phase starts by opening the table and preparing description
  4610. of the new version of the table.
  4611. *) Then we check if it is impossible even in theory to carry out
  4612. this ALTER TABLE using the in-place/instant algorithm. For example,
  4613. because we need to change storage engine or the user has explicitly
  4614. requested usage of the "copy" algorithm.
  4615. *) If in-place/instant ALTER TABLE is theoretically possible, we continue
  4616. by compiling differences between old and new versions of the table
  4617. in the form of HA_ALTER_FLAGS bitmap. We also build a few
  4618. auxiliary structures describing requested changes and store
  4619. all these data in the Alter_inplace_info object.
  4620. *) Then the handler::check_if_supported_inplace_alter() method is called
  4621. in order to find if the storage engine can carry out changes requested
  4622. by this ALTER TABLE using the in-place or instant algorithm.
  4623. To determine this, the engine can rely on data in HA_ALTER_FLAGS/
  4624. Alter_inplace_info passed to it as well as on its own checks.
  4625. If the in-place algorithm can be used for this ALTER TABLE, the level
  4626. of required concurrency for its execution is also returned.
  4627. If any errors occur during the handler call, ALTER TABLE is aborted
  4628. and no further handler functions are called.
  4629. Note that in cases when there is difference between in-place and
  4630. instant algorithm and user explicitly asked for usage of in-place
  4631. algorithm storage engine MUST return one of values corresponding
  4632. to in-place algorithm and not HA_ALTER_INPLACE_INSTANT from this
  4633. method.
  4634. *) Locking requirements of the in-place algorithm are compared to any
  4635. concurrency requirements specified by user. If there is a conflict
  4636. between them, we either switch to the copy algorithm or emit an error.
  4637. Phase 2 : Execution
  4638. ===================
  4639. In this phase the operations are executed.
  4640. *) As the first step, we acquire a lock corresponding to the concurrency
  4641. level which was returned by handler::check_if_supported_inplace_alter()
  4642. and requested by the user. This lock is held for most of the
  4643. duration of in-place ALTER (if HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE
  4644. or HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE were returned we acquire an
  4645. exclusive lock for duration of the next step only).
  4646. For HA_ALTER_INPLACE_INSTANT we keep shared upgradable metadata lock
  4647. which was acquired at table open time.
  4648. *) After that we call handler::ha_prepare_inplace_alter_table() to give the
  4649. storage engine a chance to update its internal structures with a higher
  4650. lock level than the one that will be used for the main step of algorithm.
  4651. After that we downgrade the lock if it is necessary.
  4652. This step should be no-op for instant algorithm.
  4653. *) After that, the main step of this phase and algorithm is executed.
  4654. We call the handler::ha_inplace_alter_table() method, which carries out
  4655. the changes requested by ALTER TABLE but does not makes them visible to
  4656. other connections yet.
  4657. This step should be no-op for instant algorithm as well.
  4658. *) We ensure that no other connection uses the table by upgrading our
  4659. lock on it to exclusive.
  4660. *) a) If the previous step succeeds,
  4661. handler::ha_commit_inplace_alter_table() is called to allow the storage
  4662. engine to do any final updates to its structures, to make all earlier
  4663. changes durable and visible to other connections.
  4664. For instant algorithm this is the step during which SE changes are done.
  4665. Engines that support atomic DDL only prepare for the commit during this
  4666. step but do not finalize it. Real commit happens later when the whole
  4667. statement is committed. Also in some situations statement might be rolled
  4668. back after call to commit_inplace_alter_table() for such storage engines.
  4669. In the latter special case SE might require call to
  4670. handlerton::dict_cache_reset() in order to invalidate its internal table
  4671. definition cache after rollback.
  4672. b) If we have failed to upgrade lock or any errors have occurred during
  4673. the handler functions calls (including commit), we call
  4674. handler::ha_commit_inplace_alter_table() to rollback all changes which
  4675. were done during previous steps.
  4676. All the above calls to SE are provided with dd::Table objects describing old
  4677. and new version of table being altered. Engines which support atomic DDL are
  4678. allowed to adjust object corresponding to the new version. During phase 3
  4679. these changes are saved to the data-dictionary.
  4680. Phase 3 : Final
  4681. ===============
  4682. In this phase we:
  4683. a) For engines which don't support atomic DDL:
  4684. *) Update the SQL-layer data-dictionary by replacing description of old
  4685. version of the table with its new version. This change is immediately
  4686. committed.
  4687. *) Inform the storage engine about this change by calling the
  4688. handler::ha_notify_table_changed() method.
  4689. *) Process the RENAME clause by calling handler::ha_rename_table() and
  4690. updating the data-dictionary accordingly. Again this change is
  4691. immediately committed.
  4692. *) Destroy the Alter_inplace_info and handler_ctx objects.
  4693. b) For engines which support atomic DDL:
  4694. *) Update the SQL-layer data-dictionary by replacing description of old
  4695. version of the table with its new version.
  4696. *) Process the RENAME clause by calling handler::ha_rename_table() and
  4697. updating the data-dictionary accordingly.
  4698. *) Commit the statement/transaction.
  4699. *) Finalize atomic DDL operation by calling handlerton::post_ddl() hook
  4700. for the storage engine.
  4701. *) Additionally inform the storage engine about completion of ALTER TABLE
  4702. for the table by calling the handler::ha_notify_table_changed()
  4703. method.
  4704. *) Destroy the Alter_inplace_info and handler_ctx objects.
  4705. */
  4706. /**
  4707. Check if a storage engine supports a particular alter table in-place
  4708. @param altered_table TABLE object for new version of table.
  4709. @param ha_alter_info Structure describing changes to be done
  4710. by ALTER TABLE and holding data used
  4711. during in-place alter.
  4712. @retval HA_ALTER_ERROR Unexpected error.
  4713. @retval HA_ALTER_INPLACE_NOT_SUPPORTED Not supported, must use copy.
  4714. @retval HA_ALTER_INPLACE_EXCLUSIVE_LOCK Supported, but requires X lock.
  4715. @retval HA_ALTER_INPLACE_SHARED_LOCK_AFTER_PREPARE
  4716. Supported, but requires SNW lock
  4717. during main phase. Prepare phase
  4718. requires X lock.
  4719. @retval HA_ALTER_INPLACE_SHARED_LOCK Supported, but requires SNW lock.
  4720. @retval HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE
  4721. Supported, concurrent
  4722. reads/writes allowed. However, prepare phase requires X lock.
  4723. @retval HA_ALTER_INPLACE_NO_LOCK Supported, concurrent
  4724. reads/writes allowed.
  4725. @retval HA_ALTER_INPLACE_INSTANT Instant algorithm is supported.
  4726. Prepare and main phases are
  4727. no-op. Changes happen during
  4728. commit phase and it should be
  4729. "instant". We keep SU lock,
  4730. allowing concurrent reads and
  4731. writes during no-op phases and
  4732. upgrade it to X lock before
  4733. commit phase.
  4734. @note The default implementation uses the old in-place ALTER API
  4735. to determine if the storage engine supports in-place ALTER or not.
  4736. @note In cases when there is difference between in-place and instant
  4737. algorithm and explicit ALGORITHM=INPLACE clause was provided SE MUST
  4738. return one of values corresponding to in-place algorithm and not
  4739. HA_ALTER_INPLACE_INSTANT from this method.
  4740. @note Called without holding thr_lock.c lock.
  4741. */
  4742. virtual enum_alter_inplace_result check_if_supported_inplace_alter(
  4743. TABLE *altered_table, Alter_inplace_info *ha_alter_info);
  4744. /**
  4745. Public functions wrapping the actual handler call.
  4746. @see prepare_inplace_alter_table()
  4747. */
  4748. bool ha_prepare_inplace_alter_table(TABLE *altered_table,
  4749. Alter_inplace_info *ha_alter_info,
  4750. const dd::Table *old_table_def,
  4751. dd::Table *new_table_def);
  4752. /**
  4753. Public function wrapping the actual handler call.
  4754. @see inplace_alter_table()
  4755. */
  4756. bool ha_inplace_alter_table(TABLE *altered_table,
  4757. Alter_inplace_info *ha_alter_info,
  4758. const dd::Table *old_table_def,
  4759. dd::Table *new_table_def) {
  4760. return inplace_alter_table(altered_table, ha_alter_info, old_table_def,
  4761. new_table_def);
  4762. }
  4763. /**
  4764. Public function wrapping the actual handler call.
  4765. Allows us to enforce asserts regardless of handler implementation.
  4766. @see commit_inplace_alter_table()
  4767. */
  4768. bool ha_commit_inplace_alter_table(TABLE *altered_table,
  4769. Alter_inplace_info *ha_alter_info,
  4770. bool commit,
  4771. const dd::Table *old_table_def,
  4772. dd::Table *new_table_def);
  4773. /**
  4774. Public function wrapping the actual handler call.
  4775. @see notify_table_changed()
  4776. */
  4777. void ha_notify_table_changed(Alter_inplace_info *ha_alter_info) {
  4778. notify_table_changed(ha_alter_info);
  4779. }
  4780. protected:
  4781. /**
  4782. Allows the storage engine to update internal structures with concurrent
  4783. writes blocked. If check_if_supported_inplace_alter() returns
  4784. HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE or
  4785. HA_ALTER_INPLACE_SHARED_AFTER_PREPARE, this function is called with
  4786. exclusive lock otherwise the same level of locking as for
  4787. inplace_alter_table() will be used.
  4788. @note Should be no-op for instant algorithm.
  4789. @note Storage engines are responsible for reporting any errors by
  4790. calling my_error()/print_error()
  4791. @note If this function reports error, commit_inplace_alter_table()
  4792. will be called with commit= false.
  4793. @note For partitioning, failing to prepare one partition, means that
  4794. commit_inplace_alter_table() will be called to roll back changes for
  4795. all partitions. This means that commit_inplace_alter_table() might be
  4796. called without prepare_inplace_alter_table() having been called first
  4797. for a given partition.
  4798. @param altered_table TABLE object for new version of table.
  4799. @param ha_alter_info Structure describing changes to be done
  4800. by ALTER TABLE and holding data used
  4801. during in-place alter.
  4802. @param old_table_def dd::Table object describing old version of
  4803. the table.
  4804. @param new_table_def dd::Table object for the new version of the
  4805. table. Can be adjusted by this call if SE
  4806. supports atomic DDL. These changes to the
  4807. table definition will be persisted in the
  4808. data-dictionary at statement commit time.
  4809. @retval true Error
  4810. @retval false Success
  4811. */
  4812. virtual bool prepare_inplace_alter_table(
  4813. TABLE *altered_table MY_ATTRIBUTE((unused)),
  4814. Alter_inplace_info *ha_alter_info MY_ATTRIBUTE((unused)),
  4815. const dd::Table *old_table_def MY_ATTRIBUTE((unused)),
  4816. dd::Table *new_table_def MY_ATTRIBUTE((unused))) {
  4817. return false;
  4818. }
  4819. /**
  4820. Alter the table structure in-place with operations specified using
  4821. HA_ALTER_FLAGS and Alter_inplace_info. The level of concurrency allowed
  4822. during this operation depends on the return value from
  4823. check_if_supported_inplace_alter().
  4824. @note Should be no-op for instant algorithm.
  4825. @note Storage engines are responsible for reporting any errors by
  4826. calling my_error()/print_error()
  4827. @note If this function reports error, commit_inplace_alter_table()
  4828. will be called with commit= false.
  4829. @param altered_table TABLE object for new version of table.
  4830. @param ha_alter_info Structure describing changes to be done
  4831. by ALTER TABLE and holding data used
  4832. during in-place alter.
  4833. @param old_table_def dd::Table object describing old version of
  4834. the table.
  4835. @param new_table_def dd::Table object for the new version of the
  4836. table. Can be adjusted by this call if SE
  4837. supports atomic DDL. These changes to the
  4838. table definition will be persisted in the
  4839. data-dictionary at statement commit time.
  4840. @retval true Error
  4841. @retval false Success
  4842. */
  4843. virtual bool inplace_alter_table(
  4844. TABLE *altered_table MY_ATTRIBUTE((unused)),
  4845. Alter_inplace_info *ha_alter_info MY_ATTRIBUTE((unused)),
  4846. const dd::Table *old_table_def MY_ATTRIBUTE((unused)),
  4847. dd::Table *new_table_def MY_ATTRIBUTE((unused))) {
  4848. return false;
  4849. }
  4850. /**
  4851. Commit or rollback the changes made during prepare_inplace_alter_table()
  4852. and inplace_alter_table() inside the storage engine.
  4853. Note that in case of rollback the allowed level of concurrency during
  4854. this operation will be the same as for inplace_alter_table() and thus
  4855. might be higher than during prepare_inplace_alter_table(). (For example,
  4856. concurrent writes were blocked during prepare, but might not be during
  4857. rollback).
  4858. @note This is the place where SE changes happen for instant algorithm.
  4859. @note For storage engines supporting atomic DDL this method should only
  4860. prepare for the commit but do not finalize it. Real commit should happen
  4861. later when the whole statement is committed. Also in some situations
  4862. statement might be rolled back after call to commit_inplace_alter_table()
  4863. for such storage engines. In the latter special case SE might require call
  4864. to handlerton::dict_cache_reset() in order to invalidate its internal
  4865. table definition cache after rollback.
  4866. @note Storage engines are responsible for reporting any errors by
  4867. calling my_error()/print_error()
  4868. @note If this function with commit= true reports error, it will be called
  4869. again with commit= false.
  4870. @note In case of partitioning, this function might be called for rollback
  4871. without prepare_inplace_alter_table() having been called first.
  4872. Also partitioned tables sets ha_alter_info->group_commit_ctx to a NULL
  4873. terminated array of the partitions handlers and if all of them are
  4874. committed as one, then group_commit_ctx should be set to NULL to indicate
  4875. to the partitioning handler that all partitions handlers are committed.
  4876. @see prepare_inplace_alter_table().
  4877. @param altered_table TABLE object for new version of table.
  4878. @param ha_alter_info Structure describing changes to be done
  4879. by ALTER TABLE and holding data used
  4880. during in-place alter.
  4881. @param commit True => Commit, False => Rollback.
  4882. @param old_table_def dd::Table object describing old version of
  4883. the table.
  4884. @param new_table_def dd::Table object for the new version of the
  4885. table. Can be adjusted by this call if SE
  4886. supports atomic DDL. These changes to the
  4887. table definition will be persisted in the
  4888. data-dictionary at statement commit time.
  4889. @retval true Error
  4890. @retval false Success
  4891. */
  4892. virtual bool commit_inplace_alter_table(
  4893. TABLE *altered_table MY_ATTRIBUTE((unused)),
  4894. Alter_inplace_info *ha_alter_info MY_ATTRIBUTE((unused)),
  4895. bool commit MY_ATTRIBUTE((unused)),
  4896. const dd::Table *old_table_def MY_ATTRIBUTE((unused)),
  4897. dd::Table *new_table_def MY_ATTRIBUTE((unused))) {
  4898. /* Nothing to commit/rollback, mark all handlers committed! */
  4899. ha_alter_info->group_commit_ctx = NULL;
  4900. return false;
  4901. }
  4902. /**
  4903. Notify the storage engine that the table definition has been updated.
  4904. @param ha_alter_info Structure describing changes done by
  4905. ALTER TABLE and holding data used
  4906. during in-place alter.
  4907. @note No errors are allowed during notify_table_changed().
  4908. @note For storage engines supporting atomic DDL this method is invoked
  4909. after the whole ALTER TABLE is completed and committed.
  4910. Particularly this means that for ALTER TABLE statements with RENAME
  4911. clause TABLE/handler object used for invoking this method will be
  4912. associated with new table name. If storage engine needs to know
  4913. the old schema and table name in this method for some reason it
  4914. has to use ha_alter_info object to figure it out.
  4915. */
  4916. virtual void notify_table_changed(
  4917. Alter_inplace_info *ha_alter_info MY_ATTRIBUTE((unused))) {}
  4918. public:
  4919. /* End of On-line/in-place ALTER TABLE interface. */
  4920. /**
  4921. use_hidden_primary_key() is called in case of an update/delete when
  4922. (table_flags() and HA_PRIMARY_KEY_REQUIRED_FOR_DELETE) is defined
  4923. but we don't have a primary key
  4924. */
  4925. virtual void use_hidden_primary_key();
  4926. protected:
  4927. /* Service methods for use by storage engines. */
  4928. void ha_statistic_increment(ulonglong System_status_var::*offset) const;
  4929. THD *ha_thd(void) const;
  4930. /**
  4931. Acquire the instrumented table information from a table share.
  4932. @param share a table share
  4933. @return an instrumented table share, or NULL.
  4934. */
  4935. PSI_table_share *ha_table_share_psi(const TABLE_SHARE *share) const;
  4936. /**
  4937. Default rename_table() and delete_table() rename/delete files with a
  4938. given name and extensions from handlerton::file_extensions.
  4939. These methods can be overridden, but their default implementation
  4940. provide useful functionality.
  4941. @param [in] from Path for the old table name.
  4942. @param [in] to Path for the new table name.
  4943. @param [in] from_table_def Old version of definition for table
  4944. being renamed (i.e. prior to rename).
  4945. @param [in,out] to_table_def New version of definition for table
  4946. being renamed. Storage engines which
  4947. support atomic DDL (i.e. having
  4948. HTON_SUPPORTS_ATOMIC_DDL flag set)
  4949. are allowed to adjust this object.
  4950. @retval >0 Error.
  4951. @retval 0 Success.
  4952. */
  4953. virtual int rename_table(const char *from, const char *to,
  4954. const dd::Table *from_table_def,
  4955. dd::Table *to_table_def);
  4956. /**
  4957. Delete a table.
  4958. Used to delete a table. By the time delete_table() has been called all
  4959. opened references to this table will have been closed (and your globally
  4960. shared references released. The variable name will just be the name of
  4961. the table. You will need to remove any files you have created at this
  4962. point. Called for base as well as temporary tables.
  4963. @param name Full path of table name.
  4964. @param table_def dd::Table describing table being deleted
  4965. (can be NULL for temporary tables created
  4966. by optimizer).
  4967. @retval >0 Error.
  4968. @retval 0 Success.
  4969. */
  4970. virtual int delete_table(const char *name, const dd::Table *table_def);
  4971. private:
  4972. /* Private helpers */
  4973. void mark_trx_read_write();
  4974. /*
  4975. Low-level primitives for storage engines. These should be
  4976. overridden by the storage engine class. To call these methods, use
  4977. the corresponding 'ha_*' method above.
  4978. */
  4979. virtual int open(const char *name, int mode, uint test_if_locked,
  4980. const dd::Table *table_def) = 0;
  4981. virtual int close(void) = 0;
  4982. virtual int index_init(uint idx, bool sorted MY_ATTRIBUTE((unused))) {
  4983. active_index = idx;
  4984. return 0;
  4985. }
  4986. virtual int index_end() {
  4987. active_index = MAX_KEY;
  4988. return 0;
  4989. }
  4990. /**
  4991. rnd_init() can be called two times without rnd_end() in between
  4992. (it only makes sense if scan=1).
  4993. then the second call should prepare for the new table scan (e.g
  4994. if rnd_init allocates the cursor, second call should position it
  4995. to the start of the table, no need to deallocate and allocate it again
  4996. */
  4997. virtual int rnd_init(bool scan) = 0;
  4998. virtual int rnd_end() { return 0; }
  4999. /**
  5000. Write a row.
  5001. write_row() inserts a row. buf is a byte array of data, normally
  5002. record[0].
  5003. You can use the field information to extract the data from the native byte
  5004. array type.
  5005. Example of this would be:
  5006. for (Field **field=table->field ; *field ; field++)
  5007. {
  5008. ...
  5009. }
  5010. @param buf Buffer to write from.
  5011. @return Operation status.
  5012. @retval 0 Success.
  5013. @retval != 0 Error code.
  5014. */
  5015. virtual int write_row(uchar *buf MY_ATTRIBUTE((unused))) {
  5016. return HA_ERR_WRONG_COMMAND;
  5017. }
  5018. /**
  5019. Update a single row.
  5020. Note: If HA_ERR_FOUND_DUPP_KEY is returned, the handler must read
  5021. all columns of the row so MySQL can create an error message. If
  5022. the columns required for the error message are not read, the error
  5023. message will contain garbage.
  5024. */
  5025. virtual int update_row(const uchar *old_data MY_ATTRIBUTE((unused)),
  5026. uchar *new_data MY_ATTRIBUTE((unused))) {
  5027. return HA_ERR_WRONG_COMMAND;
  5028. }
  5029. virtual int delete_row(const uchar *buf MY_ATTRIBUTE((unused))) {
  5030. return HA_ERR_WRONG_COMMAND;
  5031. }
  5032. /**
  5033. Reset state of file to after 'open'.
  5034. This function is called after every statement for all tables used
  5035. by that statement.
  5036. */
  5037. virtual int reset() { return 0; }
  5038. virtual Table_flags table_flags(void) const = 0;
  5039. /**
  5040. Is not invoked for non-transactional temporary tables.
  5041. Tells the storage engine that we intend to read or write data
  5042. from the table. This call is prefixed with a call to handler::store_lock()
  5043. and is invoked only for those handler instances that stored the lock.
  5044. Calls to @c rnd_init / @c index_init are prefixed with this call. When table
  5045. IO is complete, we call @code external_lock(F_UNLCK) @endcode.
  5046. A storage engine writer should expect that each call to
  5047. @code ::external_lock(F_[RD|WR]LOCK @endcode is followed by a call to
  5048. @code ::external_lock(F_UNLCK) @endcode. If it is not, it is a bug in MySQL.
  5049. The name and signature originate from the first implementation
  5050. in MyISAM, which would call @c fcntl to set/clear an advisory
  5051. lock on the data file in this method.
  5052. Originally this method was used to set locks on file level to enable
  5053. several MySQL Servers to work on the same data. For transactional
  5054. engines it has been "abused" to also mean start and end of statements
  5055. to enable proper rollback of statements and transactions. When LOCK
  5056. TABLES has been issued the start_stmt method takes over the role of
  5057. indicating start of statement but in this case there is no end of
  5058. statement indicator(?).
  5059. Called from lock.cc by lock_external() and unlock_external(). Also called
  5060. from sql_table.cc by copy_data_between_tables().
  5061. @param thd the current thread
  5062. @param lock_type F_RDLCK, F_WRLCK, F_UNLCK
  5063. @return non-0 in case of failure, 0 in case of success.
  5064. When lock_type is F_UNLCK, the return value is ignored.
  5065. */
  5066. virtual int external_lock(THD *thd MY_ATTRIBUTE((unused)),
  5067. int lock_type MY_ATTRIBUTE((unused))) {
  5068. return 0;
  5069. }
  5070. virtual void release_auto_increment() { return; }
  5071. /** admin commands - called from mysql_admin_table */
  5072. virtual int check_for_upgrade(HA_CHECK_OPT *) { return 0; }
  5073. virtual int check(THD *, HA_CHECK_OPT *) { return HA_ADMIN_NOT_IMPLEMENTED; }
  5074. /**
  5075. In this method check_opt can be modified
  5076. to specify CHECK option to use to call check()
  5077. upon the table.
  5078. */
  5079. virtual int repair(THD *, HA_CHECK_OPT *) {
  5080. DBUG_ASSERT(!(ha_table_flags() & HA_CAN_REPAIR));
  5081. return HA_ADMIN_NOT_IMPLEMENTED;
  5082. }
  5083. virtual void start_bulk_insert(ha_rows) {}
  5084. virtual int end_bulk_insert() { return 0; }
  5085. /**
  5086. Does this handler want to get a Record_buffer for multi-row reads
  5087. via the ha_set_record_buffer() function? And if so, what is the
  5088. maximum number of records to allocate space for in the buffer?
  5089. Storage engines that support using a Record_buffer should override
  5090. this function and return true for scans that could benefit from a
  5091. buffer.
  5092. @param[out] max_rows gets set to the maximum number of records to
  5093. allocate space for in the buffer if the function
  5094. returns true
  5095. @retval true if the handler would like a Record_buffer
  5096. @retval false if the handler does not want a Record_buffer
  5097. */
  5098. virtual bool is_record_buffer_wanted(ha_rows *const max_rows) const {
  5099. *max_rows = 0;
  5100. return false;
  5101. }
  5102. // Set se_private_id and se_private_data during upgrade
  5103. virtual bool upgrade_table(THD *thd MY_ATTRIBUTE((unused)),
  5104. const char *dbname MY_ATTRIBUTE((unused)),
  5105. const char *table_name MY_ATTRIBUTE((unused)),
  5106. dd::Table *dd_table MY_ATTRIBUTE((unused))) {
  5107. return false;
  5108. }
  5109. virtual int sample_init();
  5110. virtual int sample_next(uchar *buf);
  5111. virtual int sample_end();
  5112. /**
  5113. * Prepares secondary engine for loading a table.
  5114. *
  5115. * @param table Table opened in primary storage engine. Its read_set tells
  5116. * which columns to load.
  5117. *
  5118. * @return 0 if success, error code otherwise.
  5119. */
  5120. virtual int prepare_load_table(const TABLE &table MY_ATTRIBUTE((unused))) {
  5121. DBUG_ASSERT(false);
  5122. return HA_ERR_WRONG_COMMAND;
  5123. }
  5124. /**
  5125. * Loads a table into its defined secondary storage engine.
  5126. *
  5127. * @param table Table opened in primary storage engine. Its read_set tells
  5128. * which columns to load.
  5129. *
  5130. * @return 0 if success, error code otherwise.
  5131. */
  5132. virtual int load_table(const TABLE &table MY_ATTRIBUTE((unused))) {
  5133. /* purecov: begin inspected */
  5134. DBUG_ASSERT(false);
  5135. return HA_ERR_WRONG_COMMAND;
  5136. /* purecov: end */
  5137. }
  5138. /**
  5139. * Unloads a table from its defined secondary storage engine.
  5140. *
  5141. * @param db_name Database name.
  5142. * @param table_name Table name.
  5143. * @param error_if_not_loaded If true, then errors will be reported by this
  5144. * function. If false, no errors will be reported
  5145. * (silently fail). This case of false is useful
  5146. * during DROP TABLE where a failure to unload
  5147. * should not prevent dropping the whole table.
  5148. * @return 0 if success, error code otherwise.
  5149. */
  5150. virtual int unload_table(const char *db_name MY_ATTRIBUTE((unused)),
  5151. const char *table_name MY_ATTRIBUTE((unused)),
  5152. bool error_if_not_loaded MY_ATTRIBUTE((unused))) {
  5153. /* purecov: begin inspected */
  5154. DBUG_ASSERT(false);
  5155. return HA_ERR_WRONG_COMMAND;
  5156. /* purecov: end */
  5157. }
  5158. protected:
  5159. virtual int index_read(uchar *buf MY_ATTRIBUTE((unused)),
  5160. const uchar *key MY_ATTRIBUTE((unused)),
  5161. uint key_len MY_ATTRIBUTE((unused)),
  5162. enum ha_rkey_function find_flag
  5163. MY_ATTRIBUTE((unused))) {
  5164. return HA_ERR_WRONG_COMMAND;
  5165. }
  5166. virtual int index_read_last(uchar *buf MY_ATTRIBUTE((unused)),
  5167. const uchar *key MY_ATTRIBUTE((unused)),
  5168. uint key_len MY_ATTRIBUTE((unused))) {
  5169. set_my_errno(HA_ERR_WRONG_COMMAND);
  5170. return HA_ERR_WRONG_COMMAND;
  5171. }
  5172. public:
  5173. /**
  5174. This method is similar to update_row, however the handler doesn't need
  5175. to execute the updates at this point in time. The handler can be certain
  5176. that another call to bulk_update_row will occur OR a call to
  5177. exec_bulk_update before the set of updates in this query is concluded.
  5178. Note: If HA_ERR_FOUND_DUPP_KEY is returned, the handler must read
  5179. all columns of the row so MySQL can create an error message. If
  5180. the columns required for the error message are not read, the error
  5181. message will contain garbage.
  5182. @param old_data Old record
  5183. @param new_data New record
  5184. @param dup_key_found Number of duplicate keys found
  5185. */
  5186. virtual int bulk_update_row(const uchar *old_data MY_ATTRIBUTE((unused)),
  5187. uchar *new_data MY_ATTRIBUTE((unused)),
  5188. uint *dup_key_found MY_ATTRIBUTE((unused))) {
  5189. DBUG_ASSERT(false);
  5190. return HA_ERR_WRONG_COMMAND;
  5191. }
  5192. /**
  5193. Delete all rows in a table.
  5194. This is called both for cases of truncate and for cases where the
  5195. optimizer realizes that all rows will be removed as a result of an
  5196. SQL statement.
  5197. If the handler don't support this, then this function will
  5198. return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one
  5199. by one.
  5200. */
  5201. virtual int delete_all_rows() {
  5202. set_my_errno(HA_ERR_WRONG_COMMAND);
  5203. return HA_ERR_WRONG_COMMAND;
  5204. }
  5205. /**
  5206. Quickly remove all rows from a table.
  5207. @param[in,out] table_def dd::Table object for table being truncated.
  5208. @remark This method is responsible for implementing MySQL's TRUNCATE
  5209. TABLE statement, which is a DDL operation. As such, a engine
  5210. can bypass certain integrity checks and in some cases avoid
  5211. fine-grained locking (e.g. row locks) which would normally be
  5212. required for a DELETE statement.
  5213. @remark Typically, truncate is not used if it can result in integrity
  5214. violation. For example, truncate is not used when a foreign
  5215. key references the table, but it might be used if foreign key
  5216. checks are disabled.
  5217. @remark Engine is responsible for resetting the auto-increment counter.
  5218. @remark The table is locked in exclusive mode. All open TABLE/handler
  5219. instances except the one which is used for truncate() call
  5220. are closed.
  5221. @note It is assumed that transactional storage engines implementing
  5222. this method can revert its effects if transaction is rolled
  5223. back (e.g. because we failed to write statement to the binary
  5224. log).
  5225. @note Changes to dd::Table object done by this method will be saved
  5226. to data-dictionary only if storage engine supports atomic DDL
  5227. (i.e. has HTON_SUPPORTS_ATOMIC_DDL flag set).
  5228. */
  5229. virtual int truncate(dd::Table *table_def MY_ATTRIBUTE((unused))) {
  5230. return HA_ERR_WRONG_COMMAND;
  5231. }
  5232. virtual int optimize(THD *, HA_CHECK_OPT *) {
  5233. return HA_ADMIN_NOT_IMPLEMENTED;
  5234. }
  5235. virtual int analyze(THD *, HA_CHECK_OPT *) {
  5236. return HA_ADMIN_NOT_IMPLEMENTED;
  5237. }
  5238. /**
  5239. @brief Check and repair the table if necessary.
  5240. @param thd Thread object
  5241. @retval true Error/Not supported
  5242. @retval false Success
  5243. @note Called if open_table_from_share fails and is_crashed().
  5244. */
  5245. virtual bool check_and_repair(THD *thd MY_ATTRIBUTE((unused))) {
  5246. return true;
  5247. }
  5248. /**
  5249. Disable indexes for a while.
  5250. @param mode Mode.
  5251. @retval 0 Success.
  5252. @retval != 0 Error.
  5253. */
  5254. virtual int disable_indexes(uint mode MY_ATTRIBUTE((unused))) {
  5255. return HA_ERR_WRONG_COMMAND;
  5256. }
  5257. /**
  5258. Enable indexes again.
  5259. @param mode Mode.
  5260. @retval 0 Success.
  5261. @retval != 0 Error.
  5262. */
  5263. virtual int enable_indexes(uint mode MY_ATTRIBUTE((unused))) {
  5264. return HA_ERR_WRONG_COMMAND;
  5265. }
  5266. /**
  5267. Discard or import tablespace.
  5268. @param [in] discard Indicates whether this is discard operation.
  5269. @param [in,out] table_def dd::Table object describing the table
  5270. in which tablespace needs to be discarded
  5271. or imported. This object can be adjusted by
  5272. storage engine if it supports atomic DDL
  5273. (i.e. has HTON_SUPPORTS_ATOMIC_DDL flag set).
  5274. These changes will be persisted in the
  5275. data-dictionary.
  5276. @retval 0 Success.
  5277. @retval != 0 Error.
  5278. */
  5279. virtual int discard_or_import_tablespace(bool discard MY_ATTRIBUTE((unused)),
  5280. dd::Table *table_def
  5281. MY_ATTRIBUTE((unused))) {
  5282. set_my_errno(HA_ERR_WRONG_COMMAND);
  5283. return HA_ERR_WRONG_COMMAND;
  5284. }
  5285. virtual void drop_table(const char *name);
  5286. /**
  5287. Create table (implementation).
  5288. @param [in] name Table name.
  5289. @param [in] form TABLE object describing the table to be
  5290. created.
  5291. @param [in] info HA_CREATE_INFO describing table.
  5292. @param [in,out] table_def dd::Table object describing the table
  5293. to be created. This object can be
  5294. adjusted by storage engine if it
  5295. supports atomic DDL (i.e. has
  5296. HTON_SUPPORTS_ATOMIC_DDL flag set).
  5297. These changes will be persisted in the
  5298. data-dictionary. Can be NULL for
  5299. temporary tables created by optimizer.
  5300. @retval 0 Success.
  5301. @retval non-0 Error.
  5302. */
  5303. virtual int create(const char *name, TABLE *form, HA_CREATE_INFO *info,
  5304. dd::Table *table_def) = 0;
  5305. virtual bool get_se_private_data(dd::Table *dd_table MY_ATTRIBUTE((unused)),
  5306. bool reset MY_ATTRIBUTE((unused))) {
  5307. return false;
  5308. }
  5309. /**
  5310. Adjust definition of table to be created by adding implicit columns
  5311. and indexes necessary for the storage engine.
  5312. @param [in] create_info HA_CREATE_INFO describing the table.
  5313. @param [in] create_list List of columns in the table.
  5314. @param [in] key_info Array of KEY objects describing table
  5315. indexes.
  5316. @param [in] key_count Number of indexes in the table.
  5317. @param [in,out] table_obj dd::Table object describing the table
  5318. to be created. Implicit columns and
  5319. indexes are to be added to this object.
  5320. Adjusted table description will be
  5321. saved into the data-dictionary.
  5322. @retval 0 Success.
  5323. @retval non-0 Error.
  5324. */
  5325. virtual int get_extra_columns_and_keys(
  5326. const HA_CREATE_INFO *create_info MY_ATTRIBUTE((unused)),
  5327. const List<Create_field> *create_list MY_ATTRIBUTE((unused)),
  5328. const KEY *key_info MY_ATTRIBUTE((unused)),
  5329. uint key_count MY_ATTRIBUTE((unused)),
  5330. dd::Table *table_obj MY_ATTRIBUTE((unused))) {
  5331. return 0;
  5332. }
  5333. virtual bool set_ha_share_ref(Handler_share **arg_ha_share) {
  5334. ha_share = arg_ha_share;
  5335. return false;
  5336. }
  5337. int get_lock_type() const { return m_lock_type; }
  5338. /**
  5339. Callback function that will be called by my_prepare_gcolumn_template
  5340. once the table has been opened.
  5341. */
  5342. typedef void (*my_gcolumn_template_callback_t)(const TABLE *, void *);
  5343. static bool my_prepare_gcolumn_template(THD *thd, const char *db_name,
  5344. const char *table_name,
  5345. my_gcolumn_template_callback_t myc,
  5346. void *ib_table);
  5347. static bool my_eval_gcolumn_expr_with_open(THD *thd, const char *db_name,
  5348. const char *table_name,
  5349. const MY_BITMAP *const fields,
  5350. uchar *record,
  5351. const char **mv_data_ptr,
  5352. ulong *mv_length);
  5353. /**
  5354. Callback for computing generated column values.
  5355. Storage engines that need to have virtual column values for a row
  5356. can use this function to get the values computed. The storage
  5357. engine must have filled in the values for the base columns that
  5358. the virtual columns depend on.
  5359. @param thd thread handle
  5360. @param table table object
  5361. @param fields bitmap of field index of evaluated generated
  5362. column
  5363. @param[in,out] record buff of base columns generated column depends.
  5364. After calling this function, it will be
  5365. used to return the value of the generated
  5366. columns.
  5367. @param[out] mv_data_ptr When given (not null) and the field
  5368. needs to be calculated is a typed array field, it
  5369. will contain pointer to field's calculated value.
  5370. @param[out] mv_length Length of the data above
  5371. @retval true in case of error
  5372. @retval false on success
  5373. */
  5374. static bool my_eval_gcolumn_expr(THD *thd, TABLE *table,
  5375. const MY_BITMAP *const fields, uchar *record,
  5376. const char **mv_data_ptr, ulong *mv_length);
  5377. /* This must be implemented if the handlerton's partition_flags() is set. */
  5378. virtual Partition_handler *get_partition_handler() { return NULL; }
  5379. /**
  5380. Set se_private_id and se_private_data during upgrade
  5381. @param thd Pointer of THD
  5382. @param dbname Database name
  5383. @param table_name Table name
  5384. @param dd_table dd::Table for the table
  5385. @param table_arg TABLE object for the table.
  5386. @return Operation status
  5387. @retval false Success
  5388. @retval true Error
  5389. */
  5390. bool ha_upgrade_table(THD *thd, const char *dbname, const char *table_name,
  5391. dd::Table *dd_table, TABLE *table_arg);
  5392. /**
  5393. Store a pointer to the handler of the primary table that
  5394. corresponds to the secondary table in this handler.
  5395. */
  5396. void ha_set_primary_handler(handler *primary_handler);
  5397. /**
  5398. Get a pointer to a handler for the table in the primary storage
  5399. engine, if this handler is for a table in a secondary storage
  5400. engine.
  5401. */
  5402. handler *ha_get_primary_handler() const { return m_primary_handler; }
  5403. /**
  5404. Return max limits for a single set of multi-valued keys
  5405. @param[out] num_keys number of keys to store
  5406. @param[out] keys_length total length of keys, bytes
  5407. */
  5408. void ha_mv_key_capacity(uint *num_keys, size_t *keys_length) const {
  5409. return mv_key_capacity(num_keys, keys_length);
  5410. }
  5411. private:
  5412. /**
  5413. Engine-specific function for ha_can_store_mv_keys().
  5414. Dummy function. SE's overloaded method is used instead.
  5415. */
  5416. /* purecov: begin inspected */
  5417. virtual void mv_key_capacity(uint *num_keys, size_t *keys_length) const {
  5418. *num_keys = 0;
  5419. *keys_length = 0;
  5420. }
  5421. /* purecov: end */
  5422. /**
  5423. Filter duplicate records when multi-valued index is used for retrieval
  5424. @returns
  5425. true duplicate, such row id was already seen
  5426. false row id is seen for the first time
  5427. */
  5428. bool filter_dup_records();
  5429. protected:
  5430. Handler_share *get_ha_share_ptr();
  5431. void set_ha_share_ptr(Handler_share *arg_ha_share);
  5432. void lock_shared_ha_data();
  5433. void unlock_shared_ha_data();
  5434. friend class DsMrr_impl;
  5435. };
  5436. /**
  5437. Function identifies any old data type present in table.
  5438. This function was handler::check_old_types().
  5439. Function is not part of SE API. It is now converted to
  5440. auxiliary standalone function.
  5441. @param[in] table TABLE object
  5442. @param[in] check_temporal_upgrade Check if temporal upgrade is needed
  5443. @retval 0 ON SUCCESS
  5444. @retval error code ON FAILURE
  5445. */
  5446. int check_table_for_old_types(const TABLE *table, bool check_temporal_upgrade);
  5447. /*
  5448. A Disk-Sweep MRR interface implementation
  5449. This implementation makes range (and, in the future, 'ref') scans to read
  5450. table rows in disk sweeps.
  5451. Currently it is used by MyISAM and InnoDB. Potentially it can be used with
  5452. any table handler that has non-clustered indexes and on-disk rows.
  5453. */
  5454. class DsMrr_impl {
  5455. public:
  5456. DsMrr_impl(handler *owner) : h(owner), table(NULL), h2(NULL) {}
  5457. ~DsMrr_impl() {
  5458. /*
  5459. If ha_reset() has not been called then the h2 dialog might still
  5460. exist. This must be closed and deleted (this is the case for
  5461. internally created temporary tables).
  5462. */
  5463. if (h2) reset();
  5464. DBUG_ASSERT(h2 == NULL);
  5465. }
  5466. private:
  5467. /*
  5468. The "owner" handler object (the one that calls dsmrr_XXX functions.
  5469. It is used to retrieve full table rows by calling rnd_pos().
  5470. */
  5471. handler *const h;
  5472. TABLE *table; /* Always equal to h->table */
  5473. /* Secondary handler object. It is used for scanning the index */
  5474. handler *h2;
  5475. /* Buffer to store rowids, or (rowid, range_id) pairs */
  5476. uchar *rowids_buf;
  5477. uchar *rowids_buf_cur; /* Current position when reading/writing */
  5478. uchar *rowids_buf_last; /* When reading: end of used buffer space */
  5479. uchar *rowids_buf_end; /* End of the buffer */
  5480. bool dsmrr_eof; /* true <=> We have reached EOF when reading index tuples */
  5481. /* true <=> need range association, buffer holds {rowid, range_id} pairs */
  5482. bool is_mrr_assoc;
  5483. bool use_default_impl; /* true <=> shortcut all calls to default MRR impl */
  5484. public:
  5485. /**
  5486. Initialize the DsMrr_impl object.
  5487. This object is used for both doing default MRR scans and DS-MRR scans.
  5488. This function just initializes the object. To do a DS-MRR scan,
  5489. this must also be initialized by calling dsmrr_init().
  5490. @param table_arg pointer to the TABLE that owns the handler
  5491. */
  5492. void init(TABLE *table_arg) {
  5493. DBUG_ASSERT(table_arg != NULL);
  5494. table = table_arg;
  5495. }
  5496. int dsmrr_init(RANGE_SEQ_IF *seq_funcs, void *seq_init_param, uint n_ranges,
  5497. uint mode, HANDLER_BUFFER *buf);
  5498. void dsmrr_close();
  5499. /**
  5500. Resets the DS-MRR object to the state it had after being intialized.
  5501. If there is an open scan then this will be closed.
  5502. This function should be called by handler::ha_reset() which is called
  5503. when a statement is completed in order to make the handler object ready
  5504. for re-use by a different statement.
  5505. */
  5506. void reset();
  5507. int dsmrr_fill_buffer();
  5508. int dsmrr_next(char **range_info);
  5509. ha_rows dsmrr_info(uint keyno, uint n_ranges, uint keys, uint *bufsz,
  5510. uint *flags, Cost_estimate *cost);
  5511. ha_rows dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq, void *seq_init_param,
  5512. uint n_ranges, uint *bufsz, uint *flags,
  5513. Cost_estimate *cost);
  5514. private:
  5515. bool choose_mrr_impl(uint keyno, ha_rows rows, uint *flags, uint *bufsz,
  5516. Cost_estimate *cost);
  5517. bool get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags,
  5518. uint *buffer_size, Cost_estimate *cost);
  5519. };
  5520. /* lookups */
  5521. handlerton *ha_default_handlerton(THD *thd);
  5522. handlerton *ha_default_temp_handlerton(THD *thd);
  5523. /**
  5524. Resolve handlerton plugin by name, without checking for "DEFAULT" or
  5525. HTON_NOT_USER_SELECTABLE.
  5526. @param thd Thread context.
  5527. @param name Plugin name.
  5528. @return plugin or NULL if not found.
  5529. */
  5530. plugin_ref ha_resolve_by_name_raw(THD *thd, const LEX_CSTRING &name);
  5531. plugin_ref ha_resolve_by_name(THD *thd, const LEX_CSTRING *name,
  5532. bool is_temp_table);
  5533. plugin_ref ha_lock_engine(THD *thd, const handlerton *hton);
  5534. handlerton *ha_resolve_by_legacy_type(THD *thd, enum legacy_db_type db_type);
  5535. handler *get_new_handler(TABLE_SHARE *share, bool partitioned, MEM_ROOT *alloc,
  5536. handlerton *db_type);
  5537. handlerton *ha_checktype(THD *thd, enum legacy_db_type database_type,
  5538. bool no_substitute, bool report_error);
  5539. static inline enum legacy_db_type ha_legacy_type(const handlerton *db_type) {
  5540. return (db_type == NULL) ? DB_TYPE_UNKNOWN : db_type->db_type;
  5541. }
  5542. const char *ha_resolve_storage_engine_name(const handlerton *db_type);
  5543. static inline bool ha_check_storage_engine_flag(const handlerton *db_type,
  5544. uint32 flag) {
  5545. return db_type == nullptr ? false : (db_type->flags & flag);
  5546. }
  5547. static inline bool ha_storage_engine_is_enabled(const handlerton *db_type) {
  5548. return (db_type && db_type->create) ? (db_type->state == SHOW_OPTION_YES)
  5549. : false;
  5550. }
  5551. /* basic stuff */
  5552. int ha_init_errors(void);
  5553. int ha_init(void);
  5554. void ha_end();
  5555. int ha_initialize_handlerton(st_plugin_int *plugin);
  5556. int ha_finalize_handlerton(st_plugin_int *plugin);
  5557. TYPELIB *ha_known_exts();
  5558. int ha_panic(enum ha_panic_function flag);
  5559. void ha_close_connection(THD *thd);
  5560. void ha_kill_connection(THD *thd);
  5561. /** Invoke handlerton::pre_dd_shutdown() on every storage engine plugin. */
  5562. void ha_pre_dd_shutdown(void);
  5563. /**
  5564. Flush the log(s) of storage engine(s).
  5565. @param binlog_group_flush true if we got invoked by binlog group
  5566. commit during flush stage, false in other cases.
  5567. @retval false Succeed
  5568. @retval true Error
  5569. */
  5570. bool ha_flush_logs(bool binlog_group_flush = false);
  5571. void ha_drop_database(char *path);
  5572. int ha_create_table(THD *thd, const char *path, const char *db,
  5573. const char *table_name, HA_CREATE_INFO *create_info,
  5574. bool update_create_info, bool is_temp_table,
  5575. dd::Table *table_def);
  5576. int ha_delete_table(THD *thd, handlerton *db_type, const char *path,
  5577. const char *db, const char *alias,
  5578. const dd::Table *table_def, bool generate_warning);
  5579. bool ha_check_reserved_db_name(const char *name);
  5580. /* statistics and info */
  5581. bool ha_show_status(THD *thd, handlerton *db_type, enum ha_stat_type stat);
  5582. typedef bool Log_func(THD *, TABLE *, bool, const uchar *, const uchar *);
  5583. int binlog_log_row(TABLE *table, const uchar *before_record,
  5584. const uchar *after_record, Log_func *log_func);
  5585. /* discovery */
  5586. int ha_create_table_from_engine(THD *thd, const char *db, const char *name);
  5587. bool ha_check_if_table_exists(THD *thd, const char *db, const char *name,
  5588. bool *exists);
  5589. int ha_find_files(THD *thd, const char *db, const char *path, const char *wild,
  5590. bool dir, List<LEX_STRING> *files);
  5591. int ha_table_exists_in_engine(THD *thd, const char *db, const char *name);
  5592. bool ha_check_if_supported_system_table(handlerton *hton, const char *db,
  5593. const char *table_name);
  5594. bool ha_rm_tmp_tables(THD *thd, List<LEX_STRING> *files);
  5595. bool default_rm_tmp_tables(handlerton *hton, THD *thd, List<LEX_STRING> *files);
  5596. /* key cache */
  5597. extern "C" int ha_init_key_cache(const char *name, KEY_CACHE *key_cache);
  5598. int ha_resize_key_cache(KEY_CACHE *key_cache);
  5599. int ha_change_key_cache(KEY_CACHE *old_key_cache, KEY_CACHE *new_key_cache);
  5600. /* transactions: interface to handlerton functions */
  5601. int ha_start_consistent_snapshot(THD *thd);
  5602. int ha_commit_trans(THD *thd, bool all, bool ignore_global_read_lock = false);
  5603. int ha_commit_attachable(THD *thd);
  5604. int ha_rollback_trans(THD *thd, bool all);
  5605. int ha_prepare(THD *thd);
  5606. /**
  5607. recover() step of xa.
  5608. @note
  5609. there are three modes of operation:
  5610. - automatic recover after a crash
  5611. in this case commit_list != 0, tc_heuristic_recover==TC_HEURISTIC_NOT_USED
  5612. all xids from commit_list are committed, others are rolled back
  5613. - manual (heuristic) recover
  5614. in this case commit_list==0, tc_heuristic_recover != TC_HEURISTIC_NOT_USED
  5615. DBA has explicitly specified that all prepared transactions should
  5616. be committed (or rolled back).
  5617. - no recovery (MySQL did not detect a crash)
  5618. in this case commit_list==0, tc_heuristic_recover == TC_HEURISTIC_NOT_USED
  5619. there should be no prepared transactions in this case.
  5620. */
  5621. typedef ulonglong my_xid; // this line is the same as in log_event.h
  5622. int ha_recover(const memroot_unordered_set<my_xid> *commit_list);
  5623. /**
  5624. Perform SE-specific cleanup after recovery of transactions.
  5625. @note SE supporting atomic DDL can use this method to perform
  5626. post-DDL actions for DDL statements which were committed
  5627. or rolled back during recovery stage.
  5628. */
  5629. void ha_post_recover();
  5630. /*
  5631. transactions: interface to low-level handlerton functions. These are
  5632. intended to be used by the transaction coordinators to
  5633. commit/prepare/rollback transactions in the engines.
  5634. */
  5635. int ha_commit_low(THD *thd, bool all, bool run_after_commit = true);
  5636. int ha_prepare_low(THD *thd, bool all);
  5637. int ha_rollback_low(THD *thd, bool all);
  5638. /* transactions: these functions never call handlerton functions directly */
  5639. int ha_enable_transaction(THD *thd, bool on);
  5640. /* savepoints */
  5641. int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv);
  5642. bool ha_rollback_to_savepoint_can_release_mdl(THD *thd);
  5643. int ha_savepoint(THD *thd, SAVEPOINT *sv);
  5644. int ha_release_savepoint(THD *thd, SAVEPOINT *sv);
  5645. /* Build pushed joins in handlers implementing this feature */
  5646. int ha_make_pushed_joins(THD *thd, const AQP::Join_plan *plan);
  5647. /* these are called by storage engines */
  5648. void trans_register_ha(THD *thd, bool all, handlerton *ht,
  5649. const ulonglong *trxid);
  5650. int ha_reset_logs(THD *thd);
  5651. int ha_binlog_index_purge_file(THD *thd, const char *file);
  5652. void ha_reset_slave(THD *thd);
  5653. void ha_binlog_log_query(THD *thd, handlerton *db_type,
  5654. enum_binlog_command binlog_command, const char *query,
  5655. size_t query_length, const char *db,
  5656. const char *table_name);
  5657. void ha_binlog_wait(THD *thd);
  5658. /* It is required by basic binlog features on both MySQL server and libmysqld */
  5659. int ha_binlog_end(THD *thd);
  5660. const char *get_canonical_filename(handler *file, const char *path,
  5661. char *tmp_path);
  5662. const char *table_case_name(const HA_CREATE_INFO *info, const char *name);
  5663. void print_keydup_error(TABLE *table, KEY *key, const char *msg, myf errflag);
  5664. void print_keydup_error(TABLE *table, KEY *key, myf errflag);
  5665. void ha_set_normalized_disabled_se_str(const std::string &disabled_se_str);
  5666. bool ha_is_storage_engine_disabled(handlerton *se_engine);
  5667. bool ha_notify_exclusive_mdl(THD *thd, const MDL_key *mdl_key,
  5668. ha_notification_type notification_type,
  5669. bool *victimized);
  5670. bool ha_notify_alter_table(THD *thd, const MDL_key *mdl_key,
  5671. ha_notification_type notification_type);
  5672. int commit_owned_gtids(THD *thd, bool all, bool *need_clear_ptr);
  5673. int commit_owned_gtid_by_partial_command(THD *thd);
  5674. bool set_tx_isolation(THD *thd, enum_tx_isolation tx_isolation, bool one_shot);
  5675. /** Generate a string representation of an `ha_rkey_function` enum value.
  5676. * @param[in] r value to turn into string
  5677. * @return a string, e.g. "HA_READ_KEY_EXACT" if r == HA_READ_KEY_EXACT */
  5678. const char *ha_rkey_function_to_str(enum ha_rkey_function r);
  5679. /** Generate a human readable string that describes a table structure. For
  5680. * example:
  5681. * t1 (`c1` char(60) not null, `c2` char(60), hash unique index0(`c1`, `c2`))
  5682. * @param[in] table_name name of the table to be described
  5683. * @param[in] mysql_table table structure
  5684. * @return a string similar to a CREATE TABLE statement */
  5685. std::string table_definition(const char *table_name, const TABLE *mysql_table);
  5686. #ifndef DBUG_OFF
  5687. /** Generate a human readable string that describes the contents of a row. The
  5688. * row must be in the same format as provided to handler::write_row(). For
  5689. * example, given this table structure:
  5690. * t1 (`pk` int(11) not null,
  5691. * `col_int_key` int(11),
  5692. * `col_varchar_key` varchar(1),
  5693. * hash unique index0(`pk`, `col_int_key`, `col_varchar_key`))
  5694. *
  5695. * something like this will be generated (without the new lines):
  5696. *
  5697. * len=16,
  5698. * raw=..........c.....,
  5699. * hex=f9 1d 00 00 00 08 00 00 00 01 63 a5 a5 a5 a5 a5,
  5700. * human=(`pk`=29, `col_int_key`=8, `col_varchar_key`=c)
  5701. *
  5702. * @param[in] mysql_row row to dump
  5703. * @param[in] mysql_table table to which the row belongs, for querying metadata
  5704. * @return textual dump of the row */
  5705. std::string row_to_string(const uchar *mysql_row, TABLE *mysql_table);
  5706. /** Generate a human readable string that describes indexed cells that are given
  5707. * to handler::index_read() as input. The generated string is similar to the one
  5708. * generated by row_to_string(), but only contains the cells covered by the
  5709. * given index.
  5710. * @param[in] indexed_cells raw buffer in handler::index_read() input format
  5711. * @param[in] indexed_cells_len length of indexed_cells in bytes
  5712. * @param[in] mysql_index the index that covers the cells, for querying metadata
  5713. * @return textual dump of the cells */
  5714. std::string indexed_cells_to_string(const uchar *indexed_cells,
  5715. uint indexed_cells_len,
  5716. const KEY &mysql_index);
  5717. #endif /* DBUG_OFF */
  5718. /*
  5719. This class is used by INFORMATION_SCHEMA.FILES to read SE specific
  5720. tablespace dynamic metadata. Some member like m_type and id, is not
  5721. really dynamic, but as this information is not stored in data dictionary
  5722. in a generic format and still is SE specific Some member like m_type and
  5723. id, is not really dynamic, but as this information is not stored in data
  5724. dictionary in a generic format and still needs SE specific decision, we
  5725. are requesting the same from SE.
  5726. */
  5727. class ha_tablespace_statistics {
  5728. public:
  5729. ha_tablespace_statistics()
  5730. : m_id(0),
  5731. m_logfile_group_number(-1),
  5732. m_free_extents(0),
  5733. m_total_extents(0),
  5734. m_extent_size(0),
  5735. m_initial_size(0),
  5736. m_maximum_size(0),
  5737. m_autoextend_size(0),
  5738. m_version(-1),
  5739. m_data_free(0) {}
  5740. ulonglong m_id;
  5741. dd::String_type m_type;
  5742. dd::String_type m_logfile_group_name; // NDB only
  5743. ulonglong m_logfile_group_number; // NDB only
  5744. ulonglong m_free_extents;
  5745. ulonglong m_total_extents;
  5746. ulonglong m_extent_size;
  5747. ulonglong m_initial_size;
  5748. ulonglong m_maximum_size;
  5749. ulonglong m_autoextend_size;
  5750. ulonglong m_version; // NDB only
  5751. dd::String_type m_row_format; // NDB only
  5752. ulonglong m_data_free; // InnoDB
  5753. dd::String_type m_status;
  5754. dd::String_type m_extra; // NDB only
  5755. };
  5756. #endif /* HANDLER_INCLUDED */