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

Got simple grouping working again


diffs (truncated from 634 to 300 lines):

diff --git a/monetdb5/optimizer/opt_centipede.c 
b/monetdb5/optimizer/opt_centipede.c
--- a/monetdb5/optimizer/opt_centipede.c
+++ b/monetdb5/optimizer/opt_centipede.c
@@ -34,10 +34,10 @@
 #define DEBUG_OPT_DETAIL
 #define _DEBUG_OPT_CENTIPEDE_ 
 
-#define BLOCKED 1
-#define PARTITION 2     // phase 1 result
-#define PIVOT    3     // Instruction requires care at next level
-#define SUPPORTIVE 4   // phase 2 result
+#define BLOCKED 1      // Instruction should remain in main routine
+#define PARTITION 2    // Instruction is part of the fragment routine
+#define PIVOT    3     // Instruction is part of the consolidation routine
+#define SUPPORTIVE 4// Instruction is part of fragment routine
 
 /*
  * The columns are broken using fixed OID ranges.
@@ -59,7 +59,7 @@ static int nrservers;
  * geared at parallel execution 
 */
 static MalBlkPtr
-OPTexecController(Client cntxt, MalBlkPtr mb, MalBlkPtr pmb, InstrPtr ret, 
Slices *slices, oid plantag, int *status)
+OPTexecController(Client cntxt, MalBlkPtr mb, MalBlkPtr pmb, InstrPtr ret, 
InstrPtr packs, Slices *slices, oid plantag, int *status)
 {
        MalBlkPtr cmb;
        Symbol s;
@@ -67,6 +67,7 @@ OPTexecController(Client cntxt, MalBlkPt
        int barrier, x, i, j, k, *alias, nrpack;
        InstrPtr p, q, *pack;
 
+       (void) p;
        /* define the query controller */
        //snprintf(nme, BUFSIZ, "%s_plan"OIDFMT, getFunctionId( 
getInstrPtr(mb,0)), plantag);
        //putName(nme, strlen(nme));
@@ -132,19 +133,10 @@ OPTexecController(Client cntxt, MalBlkPt
                        pack[k] = newInstruction(cmb,ASSIGNsymbol);
                        getModuleId(pack[k]) = matRef;
                        getFunctionId(pack[k]) = packRef;
-                       getArg(pack[k],0) = getArg(p,k); 
+                       getArg(pack[k],0) = getArg(packs,k); 
                }
        }
 
-       /* under dataflow control, initialize the variables 
-          Arguments are considered defined already */
-       for ( k=0 ; k < nrpack ; k++){
-               q = newInstruction(cmb,ASSIGNsymbol);
-               getArg(q,0) = getArg(pack[k],0);
-               pushNil(cmb,q, getArgType(cmb,pack[k],0));
-               pushInstruction(cmb,q);
-       }
-
 #ifdef REMOTE_EXECUTION
        q= newFcnCall(cmb,schedulerRef,srvpoolRef);
 #else
@@ -197,46 +189,36 @@ OPTexecController(Client cntxt, MalBlkPt
        if ( slices->column) {
                for ( k=0 ; k < nrpack; k++) {
                        /* after packing we may have to re-do groupings*/
+                       int z;
                        pushInstruction(cmb, pack[k]);
-                       setVarUsed(cmb,getArg(pack[k],0));
+                       setVarUsed(cmb, z = getArg(pack[k],0));
+                       //setVarType(cmb,z, 
newBatType(TYPE_oid,getTailType(getVarType(cmb,z))) );
                }
        }
 
-       /* finalize the dataflow block */
-       q= newAssignment(cmb);
-       q->barrier = EXITsymbol;
-       getArg(q,0) = barrier;
-
        (void) status;
        /* look for pivot operations in original plan */
        for ( i=1; i < mb->stop; i++)
        if (status[i] == PIVOT){
+               char buf[BUFSIZ];
                q= copyInstruction(getInstrPtr(mb,i));
 #ifdef _DEBUG_OPT_CENTIPEDE_
-       if ( status[i]){
-               mnstr_printf(cntxt->fdout,"\n#cmb include stmt %d status 
%d\n",i,status[i]);
-               printInstruction(cntxt->fdout, mb, 0, q,LIST_MAL_STMT);
-       }
+               if ( status[i]){
+                       mnstr_printf(cntxt->fdout,"\n#cmb include stmt %d 
status %d\n",i,status[i]);
+                       printInstruction(cntxt->fdout, mb, 0, q,LIST_MAL_STMT);
+               }
 #endif
-/*
-                       for( j= q->retc; j<q->argc; j++){
-                               int idx;
-                               InstrPtr pq;
-                               snprintf(nme,BUFSIZ,"C_%d",getArg(q,j));
-                               idx= findVariable(pmb,nme);
-                               if ( idx >= 0)
-                                       getArg(q,j) = idx;
-
-                               pq= getInstrPtr(cmb,0);
-                               for ( k = 0; k< pq->retc; k++)
-                               if (getArg(pq,k) == getArg(q, q->retc)){
-                                       delArgument(pq,k);
-                                       break;
-                               }
-                       }
-*/
                if (getModuleId(q) == groupRef && (getFunctionId(q) == 
subgroupRef || getFunctionId(q) == subgroupdoneRef)){
+                       snprintf(buf,BUFSIZ,"Y_%d",getArg(q,q->retc));
                        q= copyInstruction(q);
+                       getArg(q,q->retc) = findVariable(cmb,buf);
+                       pushInstruction(cmb,q);
+               } else
+               if (getModuleId(q) == aggrRef && getFunctionId(q) == countRef ){
+                       q= copyInstruction(q);
+                       getFunctionId(q) = sumRef;
+                       // correct the return statement
+                       setVarType(cmb, getArg(q,1), newBatType(TYPE_oid, 
TYPE_wrd));
                        pushInstruction(cmb,q);
                } else
                if (getModuleId(q) == aggrRef && getFunctionId(q) == 
subcountRef ){
@@ -249,13 +231,24 @@ OPTexecController(Client cntxt, MalBlkPt
                if (getModuleId(q) == aggrRef && (getFunctionId(q)==subsumRef 
|| getFunctionId(q) == subminRef ||
                        getFunctionId(q) == submaxRef || getFunctionId(q) == 
subavgRef)){
                        q= copyInstruction(q);
-                       getArg(q,1) = getArg(q,0);
+                       //getArg(q,1) = getArg(q,0);
+                       pushInstruction(cmb,q);
+               } else
+               if (getModuleId(q) == algebraRef && getFunctionId(q) == 
leftfetchjoinRef ){
+                       snprintf(buf,BUFSIZ,"Y_%d",getArg(q,q->argc-1));
+                       q= copyInstruction(q);
+                       getArg(q,q->argc-1) = findVariable(cmb,buf);
                        pushInstruction(cmb,q);
                } else{
                        q= copyInstruction(q);
                        pushInstruction(cmb,q);
                }
        }
+       /* finalize the dataflow block */
+       q= newAssignment(cmb);
+       q->barrier = EXITsymbol;
+       getArg(q,0) = barrier;
+
 
        /* consolidate the result of the control function */
        ret = copyInstruction(ret);
@@ -459,6 +452,21 @@ OPTsliceColumn(Client cntxt, MalBlkPtr n
  * when a connection is re-used by different client sessions.
 */
 
+static void addvartolist(MalBlkPtr mb, InstrPtr *pq, int arg)
+{
+       int k;
+       InstrPtr p = *pq;
+
+       for ( k = 0; k < p->retc; k++)
+       if (getArg(p,k) == arg)
+               break;
+       if ( k == p->retc){
+               p = pushReturn(mb, p, arg);
+               //p = pushArgument(mb, p, arg);
+       }
+       *pq = p;
+}
+
 #ifdef _DEBUG_OPT_CENTIPEDE_ 
 static char *statusname[7]= {"", "blocked   ", "partition ", "pivot     ", 
"support   ", "exported ", "keeplocal "};
 #endif
@@ -468,7 +476,7 @@ OPTbakePlans(Client cntxt, MalBlkPtr mb,
 {
        int *status,*vars;
        int i, j, k, limit, last;
-       InstrPtr ret, orig, planargs= 0, call, q = NULL, p = NULL, *old;
+       InstrPtr cntrlreturn, planreturn, orig, packs= 0, call, q = NULL, p = 
NULL, *old;
        Symbol s;
        MalBlkPtr plan, cntrl, stub;
        str msg= MAL_SUCCEED;
@@ -534,11 +542,7 @@ OPTbakePlans(Client cntxt, MalBlkPtr mb,
                                vars[getArg(p,0)] = PARTITION;
                } else
                if ( getModuleId(p) == sqlRef && getFunctionId(p) == deltaRef ){
-                       // Use a readonly view on the database TO BE FIXED
-                       //clrFunction(p);
-                       //p->argc =2;
-                       //p->token = ASSIGNsymbol;
-                       if ( vars[getArg(p,1)] ){
+                       if ( vars[getArg(p,1)] == PARTITION ){
                                status[i] = PARTITION;
                                vars[getArg(p,0)] = PARTITION;
                        }
@@ -546,65 +550,74 @@ OPTbakePlans(Client cntxt, MalBlkPtr mb,
 
                /* blocking instructions are those that require data exchange, 
aggregation or total view */
                if ( getModuleId(p) == algebraRef && (getFunctionId(p) == 
joinRef || getFunctionId(p) == leftjoinRef || getFunctionId(p) == 
leftfetchjoinRef) ) {
-                       if ( vars[getArg(p,p->retc)] || 
vars[getArg(p,p->retc+1)] ){
+                       if ( vars[getArg(p,p->retc)] == PARTITION ){
                                status[i] = PARTITION;
                                vars[getArg(p,0)] = PARTITION;
                        } 
+                       if ( vars[getArg(p,p->retc)] == PIVOT ){
+                               status[i] = PIVOT;
+                               vars[getArg(p,0)] = PIVOT;
+                       } 
                } else
                if ( getModuleId(p) == algebraRef && (getFunctionId(p)== 
thetaselectRef  || getFunctionId(p) == selectRef || getFunctionId(p) == 
subselectRef)){
-                       if ( vars[getArg(p,p->retc)] ){
+                       if ( vars[getArg(p,p->retc)] == PARTITION ){
                                status[i] = PARTITION;
                                vars[getArg(p,0)] = PARTITION;
                        }
                } else
                if (    getModuleId(p) == batRef && getFunctionId(p) == 
mirrorRef )  {
-                       if ( vars[getArg(p,p->retc)] ){
+                       if ( vars[getArg(p,p->retc)] == PARTITION ){
                                status[i] = PARTITION;
                                vars[getArg(p,0)] = PARTITION;
                        }
                } else
                if (    getModuleId(p) == batRef && 
getFunctionId(p)==reverseRef )  {
-                       if ( vars[getArg(p,p->retc)] ){
+                       if ( vars[getArg(p,p->retc)] == PARTITION ){
                                status[i] = PARTITION;
                                vars[getArg(p,0)] = PARTITION;
                        }
                } else
+               if ( getModuleId(p) == aggrRef  && getFunctionId(p) == 
countRef) {
+                       if( vars[getArg(p,p->retc)] == PARTITION ) {
+                               vars[getArg(p,0)] = PIVOT;
+                               status[i]= PIVOT;
+                       }
+               } else
                if ( getModuleId(p) == aggrRef && (getFunctionId(p) == 
subcountRef || getFunctionId(p) == subsumRef ||
                        getFunctionId(p) == subminRef || getFunctionId(p) == 
submaxRef || getFunctionId(p) == subavgRef )){
-                       if (vars[getArg(p,p->retc)] ){
+                       if (vars[getArg(p,p->retc)] == PARTITION || 
vars[getArg(p,p->retc)] == PIVOT ){
                                status[i] = PIVOT;
                                for(j = 0; j < p->argc; j++)
-                               if ( vars[getArg(p,j)] ==0)
                                        vars[getArg(p,j)] = PIVOT;
                        }
                } else
                if ( getModuleId(p) == groupRef && ( getFunctionId(p) == 
subgroupRef || getFunctionId(p) == subgroupdoneRef) && p->retc== 3){
-                       if ( vars[getArg(p,p->retc)] ){
+                       if ( vars[getArg(p,p->retc)]== PARTITION ){
                                status[i] = PIVOT;
-                               for(j = 0; j < p->argc; j++)
-                               if ( vars[getArg(p,j)] ==0)
+                               for(j = 0; j < p->retc; j++)
                                        vars[getArg(p,j)] = PIVOT;
                        }
                } else
-               if ((getModuleId(p) == sqlRef && (getFunctionId(p) == 
resultSetRef || getFunctionId(p) == putName("exportValue",11))) || 
getModuleId(p) == ioRef )
+               if ((getModuleId(p) == sqlRef && (getFunctionId(p) == 
resultSetRef || getFunctionId(p) == putName("exportValue",11))) || 
getModuleId(p) == ioRef ){
                        status[i] = BLOCKED;
-               else 
+                       vars[getArg(p,0)] = BLOCKED;
+               } else 
                if ( getModuleId(p) == batcalcRef ){
-                       if ( vars[getArg(p,p->retc)] || 
vars[getArg(p,p->retc+1)] ){
+                       if ( vars[getArg(p,p->retc)] == PARTITION || 
vars[getArg(p,p->retc+1)] == PARTITION ){
                                status[i] = PARTITION;
                                vars[getArg(p,0)] = PARTITION;
                        }
                } else 
                if ( getModuleId(p) == algebraRef && getFunctionId(p) == 
subsliceRef ){
-                       if ( vars[getArg(p,1)] == PARTITION || 
vars[getArg(p,1)] == PIVOT){
+                       if ( vars[getArg(p,1)] == PARTITION ){
                                status[i] = BLOCKED;
                                vars[getArg(p,0)] = BLOCKED;
                        }
                } else
                if ( getModuleId(p) == pqueueRef && getFunctionId(p) == 
utopn_minRef ){
-                       if ( vars[getArg(p,1)] == PARTITION || 
vars[getArg(p,1)] == PIVOT){
-                               status[i] = BLOCKED;
-                               vars[getArg(p,0)] = BLOCKED;
+                       if ( vars[getArg(p,1)] == PARTITION ){
+                               status[i] = PIVOT;
+                               vars[getArg(p,0)] = PIVOT;
                        }
                } else
                if ( getModuleId(p) == algebraRef && (getFunctionId(p) == 
subsortRef || getFunctionId(p) == sortRef || getFunctionId(p)== tinterRef) ) {
@@ -622,42 +635,28 @@ OPTbakePlans(Client cntxt, MalBlkPtr mb,
                        }
                } else
                if (    getModuleId(p) == batRef && getFunctionId(p)==appendRef 
)  {
-                       if ( vars[getArg(p,p->retc)] == PARTITION)
+                       if ( vars[getArg(p,p->retc)] == PARTITION){
                                status[i] = BLOCKED;
-                       for(j=0; status[i] == BLOCKED &&  j < p->retc; j++)
-                               vars[getArg(p,j)] = BLOCKED;
-               } else
-               if ( getModuleId(p) == aggrRef ) {
-                       status[i] = BLOCKED;
-                       for(j=0; j < p->retc; j++)
-                               vars[getArg(p,j)] = BLOCKED;
-               }
+                               for(j=0; j < p->retc; j++)
+                                       vars[getArg(p,j)] = BLOCKED;
+                       }
+               } 
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to