Example tables:

relation: people, number_of_friends

people’s columns: name(varchar), age(int), faction(varchar)

number_of_friends columns: name(varchar), friends(int)

Example query:

1.SELECT * FROM people

arg(1,5) → 1 output 5 arg

batcalc.c

A.From sql query string to symbol tree

The sql query string were processed by the lexer to keywords and then rules defined inside the sql_parser.yfile which is a bison syntax, then converted to the symbol tree below:

MonetDB-example1-symbol.png

B. From symbol tree to sql_rel tree

Then, the symbol tree was converted to a sql_rel tree

First deal with table reference:

Call chain: sql_symbol2relationrel_semanticrel_selectsrel_subqueryrel_querytable_refrel_basetable

                          `rel_query`→ `rel_select_exp` → `rel_table_exp` → `rel_table_projections` → `_rel_projection`  →  `rel_base_projection` (Get column expressions from the sql_table struct’s column linked list)

rel_select_exprel_project

MonetDB rel tree example 1.png

C. From sql_rel tree to MAL statements

Call chain:

composed first stmt node(tid & bind) sql_relation2stmtoutput_rel_binsubrel_binrel2bin_projectsubrel_binrel2bin_basetable