Changeset: f8afc241d5a2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f8afc241d5a2
Modified Files:
        monetdb5/optimizer/opt_emptybind.c
Branch: default
Log Message:

Add thetaselect and bat updates
Empty sets can be propagated.


diffs (240 lines):

diff --git a/monetdb5/optimizer/opt_emptybind.c 
b/monetdb5/optimizer/opt_emptybind.c
--- a/monetdb5/optimizer/opt_emptybind.c
+++ b/monetdb5/optimizer/opt_emptybind.c
@@ -20,6 +20,15 @@
 #include "opt_deadcode.h"
 #include "mal_builder.h"
 
+#define addresult(I)                                                           
        \
+       do {                                                                    
                        \
+               int tpe = getVarType(mb,getArg(p,I));                   \
+               q= newStmt(mb, batRef, newRef);                                 
\
+               getArg(q,0)= getArg(p,I);                                       
        \
+               q = pushType(mb, q, getBatType(tpe));                   \
+               empty[getArg(q,0)]= 1;                                          
        \
+       } while (0)
+
 #define emptyresult(I)                                                         
        \
        do {                                                                    
                        \
                int tpe = getVarType(mb,getArg(p,I));                   \
@@ -30,6 +39,7 @@
                p = pushType(mb,p, getBatType(tpe));                    \
                setVarType(mb, getArg(p,0), tpe);                               
\
                setVarFixed(mb, getArg(p,0));                                   
\
+               empty[getArg(p,0)]= 1;                                          
        \
        } while (0)
 
 
@@ -37,7 +47,7 @@ int
 OPTemptybindImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
 {
        int i,j, actions =0;
-       int *marked;
+       int *empty;
        int limit = mb->stop, slimit = mb->ssize;
        InstrPtr p, q, *old = mb->stmt, *updated;
        char buf[256];
@@ -55,19 +65,19 @@ OPTemptybindImplementation(Client cntxt,
                goto wrapup;
 
        // track of where 'emptybind' results are produced
-       marked = (int *) GDKzalloc(mb->vsize * sizeof(int));
-       if ( marked == NULL)
+       empty = (int *) GDKzalloc(mb->vsize * sizeof(int));
+       if ( empty == NULL)
                return 0;
 
        updated= (InstrPtr *) GDKzalloc(esize * sizeof(InstrPtr));
        if( updated == 0){
-               GDKfree(marked);
+               GDKfree(empty);
                return 0;
        }
        (void) stk;
 
        /* Got an instructions V:= bat.new(:tpe) 
-        * The form the initial family of marked sets.
+        * The form the initial family of empty sets.
         */
 
        (void) cntxt;
@@ -102,7 +112,7 @@ OPTemptybindImplementation(Client cntxt,
 #ifdef DEBUG_OPT_EMPTYBIND
                        mnstr_printf(cntxt->fdout, "#empty bat  pc %d var 
%d\n",i , getArg(p,0) );
 #endif
-                       marked[getArg(p,0)] = i;
+                       empty[getArg(p,0)] = i;
                        continue;
                } 
 
@@ -111,14 +121,14 @@ OPTemptybindImplementation(Client cntxt,
                        if ( etop == esize){
                                updated = (InstrPtr*) GDKrealloc( updated, 
(esize += 256) * sizeof(InstrPtr));
                                if( updated == NULL){
-                                       GDKfree(marked);
+                                       GDKfree(empty);
                                        goto wrapup;
                                }
                        }
                        updated[etop++]= p;
                }
 
-               /* restore the naming, dropping the runtime property 'marked' */
+               /* restore the naming, dropping the runtime property 'empty' */
                if (getFunctionId(p) == emptybindRef) {
 #ifdef DEBUG_OPT_EMPTYBIND
                        mnstr_printf(cntxt->fdout, "#empty bind  pc %d var 
%d\n",i , getArg(p,0) );
@@ -126,9 +136,9 @@ OPTemptybindImplementation(Client cntxt,
                        actions++;
                        setFunctionId(p,bindRef);
                        p->typechk= TYPE_UNKNOWN;
-                       marked[getArg(p,0)] = i;
+                       empty[getArg(p,0)] = i;
                        if( p->retc == 2){
-                               marked[getArg(p,1)] = i;
+                               empty[getArg(p,1)] = i;
 #ifdef DEBUG_OPT_EMPTYBIND
                                mnstr_printf(cntxt->fdout, "#empty update bind  
pc %d var %d\n",i , getArg(p,1) );
 #endif
@@ -144,30 +154,30 @@ OPTemptybindImplementation(Client cntxt,
 #ifdef DEBUG_OPT_EMPTYBIND
                                                mnstr_printf(cntxt->fdout, 
"#reset mark empty variable pc %d var %d\n",i , getArg(p,0) );
 #endif
-                                               marked[getArg(p,0)] = 0;
+                                               empty[getArg(p,0)] = 0;
                                                if( p->retc == 2){
 #ifdef DEBUG_OPT_EMPTYBIND
                                                        
mnstr_printf(cntxt->fdout, "#reset mark empty variable pc %d var %d\n",i , 
getArg(p,1) );
 #endif
-                                                       marked[getArg(p,1)] = 0;
+                                                       empty[getArg(p,1)] = 0;
                                                }
                                                break;
                                        }
                                }
                                if(q && getModuleId(q) == sqlcatalogRef){
                                        if ( 
strcmp(getVarConstant(mb,getArg(q,2)).val.sval, sch) == 0 ){
-                                               marked[getArg(p,0)] = 0;
+                                               empty[getArg(p,0)] = 0;
                                                if( p->retc == 2){
 #ifdef DEBUG_OPT_EMPTYBIND
                                                        
mnstr_printf(cntxt->fdout, "#reset mark empty variable pc %d var %d\n",i , 
getArg(p,1) );
 #endif
-                                                       marked[getArg(p,1)] = 0;
+                                                       empty[getArg(p,1)] = 0;
                                                }
                                                break;
                                        }
                                }
                        }
-                       if( marked[getArg(p,0)]){
+                       if( empty[getArg(p,0)]){
                 int tpe;
                                if( p->retc == 2){
                                        tpe = 
getBatType(getVarType(mb,getArg(p,1)));
@@ -196,7 +206,7 @@ OPTemptybindImplementation(Client cntxt,
                        actions++;
                        setFunctionId(p,bindidxRef);
                        p->typechk= TYPE_UNKNOWN;
-                       marked[getArg(p,0)] = i;
+                       empty[getArg(p,0)] = i;
                        // replace the call into a empty bat creation unless 
the table was updated already in the same query 
                        sch = getVarConstant(mb,getArg(p,2  + 
(p->retc==2))).val.sval;
                        tbl = getVarConstant(mb,getArg(p,3  + 
(p->retc==2))).val.sval;
@@ -208,24 +218,24 @@ OPTemptybindImplementation(Client cntxt,
 #ifdef DEBUG_OPT_EMPTYBIND
                                                        
mnstr_printf(cntxt->fdout, "#reset mark empty variable pc %d var %d\n",i , 
getArg(p,0) );
 #endif
-                                               marked[getArg(p,0)] = 0;
+                                               empty[getArg(p,0)] = 0;
                                                if( p->retc == 2){
 #ifdef DEBUG_OPT_EMPTYBIND
                                                        
mnstr_printf(cntxt->fdout, "#reset mark empty variable pc %d var %d\n",i , 
getArg(p,1) );
 #endif
-                                                       marked[getArg(p,1)] = 0;
+                                                       empty[getArg(p,1)] = 0;
                                                }
                                                break;
                                        }
                                }
                                if(q && getModuleId(q) == sqlcatalogRef){
                                        if ( 
strcmp(getVarConstant(mb,getArg(q,2)).val.sval, sch) == 0 ){
-                                               marked[getArg(p,0)] = 0;
+                                               empty[getArg(p,0)] = 0;
                                                break;
                                        }
                                }
                        }
-                       if( marked[getArg(p,0)]){
+                       if( empty[getArg(p,0)]){
                                int tpe;
                                if( p->retc == 2){
                                        tpe = 
getBatType(getVarType(mb,getArg(p,1)));
@@ -249,23 +259,23 @@ OPTemptybindImplementation(Client cntxt,
 
                // delta operations without updates+ insert can be replaced by 
an assignment
                if (getModuleId(p)== sqlRef && getFunctionId(p) == deltaRef  && 
p->argc ==5){
-                       if( marked[getArg(p,2)] && marked[getArg(p,3)] && 
marked[getArg(p,4)] ){
+                       if( empty[getArg(p,2)] && empty[getArg(p,3)] && 
empty[getArg(p,4)] ){
 #ifdef DEBUG_OPT_EMPTYBIND
-                               mnstr_printf(cntxt->fdout, "#empty delta  pc %d 
var %d,%d,%d\n",i ,marked[getArg(p,2)], marked[getArg(p,3)], 
marked[getArg(p,4)] );
+                               mnstr_printf(cntxt->fdout, "#empty delta  pc %d 
var %d,%d,%d\n",i ,empty[getArg(p,2)], empty[getArg(p,3)], empty[getArg(p,4)] );
                                mnstr_printf(cntxt->fdout, "#empty delta  pc %d 
var %d\n",i , getArg(p,0) );
 #endif
                                actions++;
                                clrFunction(p);
                                p->argc = 2;
-                               if ( marked[getArg(p,1)] ){
-                                       marked[getArg(p,0)] = i;
+                               if ( empty[getArg(p,1)] ){
+                                       empty[getArg(p,0)] = i;
                                }
                        }
                        continue;
                }
 
                if (getModuleId(p)== sqlRef && getFunctionId(p) == 
projectdeltaRef) {
-                       if( marked[getArg(p,3)] && marked[getArg(p,4)] ){
+                       if( empty[getArg(p,3)] && empty[getArg(p,4)] ){
 #ifdef DEBUG_OPT_EMPTYBIND
                                mnstr_printf(cntxt->fdout, "#empty projectdelta 
 pc %d var %d\n",i , getArg(p,0) );
 #endif
@@ -279,7 +289,7 @@ OPTemptybindImplementation(Client cntxt,
                }
                if (getModuleId(p)== algebraRef){
                        if( getFunctionId(p) == projectionRef) {
-                               if( marked[getArg(p,1)] || marked[getArg(p,2)] 
){
+                               if( empty[getArg(p,1)] || empty[getArg(p,2)] ){
 #ifdef DEBUG_OPT_EMPTYBIND
                                        mnstr_printf(cntxt->fdout, "#empty 
projection  pc %d var %d\n",i , getArg(p,0) );
 #endif
@@ -287,6 +297,20 @@ OPTemptybindImplementation(Client cntxt,
                                        emptyresult(0);
                                }
                        }
+                       if( getFunctionId(p) == thetaselectRef) {
+                               if( empty[getArg(p,1)] || empty[getArg(p,2)] ){
+#ifdef DEBUG_OPT_EMPTYBIND
+                                       mnstr_printf(cntxt->fdout, "#empty 
projection  pc %d var %d\n",i , getArg(p,0) );
+#endif
+                                       actions++;
+                                       emptyresult(0);
+                               }
+                       }
+               }
+               if (getModuleId(p)== batRef && isUpdateInstruction(p) && 
empty[getArg(p,2)]){
+                       actions++;
+                       clrFunction(p); 
+                       p->argc = 2;
                }
        }
 
@@ -300,7 +324,7 @@ OPTemptybindImplementation(Client cntxt,
                if( old[i])
                        freeInstruction(old[i]);
        GDKfree(old);
-       GDKfree(marked);
+       GDKfree(empty);
        GDKfree(updated);
     /* Defense line against incorrect plans */
        chkTypes(cntxt->fdout, cntxt->nspace, mb, FALSE);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to