Changeset: ae875a3e0e49 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ae875a3e0e49
Added Files:
        monetdb5/optimizer/opt_generator.c
        monetdb5/optimizer/opt_generator.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
        monetdb5/optimizer/optimizer.mal
        sql/backends/monet5/generator/generator.c
        sql/backends/monet5/generator/generator.mal
Branch: generator
Log Message:

Traditional concurrency conflict
It is wrong to call the optimizer at runtime to
change your inflight plan. It may happen that the
instructions you intend to change are already
selected for execution.

This means that the generator optimizer is a
regular optimizer to be added to the pipelines.


diffs (truncated from 554 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
@@ -42,6 +42,7 @@ lib_optimizer = {
                opt_evaluate.c opt_evaluate.h \
                opt_factorize.c opt_factorize.h \
                opt_garbageCollector.c opt_garbageCollector.h \
+               opt_generator.c opt_generator.h \
                opt_groups.c opt_groups.h \
                opt_querylog.c opt_querylog.h \
                opt_inline.c opt_inline.h \
diff --git a/monetdb5/optimizer/opt_generator.c 
b/monetdb5/optimizer/opt_generator.c
new file mode 100644
--- /dev/null
+++ b/monetdb5/optimizer/opt_generator.c
@@ -0,0 +1,136 @@
+/*
+ * 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.
+ */
+
+#include "monetdb_config.h"
+#include "opt_generator.h"
+
+/*
+ * (c) Martin Kersten, Sjoerd Mullender
+ * Series generating module for integer, decimal, real, double and timestamps.
+ */
+
+
+static int
+assignedOnce(MalBlkPtr mb, int varid)
+{
+       InstrPtr p;
+       int i,j, c=0;
+
+       for(i = 1; i< mb->stop; i++){
+               p = getInstrPtr(mb,i);
+               for( j = 0; j < p->retc; j++)
+               if( getArg(p,j) == varid){
+                       c++;
+                       break;
+               }
+       }
+       return c == 1;
+}
+static int
+useCount(MalBlkPtr mb, int varid)
+{
+       InstrPtr p;
+       int i,j, d,c=0;
+
+       for(i = 1; i< mb->stop; i++){
+               p = getInstrPtr(mb,i);
+               d= 0;
+               for( j = p->retc; j < p->argc; j++)
+               if( getArg(p,j) == varid)
+                       d++;
+               c += d > 0;
+       }
+       return c;
+}
+
+int 
+OPTgeneratorImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
+{
+       InstrPtr p,q;
+       int i,j,k, used= 0, cases, blocked;
+       str vaultRef = putName("vault",5);
+       str generateRef = putName("generate_series",15);
+       str paramRef = putName("parameters",10);
+
+       (void) cntxt;
+       (void) stk;
+       (void) pci;
+
+       for( i=1; i < mb->stop; i++){
+               p = getInstrPtr(mb,i);
+               if ( getModuleId(p) == vaultRef && getFunctionId(p) == 
generateRef){
+                       /* found a target for propagation */
+                       if ( assignedOnce(mb, getArg(p,0)) ){
+                               cases = useCount(mb, getArg(p,0));
+                               blocked = 0;
+                               for( j = i+1; j< mb->stop && blocked == 0; j++){
+                                       q = getInstrPtr(mb,j);
+                                       if ( getModuleId(q) == algebraRef && 
getFunctionId(q) == subselectRef && getArg(q,1) == getArg(p,0)){
+                                               setModuleId(q, generatorRef);
+                                               typeChecker(cntxt->fdout, 
cntxt->nspace, mb, q, TRUE);
+                                               used++;
+                                       } else
+                                       if ( getModuleId(q) == algebraRef && 
getFunctionId(q) == thetasubselectRef && getArg(q,1) == getArg(p,0)){
+                                               setModuleId(q, generatorRef);
+                                               typeChecker(cntxt->fdout, 
cntxt->nspace, mb, q, TRUE);
+                                               used++;
+                                       } else
+                                       if ( getModuleId(q) == algebraRef && 
getFunctionId(q) == leftfetchjoinRef && getArg(q,2) == getArg(p,0)){
+                                               // projection over a series
+                                               setModuleId(q, generatorRef);
+                                               typeChecker(cntxt->fdout, 
cntxt->nspace, mb, q, TRUE);
+                                               used++;
+                                       } else
+                                       if ( getModuleId(q) == algebraRef && 
getFunctionId(q) == joinRef && (getArg(q,2) == getArg(p,0) || getArg(q,3) == 
getArg(p,0))){
+                                               // projection over a series
+                                               setModuleId(q, generatorRef);
+                                               typeChecker(cntxt->fdout, 
cntxt->nspace, mb, q, TRUE);
+                                               if(q->typechk == TYPE_UNKNOWN){
+                                                       setModuleId(q, 
algebraRef);
+                                                       
typeChecker(cntxt->fdout, cntxt->nspace, mb, q, TRUE);
+                                               } else
+                                                       used++;
+                                       } else
+                                       if ( getModuleId(q) == languageRef && 
getFunctionId(q) == passRef && getArg(q,1) == getArg(p,0))
+                                               // nothing happens in this 
instruction
+                                               used++;
+                                       else {
+                                               // check for use without 
conversion
+                                               for(k = q->retc; k < q->argc; 
k++)
+                                               if( getArg(q,k) == getArg(p,0))
+                                                       blocked++;
+                                       }
+                               }
+                               // fix the original, only when all use cases 
are replaced by the overloaded function
+                               if(used == cases && blocked == 0){
+                                       setModuleId(p, generatorRef);
+                                       setFunctionId(p, paramRef);
+                                       typeChecker(cntxt->fdout, 
cntxt->nspace, mb, p, TRUE);
+                               } else used = 0;
+#ifdef VLT_DEBUG
+                               mnstr_printf(cntxt->fdout,"#generator target %d 
cases %d used %d error %d\n",getArg(p,0), cases, used, p->typechk);
+#endif
+                       }
+               }
+       }
+#ifdef VLT_DEBUG
+       printFunction(cntxt->fdout,mb,0,LIST_MAL_ALL);
+#endif
+       return used== 0;
+}
diff --git a/monetdb5/optimizer/opt_generator.h 
b/monetdb5/optimizer/opt_generator.h
new file mode 100644
--- /dev/null
+++ b/monetdb5/optimizer/opt_generator.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_GENERATORCODE_
+#define _OPT_GENERATORCODE_
+#include "opt_prelude.h"
+#include "opt_support.h"
+#include "mal_interpreter.h"
+#include "mal_instruction.h"
+#include "mal_function.h"
+
+opt_export int OPTgeneratorImplementation(Client cntxt, MalBlkPtr mb, 
MalStkPtr stk, InstrPtr pci);
+
+#define OPTDEBUGgenerator  if ( optDebug & (1 <<DEBUG_OPT_GENERATOR) )
+
+#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.generator();"
         "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.generator();"
         "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.generator();"
         "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.generator();"
         "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.generator();"
         "optimizer.garbageCollector();",
         "stable", NULL, NULL, 1},
 /*
@@ -215,6 +220,7 @@ static struct PIPELINES {
         "optimizer.dataflow();"
         "optimizer.querylog();"
         "optimizer.multiplex();"
+        "optimizer.generator();"
         "optimizer.garbageCollector();",
         "experimental", "OPToctopus", NULL, 1},
 /*
@@ -241,6 +247,7 @@ static struct PIPELINES {
         "optimizer.dataflow();"
         "optimizer.querylog();"
         "optimizer.multiplex();"
+        "optimizer.generator();"
         "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
@@ -96,6 +96,7 @@ str exportOperationRef;
 str finishRef;
 str firstnRef;
 str getRef;
+str generatorRef;
 str grabRef;
 str groupRef;
 str subgroupRef;
@@ -358,6 +359,7 @@ void optimizerInit(void)
        finishRef = putName("finish",6);
        firstnRef = putName("firstn",6);
        getRef = putName("get",3);
+       generatorRef = putName("generator",9);
        grabRef = putName("grab",4);
        groupRef = putName("group",5);
        subgroupRef = putName("subgroup",8);
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
@@ -94,6 +94,7 @@ opt_export    str exportOperationRef;
 opt_export  str finishRef;
 opt_export  str firstnRef;
 opt_export  str getRef;
+opt_export  str generatorRef;
 opt_export  str grabRef;
 opt_export  str groupRef;
 opt_export  str subgroupRef;
diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -159,6 +159,7 @@ struct OPTcatalog {
 {"evaluate",   0,      0,      0,      DEBUG_OPT_EVALUATE},
 {"factorize",  0,      0,      0,      DEBUG_OPT_FACTORIZE},
 {"garbage",            0,      0,      0,      DEBUG_OPT_GARBAGE},
+{"generator",  0,      0,      0,      DEBUG_OPT_GENERATOR},
 {"history",            0,      0,      0,      DEBUG_OPT_HISTORY},
 {"inline",             0,      0,      0,      DEBUG_OPT_INLINE},
 {"joinPath",   0,      0,      0,      DEBUG_OPT_JOINPATH},
diff --git a/monetdb5/optimizer/opt_support.h b/monetdb5/optimizer/opt_support.h
--- a/monetdb5/optimizer/opt_support.h
+++ b/monetdb5/optimizer/opt_support.h
@@ -58,6 +58,7 @@
 #define DEBUG_OPT_EVALUATE                     17
 #define DEBUG_OPT_FACTORIZE                    18
 #define DEBUG_OPT_GARBAGE                      19
+#define DEBUG_OPT_GENERATOR                    56
 #define DEBUG_OPT_INLINE                       20
 #define DEBUG_OPT_JOINPATH                     21
 #define DEBUG_OPT_MACRO                                23
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to