MonetDB 结构体分析

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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
typedef struct MALBLK {
  str binding;       /*related C-funtion*/
  str help;         /*supportive commentary*/
  struct MALBLK *alternative;
  int vtop;            /*next free slot*/
  int vsize;           /*size of variable arena*/
  VarRecord **var;   /*Variable table*/
  int stop;        /*next free slot;*/
  int ssize;         /*byte size of arena*/
  InstrPtr *stmt        /*Instruction Location*/
  int ptop;            /*next free slot*/
  int psize;           /*byte size of arena*/
  MalProp *prgs;     /*property table*/
  int errors;      /*left over errors*/
  int typefixed;       /*no undetermined instruction*/
  int flowfixed;       /*all flow instructions are fixed*/
  ProfPtr profiler;
  struct MALBLK *history;  /*of optimizer actions*/
  short keephistory;        /*do we need the history at all*/
  short dotfile;            /*send dot file to stethoscope*/
  str  marker;           /*history points are marked for backtracking*/
  int maxarg;               /*keep track on the maximal arguments used*/
  ptr replica               /*for the replicator tests*/
  short recycle;          /*execution subjuect to recycler control*/
  long recid;               /*ID given by recycler optimizer*/
  long legid;
  short trap;               /*call debugger when called*/
}*MalBlkPtr, MalBlkRecord;

InstrRecord is used as storing many fields of a instruction.

InstrPtr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
typedef struct {
  bit token;     /*instruction type*/
  bit barrier;   /*flow of control modifier takes;BARRIER,LEAVE,REDO,EXIT,CATCH,RAISE*/
  bit typechk;   /*type check status*/
  bit gc;            /*garbage control flags*/
  bit polymorphic;   /*complex type analysis*/
  bit varargs;   /*variable number of arguments*/
  bit recycle;   /*lower than 0 or index into recycle cache*/
  int jump;     /*controlflow program counter*/
  MALfcn fcn;        /*resolved function address*/
  struct MALBLK *blk; /*resolved MAL function address*/
  str modname;   /*module context*/
  str fcnname;    /*function name*/
  int argc,retc,maxarg; /*total and result argument count*/
  int argv[];   /*at least a few entries*/
}*InstrPtr, InstrRecord;

VARRECORD is used as storing variables.

VARRECORD
1
2
3
4
5
6
7
8
9
10
typedef struct VARRECORD {
  char *name;            /*argname or lexical value repr*/
  malType type;      /*internal type signature*/
  int flags;            /*see below, reserve some space*/
  int tmpindex;     /*temporary variable*/
  ValRecord value;
  int eoflife;      /*pc index when it should be garbage collected*/
  int propc, maxprop; /*proc count and max number of properties*/
  int prps[];           /*property array*/
}*VarPtr, VarRecord;

ValRecord structure is used as describing the details of one variable.

ValPtr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 typedef struct {
  union {           /*storage is first in the record*/
      int ival;
      oid oval;
      short shval;
      byte btval;
      word wval;
      float fval;
      ptr pval;
      struct BAT *Bval; /*this field is only used by mel*/
      bat bval;
      str sval;
      dbl dval;
      long lval;
  }val;
  int len, vtype;
}*ValPtr,ValRecord;

BAT is described as Binary Association Table.It is one of most important structure in MonetDB.

BAT
1
2
3
4
5
6
7
8
9
10
11
12
    typedef struct BAT{
      /*static bat properties*/
      bat batCacheid;        /*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: "BAT"

MALSTK is used as MonetDB Assembly Language Execution Stack, like the C language stack.

MalStack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 typedef int (*DFhook)(void *, void *, void *, void *);
 typdedef struct MALSTk{
  int stksize;
  int stktop;
  int stkbot;            /*the first variable to be initialized*/
  int stkdepth;      /*to protect against runtime stack overflow*/
  int calldepth;        /*to prectect against runtime stack overflow*/
  short keeplive;       /*do not garbage collect when set*/
  short garbageCollect; /*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.
*/
  DFhook admit;
  DFhook wrapup;
  MT_Lock stklock; /*used for parallel processing*/
  /*
     *It is handy to administer the timing in the stack frame
  * for use in profiling and recylcing instructions.
*/
  #ifdef HAVE_TIME
          struct tms timer; /*timing information*/
  #endif
  struct timeval clock; /*seconds + microsecs since epoch*/
  lng clk;      /* micro seconds*/
  char cmd;     /*debugger communication*/
  struct MALSTK *up;  /*stack trace list*/
  struct MALSTK *blk; /*associated definition*/
  ValRecord stk[1];
}MalStack, *MalStkPtr;

CLIENT structure represents the details of processing the requests of one connection.

CLIENT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
typedef struct CLIENT{
  int idex;     /*entry in mal_client*/
  oid user;  /*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
*/
  str scenario;  /*scenario management references */
  str oldscenrio;
  void *state[7], *oldstate[7];
  MALfcn phase[7], oldphase[7];
  short stage;  /*keep track of the phase being ran*/
  char itrace;  /*trace execution using interactive mdb*/
                      /*if set to 'S' it will put the process to sleep*/
  short debugOptimizer,debugScheduler;
  /**For program debugging we need information on the timer and memory
     *usage patterns*/
  short flags;  /*resource tracing flags*/
  long timer;       /*trace time in usec*/
  long bigfoot; /*maxium virtual memory use*/
  long vmfoot;  /*virtual memory use*/
  long memory;  /*memory claimed for keeping BATs*/
  BUN  cnt;  /*bat count*/
  ......
  ClientInput *bak; /*used for recursive script and string execution*/
  stream *fdout;    /*streams from and to user*/
  ....
  Modedule nspace; /*private scope resolution list*/
  Symbol curprg;  /*focus of parser*/
  Symbol backup;      /*save parsing context*/
  MalStkPtr glb;  /*global variable stack*/

}*Client,ClientRec;

SYMDEF structure link MALBLK together.

SYMDEF
1
2
3
4
5
6
7
    typedef struct SYMDEF{
      struct SYMDEF *peer; /*where to look next*/
      struct SYMDEF *skip; /*skip to next different symbol*/
      str name;
      int kind;
      struct MALBLK *def;  /*the details of the MAL fcn*/
  }*Symbol,SymRecord;

Comments