MonetDB belongs to the class of database management systems designed primarilly for datawarehouse evironment.It has many components to construct.According to my ability I only focus myself on the kernel structure.
MALBLK is used as the MonetDB Assembly language Block which store the instructions which will be executed.
MALBLK
12345678910111213141516171819202122232425262728
typedefstructMALBLK{strbinding;/*related C-funtion*/strhelp;/*supportive commentary*/structMALBLK*alternative;intvtop;/*next free slot*/intvsize;/*size of variable arena*/VarRecord**var;/*Variable table*/intstop;/*next free slot;*/intssize;/*byte size of arena*/InstrPtr*stmt/*Instruction Location*/intptop;/*next free slot*/intpsize;/*byte size of arena*/MalProp*prgs;/*property table*/interrors;/*left over errors*/inttypefixed;/*no undetermined instruction*/intflowfixed;/*all flow instructions are fixed*/ProfPtrprofiler;structMALBLK*history;/*of optimizer actions*/shortkeephistory;/*do we need the history at all*/shortdotfile;/*send dot file to stethoscope*/strmarker;/*history points are marked for backtracking*/intmaxarg;/*keep track on the maximal arguments used*/ptrreplica/*for the replicator tests*/shortrecycle;/*execution subjuect to recycler control*/longrecid;/*ID given by recycler optimizer*/longlegid;shorttrap;/*call debugger when called*/}*MalBlkPtr,MalBlkRecord;
InstrRecord is used as storing many fields of a instruction.
InstrPtr
12345678910111213141516
typedefstruct{bittoken;/*instruction type*/bitbarrier;/*flow of control modifier takes;BARRIER,LEAVE,REDO,EXIT,CATCH,RAISE*/bittypechk;/*type check status*/bitgc;/*garbage control flags*/bitpolymorphic;/*complex type analysis*/bitvarargs;/*variable number of arguments*/bitrecycle;/*lower than 0 or index into recycle cache*/intjump;/*controlflow program counter*/MALfcnfcn;/*resolved function address*/structMALBLK*blk;/*resolved MAL function address*/strmodname;/*module context*/strfcnname;/*function name*/intargc,retc,maxarg;/*total and result argument count*/intargv[];/*at least a few entries*/}*InstrPtr,InstrRecord;
VARRECORD is used as storing variables.
VARRECORD
12345678910
typedefstructVARRECORD{char*name;/*argname or lexical value repr*/malTypetype;/*internal type signature*/intflags;/*see below, reserve some space*/inttmpindex;/*temporary variable*/ValRecordvalue;inteoflife;/*pc index when it should be garbage collected*/intpropc,maxprop;/*proc count and max number of properties*/intprps[];/*property array*/}*VarPtr,VarRecord;
ValRecord structure is used as describing the details of one variable.
ValPtr
1234567891011121314151617
typedefstruct{union{/*storage is first in the record*/intival;oidoval;shortshval;bytebtval;wordwval;floatfval;ptrpval;structBAT*Bval;/*this field is only used by mel*/batbval;strsval;dbldval;longlval;}val;intlen,vtype;}*ValPtr,ValRecord;
BAT is described as Binary Association Table.It is one of most important structure in MonetDB.
BAT
123456789101112
typedefstructBAT{/*static bat properties*/batbatCacheid;/*index into BBP*//*dynamic column properties*/COLrec*H;/*column info*/COLrec*T;/*column info*//*dynamic bat properties*/BATrec*P;/*cache and sort info*/BUNrec*U;/*cache and sort info*/}BAT;
This is the graph of BAT Structure:
MALSTK is used as MonetDB Assembly Language Execution Stack, like the C language stack.
typedefint(*DFhook)(void*,void*,void*,void*);typdedefstructMALSTk{intstksize;intstktop;intstkbot;/*the first variable to be initialized*/intstkdepth;/*to protect against runtime stack overflow*/intcalldepth;/*to prectect against runtime stack overflow*/shortkeeplive;/*do not garbage collect when set*/shortgarbageCollect;/*stack neeeds garbage collection*//* *Parallel processing is mostly driven by dataflow, but within this context *there may be different schemes to take instructions into execution. *The admission scheme (and wrapup) are the necessary scheduler hooks.*/DFhookadmit;DFhookwrapup;MT_Lockstklock;/*used for parallel processing*//* *It is handy to administer the timing in the stack frame * for use in profiling and recylcing instructions.*/#ifdefHAVE_TIMEstructtmstimer;/*timing information*/#endifstructtimevalclock;/*seconds + microsecs since epoch*/lngclk;/* micro seconds*/charcmd;/*debugger communication*/structMALSTK*up;/*stack trace list*/structMALSTK*blk;/*associated definition*/ValRecordstk[1];}MalStack,*MalStkPtr;
CLIENT structure represents the details of processing the requests of one connection.
typedefstructCLIENT{intidex;/*entry in mal_client*/oiduser;/*user id in the auth administration*//* *The actions for a client is separated into serveral stages: *parsing, strategic optimization,tactial optimization, and execution. *The routines to handle them are obtained once the scenario is choosen. *Each stage carries a state descriptor,but they share the IO state *description.A backup structure is provided to temporarily switch to *antoher secenario*/strscenario;/*scenario management references */stroldscenrio;void*state[7],*oldstate[7];MALfcnphase[7],oldphase[7];shortstage;/*keep track of the phase being ran*/charitrace;/*trace execution using interactive mdb*//*if set to 'S' it will put the process to sleep*/shortdebugOptimizer,debugScheduler;/**For program debugging we need information on the timer and memory *usage patterns*/shortflags;/*resource tracing flags*/longtimer;/*trace time in usec*/longbigfoot;/*maxium virtual memory use*/longvmfoot;/*virtual memory use*/longmemory;/*memory claimed for keeping BATs*/BUNcnt;/*bat count*/......ClientInput*bak;/*used for recursive script and string execution*/stream*fdout;/*streams from and to user*/....Modedulenspace;/*private scope resolution list*/Symbolcurprg;/*focus of parser*/Symbolbackup;/*save parsing context*/MalStkPtrglb;/*global variable stack*/}*Client,ClientRec;
SYMDEF structure link MALBLK together.
SYMDEF
1234567
typedefstructSYMDEF{structSYMDEF*peer;/*where to look next*/structSYMDEF*skip;/*skip to next different symbol*/strname;intkind;structMALBLK*def;/*the details of the MAL fcn*/}*Symbol,SymRecord;