MonetDB的SQL手册——Explain(执行计划)

来源:互联网 发布:js设置option选中 编辑:程序博客网 时间:2024/06/11 01:21

EXPLAIN SQL STMT

Explain语句

        

The intermediate code produced by the SQL compiler can be made visible using theexplain statement modifier.  It gives a detailed description of the actions taken to produce the answer.  The example below illustrates what you can expect when a simple query is prepended by theexplain  modifier.The output strongly depends on the optimizer pipeline. The details of this program are better understood when you have read the MAL  reference.

可以用Explain语句查看SQL编译器产生的中间代码。它给出了详细处理过程的动作描述。下面是展示的是一个例子。输出依赖于优化器的设置。

sql>select count(*) from tables;+--------+| count_ |+========+|     27 |+--------+sql>explain select count(*) from tables;+---------------------------------------------------------------------------------------------+| mal                                                                                         |+=============================================================================================+| function user.s3_2{autoCommit=true}():void;                                                 ||     _2 := sql.mvc();                                                                        || barrier _143 := language.dataflow();                                                        ||     _23:bat[:oid,:sht]  := sql.bind(_2,"sys","_tables","type",1);                           ||     _24 := algebra.thetauselect(_23,2:sht,"<");                                             ||     _25:bat[:oid,:oid]  := sql.bind_dbat(_2,"sys","_tables",1);                             ||     _27 := bat.reverse(_25);                                                                ||     _97 := algebra.kdifference(_24,_27);                                                    ||     _110 := algebra.markT(_97,5,4);                                                         ||     _117 := bat.reverse(_110);                                                              ||     _30:bat[:oid,:int]  := sql.bind(_2,"sys","_tables","id",1);                             ||     _142 := algebra.leftjoin(_117,_30);                                                     ||     _64:bat[:oid,:sht]  := sql.bind(_2,"sys","_tables","type",0,27@0,nil:oid);              ||     _72 := algebra.thetauselect(_64,2:sht,"<");                                             ||     _20:bat[:oid,:sht]  := sql.bind(_2,"sys","_tables","type",2);                           ||     _76 := algebra.kdifference(_72,_20);                                                    ||     _22 := algebra.thetauselect(_20,2:sht,"<");                                             ||     _80 := algebra.semijoin(_22,_64);                                                       ||     _85 := algebra.kunion(_76,_80);                                                         |...|     _13 := algebra.kdifference(_8,_12);                                                     ||     _14 := algebra.markT(_13,0@0);                                                          ||     _15 := bat.reverse(_14);                                                                ||     _16:bat[:oid,:int]  := sql.bind(_2,"tmp","_tables","id",0);                             ||     _18 := algebra.leftjoin(_15,_16);                                                       || exit _143;                                                                                  ||     _33:bat[:oid,:int]  := bat.new(nil:oid,nil:int);                                        || barrier _146 := language.dataflow();                                                        ||     _32 := mat.pack(_134,_136,_138,_140,_142);                                              ||     _36 := bat.append(_33,_32,true);                                                        ||     _38 := bat.append(_36,_18,true);                                                        ||     _39 := aggr.count(_38);                                                                 || exit _146;                                                                                  ||     sql.exportValue(1,".tables","L6","wrd",64,0,6,_39,"");                                  || end s3_2;                                                                                   |+---------------------------------------------------------------------------------------------+86 tuplessql>

The SQL compiler maintains a cache of compiled queries.  Each query is looked up in this cache based on an expression pattern match where the constants may take on different values.  If it doesn't exist, the query is converted into a code block and stored in the module user.s0.

The call to the cached function is included in a wrapper  function main, which is the only piece of code produced if the query is used more than  once.  The query cache disappears when the server is brought to a halt.

SQL编译陪存储在内存的cache中。每个查询检察cache,如果模式没有匹配,则查询传唤为代码存储在模行程 user.s0

 

 

     +----------------------------+     | function user.main():void; |     |     mdb.start();           |     |     user.s3_2();           |     |     mdb.stop();            |     | end main;                  |     +----------------------------+
原创粉丝点击