Changeset: 5f2d8e2ad051 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5f2d8e2ad051
Modified Files:
        monetdb5/optimizer/opt_pushselect.c
Branch: Jun2020
Log Message:

push select/project through pack's introduced by the emptybind optimizer


diffs (116 lines):

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
@@ -176,7 +176,8 @@ OPTpushselectImplementation(Client cntxt
                if (isLikeOp(p))
                        nr_likes++;
 
-               if (getModuleId(p) == sqlRef && getFunctionId(p) == deltaRef)
+               if ((getModuleId(p) == sqlRef && getFunctionId(p) == deltaRef) 
||
+                       (getModuleId(p) == matRef && getFunctionId(p) == 
packRef && p->argc == (p->retc+2)))
                        push_down_delta++;
 
                if (/* DISABLES CODE */ (0) && getModuleId(p) == sqlRef && 
getFunctionId(p) == tidRef) { /* rewrite equal table ids */
@@ -610,6 +611,10 @@ OPTpushselectImplementation(Client cntxt
                 * s = subdelta(nc, uid, nu, ni);
                 *
                 * doesn't handle Xselect(x, .. z, C1.. cases) ie multicolumn 
selects
+                *
+                * also handle
+                * c = pack(b, ins)
+                * s = select(c, C1..)
                 */
                lastbat = lastbat_arg(mb, p);
                if (isSelect(p) && p->retc == 1 && lastbat == 2) {
@@ -620,7 +625,40 @@ OPTpushselectImplementation(Client cntxt
                                var = getArg(q, 1);
                                q = old[vars[var]];
                        }
-                       if (q && getModuleId(q) == sqlRef && getFunctionId(q) 
== deltaRef) {
+                       if (q && getModuleId(q) == matRef && getFunctionId(q) 
== packRef && q->argc == (q->retc+2)) {
+                               InstrPtr r = copyInstruction(p);
+                               InstrPtr t = copyInstruction(p);
+
+                               if( r == NULL || t == NULL){
+                                       freeInstruction(r);
+                                       freeInstruction(t);
+                                       GDKfree(vars);
+                                       GDKfree(nvars);
+                                       GDKfree(slices);
+                                       GDKfree(rslices);
+                                       GDKfree(oclean);
+                                       GDKfree(old);
+                                       throw(MAL,"optimizer.pushselect", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               }
+                               getArg(r, 0) = newTmpVariable(mb, 
newBatType(TYPE_oid));
+                               setVarCList(mb,getArg(r,0));
+                               getArg(r, 1) = getArg(q, 1); /* column */
+                               r->typechk = TYPE_UNKNOWN;
+                               pushInstruction(mb,r);
+                               getArg(t, 0) = newTmpVariable(mb, 
newBatType(TYPE_oid));
+                               setVarCList(mb,getArg(t,0));
+                               getArg(t, 1) = getArg(q, 2); /* inserts */
+                               pushInstruction(mb,t);
+
+                               InstrPtr u = copyInstruction(q); /* pack result 
*/
+                               getArg(u, 0) = getArg(p,0);
+                               getArg(u, 1) = getArg(r,0);
+                               getArg(u, 2) = getArg(t,0);
+                               u->typechk = TYPE_UNKNOWN;
+                               pushInstruction(mb,u);
+                               oclean[i] = 1;
+                               continue;
+                       } else if (q && getModuleId(q) == sqlRef && 
getFunctionId(q) == deltaRef) {
                                InstrPtr r = copyInstruction(p);
                                InstrPtr s = copyInstruction(p);
                                InstrPtr t = copyInstruction(p);
@@ -673,10 +711,48 @@ OPTpushselectImplementation(Client cntxt
                                continue;
                        }
                } else if (getModuleId(p) == algebraRef && getFunctionId(p) == 
projectionRef) {
+                       int id = getArg(p, 1);
+                       InstrPtr s = old[vars[id]];
                        int var = getArg(p, 2);
                        InstrPtr q = old[vars[var]];
 
-                       if (getModuleId(q) == sqlRef && getFunctionId(q) == 
deltaRef && q->argc == 5) {
+                       if (getModuleId(q) == matRef && getFunctionId(q) == 
packRef && q->argc == 3 &&
+                           getModuleId(s) == matRef && getFunctionId(s) == 
packRef && s->argc == 3) {
+                               InstrPtr r = copyInstruction(p);
+                               InstrPtr t = copyInstruction(p);
+
+                               if( r == NULL || t == NULL){
+                                       freeInstruction(r);
+                                       freeInstruction(t);
+                                       GDKfree(vars);
+                                       GDKfree(nvars);
+                                       GDKfree(slices);
+                                       GDKfree(rslices);
+                                       GDKfree(oclean);
+                                       GDKfree(old);
+                                       throw(MAL,"optimizer.pushselect", 
SQLSTATE(HY013) MAL_MALLOC_FAIL);
+                               }
+                               getArg(r, 0) = newTmpVariable(mb, 
getArgType(mb, p, 0));
+                               setVarCList(mb,getArg(r,0));
+                               getArg(r, 1) = getArg(s, 1);
+                               getArg(r, 2) = getArg(q, 1); /* column */
+                               r->typechk = TYPE_UNKNOWN;
+                               pushInstruction(mb,r);
+                               getArg(t, 0) = newTmpVariable(mb, 
getArgType(mb, p, 0));
+                               setVarCList(mb,getArg(t,0));
+                               getArg(t, 1) = getArg(s, 2);
+                               getArg(t, 2) = getArg(q, 2); /* inserts */
+                               pushInstruction(mb,t);
+
+                               InstrPtr u = copyInstruction(q); /* pack result 
*/
+                               getArg(u, 0) = getArg(p,0);
+                               getArg(u, 1) = getArg(r,0);
+                               getArg(u, 2) = getArg(t,0);
+                               u->typechk = TYPE_UNKNOWN;
+                               pushInstruction(mb,u);
+                               oclean[i] = 1;
+                               continue;
+                       } else if (getModuleId(q) == sqlRef && getFunctionId(q) 
== deltaRef && q->argc == 5) {
                                q = copyInstruction(q);
                                if( q == NULL){
                                        GDKfree(vars);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to