1.73 MonetDB Assembly Language (MAL)

The target language for a query compiler is the MonetDB Assembly Language (MAL). It was designed to ease code generation and fast interpretation by the server. The compiler produces algebraic query plans, which are turned into physical execution plans by the MAL optimizers.

The output of a compiler is either an ascii representation of the MAL program or the compiler is tightly coupled with the server to save parsing and communication overhead.

A snippet of the MAL code produced by the SQL compiler for the query select count(*) from tables is shown below. It illustrates a sequences of relational operations against a table column and producing a partial result.

     	...
         _22:bat[:oid,:oid]  := sql.bind_dbat("tmp","_tables",0);
         _23 := bat.reverse(_22);
         _24 := algebra.kdifference(_20,_23);
         _25 := algebra.markT(_24,0:oid);
         _26 := bat.reverse(_25);
         _27 := algebra.join(_26,_20);
         _28 := bat.setWriteMode(_19);
         bat.append(_28,_27,true);
     	...

MAL supports the full breadth of computational paradigms deployed in a database setting. It is language framework where the execution semantics is determined by the code transformations and the final engine choosen.

The design and implementation of MAL takes the functionality offered previously a significant step further. To name a few:

  • All instructions are strongly typed before being executed.
  • It supports polymorphic functions. They act as templates that produce strongly typed instantiations when needed.
  • Function style expressions where each assignment instruction can receive multiple target results; it forms a point in the dataflow graph.
  • It supports co-routines (Factories) to build streaming applications.
  • Properties are associated with the program code for ease of optimization and scheduling.
  • It can be readily extended with user defined types and function modules.