当前位置: 首页 > 工具软件 > MonetDB > 使用案例 >

monetdb文档系列

金和雅
2023-12-01

8.39BinarAssociationTables

  • This module contains
    • commands and patterns to manage Binary Association Tables (BATs).
  • The relational operations
    • you can execute on BATs
    • have the form of a neat algebra,
    • described in algebra.mx

  • a database system needs more that just this algebra,
  • since often it is crucial to do table-updates (this would not be permitted in a strict algebra).

  • All commands needed for
    • BAT updates, property management,
    • basic I/O, persistence, and storage options
    • can be found in this module.

  • All parameters to the modules are passed by reference.
  • this means that string values are passed to the module layer as (str *) and we have to de-reference them before entering the gdk library.
  • (Actual a design error in gdk to differentiate passing int/str) This calls for knowledge on the underlying BAT types`s

MALReference

  • primary textual interface to the Monetdb kernel
    • is a simple, assembly-like language, called MAL.
  • The language reflects
    • the virtual machine architecture around the kernel libraries
    • has been designed for speed of parsing, ease of analysis, and ease of target compilation by query compilers.

也就是MAL这种汇编语言能够很好地利用Monetdb的内核呗!

  • a MAL program is considered a specification of intended computation and data flow behavior.

一个MAL就是计算和数据流的说明!specification的意思就是明细单的意思!

  • its actual evaluation depends on the execution paradigm choosen in a scenario.

  • The program blocks can both be interpreted

    • as ordered sequences of assembler instructions,
    • as a representation of a data-flow graph that should be resolved in a dataflow driven manner.
  • The language syntax uses a functional style definition of actions and mark those that affect the flow explicitly.

  • Flow of control keywords identify a point

    • to chance the interpretation paradigm and denote a synchronization point.

  • MAL is the target language for query compilers front-ends.
  • simple SQL generate a long sequence of MAL instructions.
  • They represent
    • both the administrative actions to ensure binding and transaction control,
    • the flow dependencies to produce the query result, and the steps needed to prepare the result set for delivery to the front-end.

  • Only when the algebraic structure is too limited (e.g. updates), or the database back-end lacks feasible builtin bulk operators, one has to rely on more detailed flow of control primitives.
  • But even in that case, the basic blocks to be processed by a MAL back-end are considered large, e.g. tens of simple bulk assignment instructions.

你说的是啥啊?
bulk operators是不是就相当于暗指出了我是一次一列的执行模式呢!

Literals

  • Literals in MAL follow the lexical conventions of the programming language C.
  • A default type is attached, e.g. the literal 1 is typed as an int value.
  • literal 3.14 is typed flt rather than dbl.

我呸,3.14在C语言里可是double啊!

  • A literal can be coerced to another type by tagging it with a type qualifier, provided a coercion operation is defined.
  • 1:lng marks the literal 1 as of type lng.
  • “1999-12-10”:date creates a date literal.

  • MonetDB comes with the hardwired types bit, bte, chr, wrd, sht, int, lng, oid, flt, dbl, and str.
  • The kernel code has been optimized to deal with these types efficiently,
    • without unnecessary function call overheads.
  • the system supports temporal types date, daytime, time, timestamp, timezone,
    • extensions to deal with IPv4 addresses and URLs using inet, url, UUID and JSON formatted strings.
  • An 128-integer arithmetic is compiled in on platforms that can support it.

本大爷:我还没见过哪个平台支持128位整数呢!

Variables

  • Variables are denoted by identifers and implicitly defined upon first assignment.
  • They take on a type through a type classifier
    • or
    • inherit it from the context in which they are first used, see MAL Type System.

  • Variables are organized into two classes: user defined and internal variables.
  • User defined variables start with a letter and temporary variables
    • 例如generated internally by optimizers, start with X_.
  • internal variables cannot be used in MAL programs directly,
    • but they may become visible in MAL program listings or during debugging.

  • MAL variables are internally represented by their position into the symbol table and runtime value stack.
  • Internal variable names are recognized by the parser and an error is produced
    • if their name does not align with the expected position in the symbol table.

Instructions

  • A MAL instruction has purposely a simple format.
  • It is syntactically represented by an assignment, where an expression (function call) delivers results to multiple target variables.
  • The assignment patterns recognized are illustrated below.
     (t1,..,t32) := module.fcn(a1,..,a32);
     t1 := module.fcn(a1,..,a32);
     t1 := v1 operator v2;
     t1 := literal;
     (t1,..,tn) := (a1,..,an);
  • Operators are grouped into user defined modules. Omission of the module name is interpreted as the user module.

  • Simple binary arithmetic operations are merely provided as a short-hand, e.g. the expression t:=2+2 is converted directly into t:= calc.+(2,2).

也就是简单的二元形式只是为了让你看起来方便,t:2+2实际上是t:= calc.+(2,2)

Target variables are optional. The compiler introduces internal variables to hold the result of the expression upon need. They won’t show up when you list the MAL program unless they are being used elsewhere.

Each instruction should fit on a single line, which makes it easy for the parser to recover upon encountering a syntax error. Comments start with a sharp ‘#’ and continues to the end of the line. They are retained in the internal code representation to ease debugging of compiler generated MAL programs.

The data structure to represent a MAL block is kept simple. It contains a sequence of MAL statements and a symbol table. The MAL instruction record is a code byte string overlaid with the instruction pattern, which contains references into the symbol tables and administrative data for the interpreter. This method leads to a large allocated block, which can be easily freed. Variable- and statement- block together describe the static part of a MAL procedure. It carries enough information to produce a listing and to aid symbolic debugging.

 类似资料: