The query execution plan produced by the SQL compiler can be made visible
using the EXPLAIN
statement modifier.
It produces a MAL (MonetDB Assembly Language) program,
the internal language understood by the MonetDB interpreter.
The example below illustrates what you can expect when a simple
SELECT count(*) FROM sys.tables
query starts with the EXPLAIN modifier.
Tip The details of this MAL code are better understood when you have read the MAL reference.
sql>SELECT count(*) FROM sys.tables;
+------+
| %2 |
+======+
| 143 |
+------+
1 tuple
sql>EXPLAIN SELECT count(*) FROM sys.tables;
+------------------------------------------------------------------------------------------+
| mal |
+==========================================================================================+
| function user.main():void; |
| X_1:void := querylog.define("explain select count(*) from sys.tables;":str, "default |
: _pipe":str, 25:int); :
| barrier X_99:bit := language.dataflow(); |
| X_4:int := sql.mvc(); |
| X_5:bat[:oid] := sql.tid(X_4:int, "sys":str, "_tables":str); |
| X_22:lng := aggr.count(X_5:bat[:oid]); |
| X_23:bat[:oid] := sql.tid(X_4:int, "tmp":str, "_tables":str); |
| X_34:lng := aggr.count(X_23:bat[:oid]); |
| X_35:bat[:lng] := bat.single(X_22:lng); |
| X_36:bat[:lng] := mat.packIncrement(X_35:bat[:lng], 2:int); |
| X_37:bat[:lng] := bat.single(X_34:lng); |
| X_38:bat[:lng] := mat.packIncrement(X_36:bat[:lng], X_37:bat[:lng]); |
| X_39:lng := aggr.sum(X_38:bat[:lng]); |
| exit X_99:bit; |
| X_41:int := sql.resultSet(".%2":str, "%2":str, "bigint":str, 63:int, 0:int, 7:int, X |
: _39:lng); :
| end user.main; |
| # ... |
| # 30 optimizers 535 usecs |
+------------------------------------------------------------------------------------------+
47 tuples