Changeset: dd91548a9cdc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dd91548a9cdc
Added Files:
monetdb5/optimizer/opt_mosaic.c
monetdb5/optimizer/opt_mosaic.h
Modified Files:
monetdb5/optimizer/Makefile.ag
monetdb5/optimizer/opt_pipes.c
monetdb5/optimizer/opt_prelude.c
monetdb5/optimizer/opt_prelude.h
monetdb5/optimizer/opt_support.c
monetdb5/optimizer/opt_support.h
monetdb5/optimizer/opt_wrapper.c
Branch: mosaic
Log Message:
Introduction of the mosaic optimizer
It should be run in the tail of the pipeline,
since that would benefit normal algebraic optimizations,
such as the select/join stuff.
diffs (truncated from 349 to 300 lines):
diff --git a/monetdb5/optimizer/Makefile.ag b/monetdb5/optimizer/Makefile.ag
--- a/monetdb5/optimizer/Makefile.ag
+++ b/monetdb5/optimizer/Makefile.ag
@@ -52,6 +52,7 @@ lib_optimizer = {
opt_json.c opt_json.h \
opt_mergetable.c opt_mergetable.h \
opt_mitosis.c opt_mitosis.h \
+ opt_mosaic.c opt_mosaic.h \
opt_multiplex.c opt_multiplex.h \
opt_octopus.c opt_octopus.h \
opt_pipes.c opt_pipes.h \
diff --git a/monetdb5/optimizer/opt_mosaic.c b/monetdb5/optimizer/opt_mosaic.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/optimizer/opt_mosaic.c
@@ -0,0 +1,125 @@
+/*
+ * 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-2014 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+/* (c) M. Kersten
+ * Pass relevant algebra operations through the mosaic library.
+ * It should only look at direct use of persistent readonly columns.
+ * This can be recognized by observing the various components being accessed.
+ */
+#include "monetdb_config.h"
+#include "opt_mosaic.h"
+#include "mosaic.h"
+#include "mtime.h"
+
+/* #define _DEBUG_MOSAIC_*/
+
+static int OPTmosaicType(MalBlkPtr mb, InstrPtr pci, int idx)
+{ int type;
+ switch(type = getArgType(mb,pci,idx)){
+ case TYPE_bte:
+ case TYPE_sht:
+ case TYPE_int:
+ case TYPE_lng:
+ case TYPE_flt:
+ case TYPE_dbl:
+ return 1;
+ default:
+ if( type == TYPE_timestamp)
+ return 1;
+ }
+ return 0;
+}
+int
+OPTmosaicImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr
pci)
+{
+ InstrPtr p,q, *old;
+ int limit,i,j, k, target=0;
+ char *check;
+
+ check = GDKzalloc(mb->vsize);
+ if ( check == NULL)
+ return 0;
+
+ limit = mb->stop;
+ old = mb->stmt;
+ if ( newMalBlkStmt(mb, mb->ssize) < 0)
+ return 0;
+
+ (void) cntxt;
+ (void) pci;
+ (void) stk;
+
+ // pre-scan to identify all potentially compressed columns
+ for( i=1; i < mb->stop; i++){
+ p = old[i];
+ if ( getModuleId(p) == sqlRef && getFunctionId(p) == bindRef &&
getVarConstant(mb,getArg(p,5)).val.ival == 0 && OPTmosaicType(mb,p,0)){
+ check[getArg(p,0)] = 1;
+ } else
+ if ( getModuleId(p) == sqlRef && getFunctionId(p) == bindRef &&
getVarConstant(mb,getArg(p,5)).val.ival != 0){
+ // locate the corresponding base column and turn it off
+ for( k= i-1; k>0; k--){
+ q = getInstrPtr(mb,k);
+ if ( getArg(q,2) == getArg(p,2) && getArg(q,3)
== getArg(p,3) && getArg(q,4) == getArg(p,4))
+ check[getArg(q,0)] = 0;
+ }
+ } else
+ if ( getModuleId(p) == algebraRef && (getFunctionId(p) == subselectRef
|| getFunctionId(p) == thetasubselectRef) && check[getArg(p,1)] )
+ /* ok */;
+ else
+ if ( getModuleId(p) == algebraRef && getFunctionId(p) ==
leftfetchjoinRef && check[getArg(p,2)])
+ /* ok */;
+ else
+ if ( getModuleId(p) == algebraRef && getFunctionId(p) == joinRef &&
(check[getArg(p,2)] || check[getArg(p,1)]))
+ /* ok */;
+ else
+ for(j= p->retc; j<p->argc; j++)
+ if( check[getArg(p,j)] )
+ check[getArg(p,j)] = -1;
+ }
+ // actual conversion
+ for( i=0; i < limit; i++){
+ p = old[i];
+ if ( getModuleId(p) == sqlRef && getFunctionId(p) == bindRef &&
getVarConstant(mb,getArg(p,5)).val.ival == 0 && check[getArg(p,0)]< 0){
+ //decompress before use such that it can be used
properly
+ q = newStmt(mb,mosaicRef,decompressRef);
+ setVarType(mb,getArg(q,0), getVarType(mb,getArg(p,0)));
+ setVarUDFtype(mb,getArg(q,0));
+ j= getArg(p,0);
+ getArg(p,0) = getArg(q,0);
+ getArg(q,0) = j;
+ p = q;
+ } else
+ // preferrably use compressed version
+ if ( getModuleId(p) == algebraRef && (getFunctionId(p) == subselectRef
|| getFunctionId(p) == thetasubselectRef) && check[getArg(p,1)] > 0)
+ setModuleId(p, mosaicRef);
+ else
+ if ( getModuleId(p) == algebraRef && getFunctionId(p) ==
leftfetchjoinRef && check[getArg(p,2)] > 0)
+ setModuleId(p, mosaicRef);
+ else
+ if ( getModuleId(p) == algebraRef && getFunctionId(p) == joinRef &&
(check[getArg(p,2)] || check[getArg(p,1)] > 0))
+ setModuleId(p, mosaicRef);
+ pushInstruction(mb,p);
+ }
+ GDKfree(old);
+ GDKfree(check);
+#ifdef _DEBUG_MOSAIC_
+ printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL);
+#endif
+ return target == 0;
+}
diff --git a/monetdb5/optimizer/opt_mosaic.h b/monetdb5/optimizer/opt_mosaic.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/optimizer/opt_mosaic.h
@@ -0,0 +1,32 @@
+/*
+ * 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-2014 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#ifndef _OPT_MOSAIC_
+#define _OPT_MOSAIC_
+#include "opt_prelude.h"
+#include "opt_support.h"
+#include "mal_interpreter.h"
+#include "mal_instruction.h"
+#include "mal_function.h"
+
+opt_export int OPTmosaicImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr
stk, InstrPtr pci);
+
+#define OPTDEBUGmosaic if ( optDebug & (1 <<DEBUG_OPT_MOSAIC) )
+
+#endif
diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c
--- a/monetdb5/optimizer/opt_pipes.c
+++ b/monetdb5/optimizer/opt_pipes.c
@@ -60,6 +60,7 @@ static struct PIPELINES {
"optimizer.remap();"
"optimizer.deadcode();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"stable", NULL, NULL, 1},
/* The default pipe line contains as of Feb2010
@@ -93,6 +94,7 @@ static struct PIPELINES {
"optimizer.dataflow();"
"optimizer.querylog();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"stable", NULL, NULL, 1},
/* The no_mitosis pipe line is (and should be kept!) identical to the
@@ -126,6 +128,7 @@ static struct PIPELINES {
"optimizer.dataflow();"
"optimizer.querylog();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"stable", NULL, NULL, 1},
/* The sequential pipe line is (and should be kept!) identical to the
@@ -158,6 +161,7 @@ static struct PIPELINES {
"optimizer.matpack();"
"optimizer.querylog();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"stable", NULL, NULL, 1},
/* Experimental pipelines stressing various components under
@@ -187,6 +191,7 @@ static struct PIPELINES {
"optimizer.recycler();"
"optimizer.querylog();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"stable", NULL, NULL, 1},
/*
@@ -215,6 +220,7 @@ static struct PIPELINES {
"optimizer.dataflow();"
"optimizer.querylog();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"experimental", "OPToctopus", NULL, 1},
/*
@@ -241,6 +247,7 @@ static struct PIPELINES {
"optimizer.dataflow();"
"optimizer.querylog();"
"optimizer.multiplex();"
+ "optimizer.mosaic();"
"optimizer.garbageCollector();",
"experimental", NULL, NULL, 1},
#endif
diff --git a/monetdb5/optimizer/opt_prelude.c b/monetdb5/optimizer/opt_prelude.c
--- a/monetdb5/optimizer/opt_prelude.c
+++ b/monetdb5/optimizer/opt_prelude.c
@@ -63,6 +63,7 @@ str clear_tableRef;
str closeRef;
str columnRef;
str columnBindRef;
+str compressRef;
str commitRef;
str connectRef;
str constraintsRef;
@@ -77,6 +78,7 @@ str datacellRef;
str dataflowRef;
str datacyclotronRef;
str dblRef;
+str decompressRef;
str deleteRef;
str depositRef;
str differenceRef;
@@ -162,6 +164,7 @@ str minRef;
str subminRef;
str mirrorRef;
str mitosisRef;
+str mosaicRef;
str mkeyRef;
str mmathRef;
str multiplexRef;
@@ -324,6 +327,8 @@ void optimizerInit(void)
closeRef = putName("close",5);
columnRef = putName("column",6);
columnBindRef = putName("columnBind",10);
+ compressRef = putName("compress",8);
+ decompressRef = putName("decompress",10);
commitRef = putName("commit",6);
connectRef = putName("connect",7);
constraintsRef = putName("constraints",11);
@@ -424,6 +429,7 @@ void optimizerInit(void)
subminRef = putName("submin", 6);
mirrorRef = putName("mirror", 6);
mitosisRef = putName("mitosis", 7);
+ mosaicRef = putName("mosaic", 6);
mkeyRef = putName("mkey", 4);
mmathRef = putName("mmath", 5);
multiplexRef = putName("multiplex", 9);
diff --git a/monetdb5/optimizer/opt_prelude.h b/monetdb5/optimizer/opt_prelude.h
--- a/monetdb5/optimizer/opt_prelude.h
+++ b/monetdb5/optimizer/opt_prelude.h
@@ -61,6 +61,7 @@ opt_export str clear_tableRef;
opt_export str closeRef;
opt_export str columnRef;
opt_export str commitRef;
+opt_export str compressRef;
opt_export str columnBindRef;
opt_export str connectRef;
opt_export str constraintsRef;
@@ -75,6 +76,7 @@ opt_export str datacellRef;
opt_export str dataflowRef;
opt_export str datacyclotronRef;
opt_export str dblRef;
+opt_export str decompressRef;
opt_export str deleteRef;
opt_export str depositRef;
opt_export str differenceRef;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list