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

push candidates into join. For now only enabled if run with debug 1<<15.


diffs (228 lines):

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
@@ -111,11 +111,16 @@ str insertRef;
 str intRef;
 str ioRef;
 str iteratorRef;
-str joinRef;
 str joinPathRef;
 str jsonRef;
+str joinRef;
+str antijoinRef;
 str bandjoinRef;
 str thetajoinRef;
+str subjoinRef;
+str subantijoinRef;
+str subbandjoinRef;
+str subthetajoinRef;
 str thetauselectRef;
 str thetaselectRef;
 str kdifferenceRef;
@@ -255,7 +260,6 @@ str uselectRef;
 str userRef;
 str vectorRef;
 str antiuselectRef;
-str antijoinRef;
 str zero_or_oneRef;
 
 int canBeCrackedProp;
@@ -378,10 +382,15 @@ void optimizerInit(void){
                intRef = putName("int",3);
                ioRef = putName("io",2);
                iteratorRef = putName("iterator",8);
+               joinPathRef = putName("joinPath",8);
                joinRef = putName("join",4);
-               joinPathRef = putName("joinPath",8);
+               antijoinRef = putName("antijoin",8);
                bandjoinRef = putName("bandjoin",8);
                thetajoinRef = putName("thetajoin",9);
+               subjoinRef = putName("subjoin",7);
+               subantijoinRef = putName("subantijoin",11);
+               subbandjoinRef = putName("subbandjoin",11);
+               subthetajoinRef = putName("subthetajoin",12);
                thetauselectRef = putName("thetauselect",12);
                thetaselectRef = putName("thetaselect",11);
                jsonRef = putName("json",4);
@@ -521,7 +530,6 @@ void optimizerInit(void){
                uselectRef = putName("uselect",7);
                vectorRef = putName("vector",6);
                antiuselectRef = putName("antiuselect",11);
-               antijoinRef = putName("antijoin",8);
                zero_or_oneRef = putName("zero_or_one",11);
                userRef = putName("user",4);
 
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
@@ -110,11 +110,16 @@ opt_export  str insertRef;
 opt_export  str intRef;
 opt_export  str ioRef;
 opt_export  str iteratorRef;
-opt_export  str joinRef;
 opt_export  str joinPathRef;
 opt_export  str jsonRef;
+opt_export  str joinRef;
+opt_export  str antijoinRef;
 opt_export  str bandjoinRef;
 opt_export  str thetajoinRef;
+opt_export  str subjoinRef;
+opt_export  str subantijoinRef;
+opt_export  str subbandjoinRef;
+opt_export  str subthetajoinRef;
 opt_export  str thetauselectRef;
 opt_export  str thetaselectRef;
 opt_export  str kdifferenceRef;
@@ -254,7 +259,6 @@ opt_export  str uselectRef;
 opt_export  str userRef;
 opt_export  str vectorRef;
 opt_export  str antiuselectRef;
-opt_export  str antijoinRef;
 opt_export  str zero_or_oneRef;
 
 opt_export int canBeCrackedProp;       /* binary */
diff --git a/monetdb5/optimizer/opt_pushselect.c 
b/monetdb5/optimizer/opt_pushselect.c
--- a/monetdb5/optimizer/opt_pushselect.c
+++ b/monetdb5/optimizer/opt_pushselect.c
@@ -33,6 +33,20 @@ PushArgument(MalBlkPtr mb, InstrPtr p, i
 }
 
 static InstrPtr
+PushNil(MalBlkPtr mb, InstrPtr p, int pos, int tpe)
+{
+       int i, arg;
+
+       p = pushNil(mb, p, tpe); /* push at end */
+       arg = getArg(p, p->argc-1);
+       for (i = p->argc-1; i > pos; i--) 
+               getArg(p, i) = getArg(p, i-1);
+       getArg(p, pos) = arg;
+       return p;
+}
+
+
+static InstrPtr
 RemoveArgument(InstrPtr p, int pos)
 {
        int i;
@@ -191,6 +205,66 @@ OPTpushselectImplementation(Client cntxt
                                return 0;
                        }
                }
+               /* left hand side */
+               if ( (GDKdebug & (1<<15)) &&
+                    isMatJoinOp(p) && p->retc == 2) { 
+                       int i1 = getArg(p, 2), tid = 0;
+                       InstrPtr q = old[vars[i1]];
+
+                       /* find the table ids */
+                       while(!tid) {
+                               if (getModuleId(q) == algebraRef && 
getFunctionId(q) == leftfetchjoinRef) {
+                                       int i1 = getArg(q, 1);
+                                       InstrPtr s = old[vars[i1]];
+       
+                                       if (getModuleId(s) == sqlRef && 
getFunctionId(s) == tidRef) 
+                                               tid = getArg(q, 1);
+                                       break;
+                               } else if (isMapOp(q) && q->argc >= 2 && 
isaBatType(getArgType(mb, q, 1))) {
+                                       int i1 = getArg(q, 1);
+                                       q = old[vars[i1]];
+                               } else if (isMapOp(q) && q->argc >= 3 && 
isaBatType(getArgType(mb, q, 2))) {
+                                       int i2 = getArg(q, 2);
+                                       q = old[vars[i2]];
+                               } else {
+                                       break;
+                               }
+                       }
+                       if (tid && subselect_add(&subselects, tid, getArg(p, 
0)) < 0) {
+                               GDKfree(vars);
+                               return 0;
+                       }
+               }
+               /* right hand side */
+               if ( (GDKdebug & (1<<15)) &&
+                    isMatJoinOp(p) && p->retc == 2) { 
+                       int i1 = getArg(p, 3), tid = 0;
+                       InstrPtr q = old[vars[i1]];
+
+                       /* find the table ids */
+                       while(!tid) {
+                               if (getModuleId(q) == algebraRef && 
getFunctionId(q) == leftfetchjoinRef) {
+                                       int i1 = getArg(q, 1);
+                                       InstrPtr s = old[vars[i1]];
+       
+                                       if (getModuleId(s) == sqlRef && 
getFunctionId(s) == tidRef) 
+                                               tid = getArg(q, 1);
+                                       break;
+                               } else if (isMapOp(q) && q->argc >= 2 && 
isaBatType(getArgType(mb, q, 1))) {
+                                       int i1 = getArg(q, 1);
+                                       q = old[vars[i1]];
+                               } else if (isMapOp(q) && q->argc >= 3 && 
isaBatType(getArgType(mb, q, 2))) {
+                                       int i2 = getArg(q, 2);
+                                       q = old[vars[i2]];
+                               } else {
+                                       break;
+                               }
+                       }
+                       if (tid && subselect_add(&subselects, tid, getArg(p, 
1)) < 0) {
+                               GDKfree(vars);
+                               return 0;
+                       }
+               }
        }
 
        if ((!subselects.nr && !nr_topn && !nr_likes) || newMalBlkStmt(mb, 
mb->ssize+20) <0 ) {
@@ -248,6 +322,53 @@ OPTpushselectImplementation(Client cntxt
                                actions++;
                        }
                }
+               else if ( (GDKdebug & (1<<15)) &&
+                        isMatJoinOp(p) && p->retc == 2
+                        && !(getFunctionId(p) == joinRef && p->argc > 4)
+                        ) { 
+                       int ltid = 0, rtid = 0, done = 0;
+                       int range = 0;
+
+                       if(getFunctionId(p) == joinRef)
+                               range = (p->argc >= 4);
+
+                       if ((ltid = subselect_find_tids(&subselects, getArg(p, 
0))) >= 0 && 
+                           (rtid = subselect_find_tids(&subselects, getArg(p, 
1))) >= 0) {
+                               p = PushArgument(mb, p, ltid, 4+range);
+                               p = PushArgument(mb, p, rtid, 5+range);
+                               done = 1;
+                       } else if ((ltid = subselect_find_tids(&subselects, 
getArg(p, 0))) >= 0) { 
+                               p = PushArgument(mb, p, ltid, 4+range);
+                               p = PushNil(mb, p, 5+range, TYPE_bat); 
+                               done = 1;
+                       } else if ((rtid = subselect_find_tids(&subselects, 
getArg(p, 1))) >= 0) {
+                               p = PushNil(mb, p, 4+range, TYPE_bat); 
+                               p = PushArgument(mb, p, rtid, 5+range);
+                               done = 1;
+                       }
+                       if (done) {
+                               if(getFunctionId(p) == antijoinRef)
+                                       p = pushInt(mb, p, JOIN_NE); 
+                               p = pushBit(mb, p, FALSE); /* do not match nils 
*/
+                               p = pushNil(mb, p, TYPE_lng); /* no estimate */
+
+                               /* TODO join* -> subjoin* */
+                               if(getFunctionId(p) == joinRef)
+                                       getFunctionId(p) = subjoinRef;
+                               else if(getFunctionId(p) == antijoinRef)
+                                       getFunctionId(p) = subthetajoinRef;
+                               else if(getFunctionId(p) == thetajoinRef)
+                                       getFunctionId(p) = subthetajoinRef;
+                               else if(getFunctionId(p) == bandjoinRef)
+                                       getFunctionId(p) = subbandjoinRef;
+                               /* make sure to resolve again */
+                               p->token = ASSIGNsymbol; 
+                               p->typechk = TYPE_UNKNOWN;
+                               p->fcn = NULL;
+                               p->blk = NULL;
+                               actions++;
+                       }
+               }
                /* Leftfetchjoins involving rewriten table ids need to be 
flattend
                 * l = leftfetchjoin(t, c); => l = c;
                 * and
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to