Changeset: ca85c8b85dc8 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ca85c8b85dc8 Modified Files: monetdb5/extras/Makefile.ag monetdb5/extras/mal_optimizer_template/91_opt_sql_append.mal monetdb5/extras/mal_optimizer_template/Makefile.ag monetdb5/extras/mal_optimizer_template/Tests/All monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.sql monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.err monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.out monetdb5/extras/mal_optimizer_template/opt_sql_append.mx monetdb5/modules/mal/Tests/inspect05.stable.out monetdb5/modules/mal/Tests/inspect05.stable.out.Windows Branch: default Log Message:
added MAL optimizer template as optimizer "show-case" This optimizer is mainly for demonstrating how to implement a MAL optimizer in priciple. Purely for that purpose, the optimizer's task is to recognize MAL code patterns like ... v3 := sql.append( ..., ..., ..., ..., v0 ); ... v5 := ... v0 ...; ... i.e., an sql.append() statement that is eventually followed by some other statement later on in the MAL program that uses the same v0 BAT as argument as the sql.append() statement does, and transform them into ... v1 := aggr.count( v0 ); v2 := algebra.slice( v0, 0, v1 ); v3 := sql.append( ..., ..., ..., ..., v2 ); ... v5 := ... v0 ...; ... i.e., handing a BAT view v2 of BAT v0 as argument to the sql.append() statement, rather than the original BAT v0. As a refinement, patterns like ... v3 := sql.append( ..., ..., ..., ..., v0 ); v4 := aggr.count( v0 ); ... v5 := ... v0 ...; ... are transformed into ... v4 := aggr.count( v0 ); v2 := algebra.slice( v0, 0, v4 ); v3 := sql.append( ..., ..., ..., ..., v2 ); ... v5 := ... v0 ...; ... diffs (truncated from 516 to 300 lines): diff --git a/monetdb5/extras/Makefile.ag b/monetdb5/extras/Makefile.ag --- a/monetdb5/extras/Makefile.ag +++ b/monetdb5/extras/Makefile.ag @@ -15,5 +15,5 @@ # Copyright August 2008-2012 MonetDB B.V. # All Rights Reserved. -SUBDIRS = compiler ENABLE_CRACKERS?crackers HAVE_RAPTOR?rdf HAVE_SPHINXCLIENT?sphinx +SUBDIRS = compiler ENABLE_CRACKERS?crackers HAVE_RAPTOR?rdf HAVE_SPHINXCLIENT?sphinx mal_optimizer_template diff --git a/monetdb5/extras/mal_optimizer_template/91_opt_sql_append.mal b/monetdb5/extras/mal_optimizer_template/91_opt_sql_append.mal new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/91_opt_sql_append.mal @@ -0,0 +1,21 @@ +# The contents of this file are subject to the MonetDB Public License +# Version 1.1 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.monetdb.org/Legal/MonetDBLicense +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the MonetDB Database System. +# +# The Initial Developer of the Original Code is CWI. +# Portions created by CWI are Copyright (C) 1997-July 2008 CWI. +# Copyright August 2008-2012 MonetDB B.V. +# All Rights Reserved. + +# This loads the opt_sql_append optimizer module +library opt_sql_append; +include opt_sql_append; + diff --git a/monetdb5/extras/mal_optimizer_template/Makefile.ag b/monetdb5/extras/mal_optimizer_template/Makefile.ag new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/Makefile.ag @@ -0,0 +1,52 @@ +# The contents of this file are subject to the MonetDB Public License +# Version 1.1 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.monetdb.org/Legal/MonetDBLicense +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the MonetDB Database System. +# +# The Initial Developer of the Original Code is CWI. +# Portions created by CWI are Copyright (C) 1997-July 2008 CWI. +# Copyright August 2008-2012 MonetDB B.V. +# All Rights Reserved. + +INCLUDES = \ + ../../optimizer \ + ../../mal \ + ../../../gdk \ + ../../../common/stream \ + ../../../common/options + +MTSAFE + +lib_opt_sql_append = { + MODULE + DIR = libdir/monetdb5 + SEP = _ + SOURCES = opt_sql_append.mx +#? LIBS = ../../tools/libmonetdb5 \ +#? ../../../gdk/libbat \ +#? ../../../common/stream/libstream \ +#? $(MALLOC_LIBS) +} + +headers_mal = { + HEADERS = mal + DIR = libdir/monetdb5 + SOURCES = opt_sql_append.mx +} + +headers_opt_sql_append_autoload = { + HEADERS = mal + DIR = libdir/monetdb5/autoload + SOURCES = 91_opt_sql_append.mal +} + +EXTRA_DIST = 91_opt_sql_append.mal + +EXTRA_DIST_DIR = Tests diff --git a/monetdb5/extras/mal_optimizer_template/Tests/All b/monetdb5/extras/mal_optimizer_template/Tests/All new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/Tests/All @@ -0,0 +1,1 @@ +opt_sql_append diff --git a/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.sql b/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.sql new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.sql @@ -0,0 +1,5 @@ +create table ttt (a int, b int, c int); +explain copy into ttt from '/tmp/xyz'; +set optimizer = substring(optimizer,0,length(optimizer)-length('garbageCollector')) || 'sql_append,garbageCollector'; +explain copy into ttt from '/tmp/xyz'; +drop table ttt; diff --git a/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.err b/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.err new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.err @@ -0,0 +1,37 @@ +stderr of test 'opt_sql_append` in directory 'extras/mal_optimizer_template` itself: + + +# 22:58:57 > +# 22:58:57 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "gdk_dbfarm=/ufs/manegold/_/Monet/HG/default/prefix/_/var/MonetDB" "--set" "mapi_open=true" "--set" "mapi_port=36275" "--set" "monet_prompt=" "--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_extras_mal_optimizer_template" "--set" "mal_listing=0" +# 22:58:57 > + +# builtin opt gdk_dbname = demo +# builtin opt gdk_dbfarm = /ufs/manegold/_/Monet/HG/default/prefix/_/var/monetdb5/dbfarm +# builtin opt gdk_debug = 0 +# builtin opt gdk_alloc_map = no +# builtin opt gdk_vmtrim = yes +# builtin opt monet_prompt = > +# builtin opt monet_daemon = no +# builtin opt mapi_port = 50000 +# builtin opt mapi_open = false +# builtin opt mapi_autosense = false +# builtin opt sql_optimizer = default_pipe +# builtin opt sql_debug = 0 +# cmdline opt gdk_nr_threads = 0 +# cmdline opt gdk_dbfarm = /ufs/manegold/_/Monet/HG/default/prefix/_/var/MonetDB +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 36275 +# cmdline opt monet_prompt = +# cmdline opt mal_listing = 2 +# cmdline opt gdk_dbname = mTests_extras_mal_optimizer_template +# cmdline opt mal_listing = 0 + +# 22:58:57 > +# 22:58:57 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=rome" "--port=36275" +# 22:58:57 > + + +# 22:58:58 > +# 22:58:58 > "Done." +# 22:58:58 > + diff --git a/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.out b/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.out new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/Tests/opt_sql_append.stable.out @@ -0,0 +1,81 @@ +stdout of test 'opt_sql_append` in directory 'extras/mal_optimizer_template` itself: + + +# 22:58:57 > +# 22:58:57 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "gdk_dbfarm=/ufs/manegold/_/Monet/HG/default/prefix/_/var/MonetDB" "--set" "mapi_open=true" "--set" "mapi_port=36275" "--set" "monet_prompt=" "--trace" "--forcemito" "--set" "mal_listing=2" "--dbname=mTests_extras_mal_optimizer_template" "--set" "mal_listing=0" +# 22:58:57 > + +# MonetDB 5 server v11.8.0 +# This is an unreleased version +# Serving database 'mTests_extras_mal_optimizer_template', using 8 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically linked +# Found 15.630 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2012 MonetDB B.V., all rights reserved +# Visit http://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://rome.ins.cwi.nl:36275/ +# MonetDB/GIS module loaded +# MonetDB/SQL module loaded + +Ready. +# SQL catalog created, loading sql scripts once +# loading sql script: 09_like.sql +# loading sql script: 10_math.sql +# loading sql script: 11_times.sql +# loading sql script: 12_url.sql +# loading sql script: 13_date.sql +# loading sql script: 14_inet.sql +# loading sql script: 15_history.sql +# loading sql script: 16_tracelog.sql +# loading sql script: 17_compress.sql +# loading sql script: 18_dictionary.sql +# loading sql script: 19_cluster.sql +# loading sql script: 20_vacuum.sql +# loading sql script: 21_dependency_functions.sql +# loading sql script: 22_clients.sql +# loading sql script: 23_skyserver.sql +# loading sql script: 24_zorder.sql +# loading sql script: 25_debug.sql +# loading sql script: 40_geom.sql +# loading sql script: 80_udf.sql +# loading sql script: 99_system.sql + +# 22:58:57 > +# 22:58:57 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=rome" "--port=36275" +# 22:58:57 > + +#create table ttt (a int, b int, c int); +#explain copy into ttt from '/tmp/xyz'; +% .explain # table_name +% mal # name +% clob # type +% 175 # length +function user.s1_1{autoCommit=true}():void; + X_2 := sql.mvc(); + (X_6:bat[:oid,:int] ,X_7:bat[:oid,:int] ,X_8:bat[:oid,:int] ) := sql.copy_from("sys":str,"ttt":str,"|":str,"\\n":str,nil:str,"null":str,"/tmp/xyz":str,-1:lng,0:lng,0:int); + X_9 := sql.append(X_2,"sys","ttt","a",X_6); + X_11 := sql.append(X_9,"sys","ttt","b",X_7); + X_14 := sql.append(X_11,"sys":str,"ttt":str,"c",X_8); + X_16 := aggr.count(X_8); + sql.affectedRows(X_14,X_16,""); +end s1_1; +#explain copy into ttt from '/tmp/xyz'; +% .explain # table_name +% mal # name +% clob # type +% 175 # length +function user.s3_1{autoCommit=true}():void; + X_2 := sql.mvc(); + (X_6:bat[:oid,:int] ,X_7:bat[:oid,:int] ,X_8:bat[:oid,:int] ) := sql.copy_from("sys":str,"ttt":str,"|":str,"\\n":str,nil:str,"null":str,"/tmp/xyz":str,-1:lng,0:lng,0:int); + X_9 := sql.append(X_2,"sys","ttt","a",X_6); + X_11 := sql.append(X_9,"sys","ttt","b",X_7); + X_16 := aggr.count(X_8); + X_14 := sql.append(X_11,"sys":str,"ttt":str,"c",X_8); + sql.affectedRows(X_14,X_16,""); +end s3_1; +#drop table ttt; + +# 22:58:58 > +# 22:58:58 > "Done." +# 22:58:58 > + diff --git a/monetdb5/extras/mal_optimizer_template/opt_sql_append.mx b/monetdb5/extras/mal_optimizer_template/opt_sql_append.mx new file mode 100644 --- /dev/null +++ b/monetdb5/extras/mal_optimizer_template/opt_sql_append.mx @@ -0,0 +1,250 @@ +@/ +The contents of this file are subject to the MonetDB Public License +Version 1.1 (the "License"); you may not use this file except in +compliance with the License. You may obtain a copy of the License at +http://www.monetdb.org/Legal/MonetDBLicense + +Software distributed under the License is distributed on an "AS IS" +basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +License for the specific language governing rights and limitations +under the License. + +The Original Code is the MonetDB Database System. + +The Initial Developer of the Original Code is CWI. +Portions created by CWI are Copyright (C) 1997-July 2008 CWI. +Copyright August 2008-2011 MonetDB B.V. +All Rights Reserved. +@ + +@f opt_sql_append + +@c +/* + * @a S. Manegold + * @- SQL append show-case optimizer + * + * This optimizer is mainly for demonstrating how to implement a MAL + * optimizer in priciple. + * + * Purely for that purpose, the optimizer's task is to recognize MAL code + * patterns like + * + * ... + * v3 := sql.append( ..., ..., ..., ..., v0 ); + * ... + * v5 := ... v0 ...; + * ... + * + * i.e., an sql.append() statement that is eventually followed by some other + * statement later on in the MAL program that uses the same v0 BAT as + * argument as the sql.append() statement does, + * + * and transform them into + * + * ... + * v1 := aggr.count( v0 ); + * v2 := algebra.slice( v0, 0, v1 ); + * v3 := sql.append( ..., ..., ..., ..., v2 ); + * ... + * v5 := ... v0 ...; + * ... + * + * i.e., handing a BAT view v2 of BAT v0 as argument to the sql.append() + * statement, rather than the original BAT v0. + * + * As a refinement, patterns like + * + * ... _______________________________________________ Checkin-list mailing list [email protected] http://mail.monetdb.org/mailman/listinfo/checkin-list
