Changeset: 12011451e229 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=12011451e229
Modified Files:
monetdb5/optimizer/opt_partition.mx
Branch: default
Log Message:
Reduce code base to single scheme
diffs (truncated from 685 to 300 lines):
diff --git a/monetdb5/optimizer/opt_partition.mx
b/monetdb5/optimizer/opt_partition.mx
--- a/monetdb5/optimizer/opt_partition.mx
+++ b/monetdb5/optimizer/opt_partition.mx
@@ -82,127 +82,21 @@ typedef struct{
ValRecord bounds[MAXSITES];
} Slices;
-static int
-OPTinitcode(Client cntxt, MalBlkPtr mb){
- InstrPtr p;
- str s;
- str l = NULL;
-
- (void) cntxt;
-
- /* _x := remote.connect(uri,"monetdb","monetdb","msql"); */
- p = newStmt(mb, remoteRef,connectRef);
- s = GDKgetenv("merovingian_uri");
- if (s == NULL) /* aparently not under Merovingian control, fall back to
local only */
- s= "dummyconnection";
- /* SABAOTHgetLocalConnection(&l);*/
- p= pushStr(mb,p, s == NULL ? l : s);
- p= pushStr(mb,p,"monetdb");
- p= pushStr(mb,p,"monetdb");
- p= pushStr(mb,p,"msql");
- if (l)
- GDKfree(l);
- return getArg(p,0);
-}
-
static MalBlkPtr
-OPTpartitionStub(Client cntxt, MalBlkPtr mb, int pc, MalBlkPtr pmb, Slices
*slices)
-{
- MalBlkPtr smb = 0;
- Symbol s;
- InstrPtr sig, q, ret;
- int j,k,conn, *arg;
- char nme[BUFSIZ];
-
- (void) slices;
- /* define the sub query stub for remote processing */
- snprintf(nme,BUFSIZ,"%s_stub%d",getFunctionId( getInstrPtr(mb,0)), pc);
- s = newFunction(userRef, putName(nme, strlen(nme)),FUNCTIONsymbol);
- if ( s == NULL)
- return 0;
- freeMalBlk(s->def);
- s->def = copyMalBlk(pmb); /* get variables */
- smb = s->def;
- if ( newMalBlkStmt(smb,smb->ssize) < 0 )
- return 0;
- pushInstruction(smb, copyInstruction(pmb->stmt[0]));
- getFunctionId( getInstrPtr(smb,0)) = putName(nme,strlen(nme));
- insertSymbol(cntxt->nspace,s);
-
- conn = OPTinitcode(cntxt,smb);
- sig = getInstrPtr(smb,0);
- arg = (int*) GDKzalloc(sizeof(int) * sig->argc);
- /* k:= remote.put(conn,kvar) */
- for (j= sig->retc; j < sig->argc; j++) {
- q= newFcnCall(smb,remoteRef,putRef);
- setVarType(smb, getArg(q,0), TYPE_str);
- setVarUDFtype(smb, getArg(q,0));
- q= pushArgument(smb,q,conn);
- q= pushArgument(smb,q,getArg(sig,j));
- arg[j]= getArg(q,0);
- }
-
- /* (k1,...kn):= remote.exec(conn,slicing,qry,version....) */
- snprintf(nme,BUFSIZ,"%s_qry_%d",getFunctionId( getInstrPtr(mb,0)),pc);
- q = newInstruction(smb,ASSIGNsymbol);
- getModuleId(q) = remoteRef;
- getFunctionId(q) = execRef;
- q->retc= q->argc= 0;
- for (j=0; j < sig->retc; j++){
- arg[j]= newTmpVariable(smb,TYPE_str);
- q = pushReturn(smb,q,arg[j]);
- }
- q= pushArgument(smb,q,conn);
- q= pushStr(smb,q,userRef);
- q= pushStr(smb,q,putName(nme,strlen(nme)));
- /* deal with all arguments ! */
- for (j=sig->retc; j < sig->argc; j++)
- q = pushArgument(smb,q,arg[j]);
- pushInstruction(smb,q);
-
- /* return exec_qry; */
- ret = newInstruction(smb, ASSIGNsymbol);
- ret->barrier= RETURNsymbol;
- ret->argc = ret->retc = 0;
- /* l:=remote.get(conn,k) */
- for ( j=0; j< sig->retc; j++){
- q= newFcnCall(smb,remoteRef,getRef);
- q= pushArgument(smb,q,conn);
- q= pushArgument(smb,q,arg[j]);
- k= getArg(q,0);
- setVarType(smb,k, getArgType(smb,sig,j));
- setVarUDFtype(smb, k);
- ret = pushArgument(smb,ret,k);
- ret = pushReturn(smb,ret,getArg(sig,j));
- }
-
- newCatchStmt(smb, "ANYexception");
- q = newStmt(smb, remoteRef, disconnectRef);
- pushArgument(smb, q, conn);
- newRaiseStmt(smb, "ANYexception"); /* pass to caller */
- newExitStmt(smb, "ANYexception");
-
- q = newStmt(smb, remoteRef, disconnectRef);
- pushArgument(smb, q, conn);
- if ( sig->retc)
- pushInstruction(smb,ret);
- pushEndInstruction(smb);
-
- GDKfree(arg);
- return smb;
-}
-
-static MalBlkPtr
-OPTpartitionCntrl(Client cntxt, MalBlkPtr mb, int pc, MalBlkPtr pmb, Slices
*slices)
+OPTplanCntrl(Client cntxt, MalBlkPtr mb, MalBlkPtr pmb, Slices *slices)
{
MalBlkPtr cmb;
Symbol s;
char nme[BUFSIZ];
int x, i, j, k, *alias, nrpack;
- InstrPtr call, ret, p, q, *pack;
+ InstrPtr ret, p, q, *pack;
+#ifdef _DEBUG_OPT_PARTITION_
+ mnstr_printf(cntxt->fdout,"#original plan \n");
+ printFunction(cntxt->fdout, mb, 0, LIST_MAL_STMT);
+#endif
/* define the query controller */
- snprintf(nme,BUFSIZ,"%s_cntrl_%d",getFunctionId( getInstrPtr(mb,0)),pc);
+ snprintf(nme,BUFSIZ,"%s_cntrl",getFunctionId( getInstrPtr(mb,0)));
s = newFunction(userRef, putName(nme, strlen(nme)),FUNCTIONsymbol);
if ( s == NULL)
return 0;
@@ -211,12 +105,9 @@ OPTpartitionCntrl(Client cntxt, MalBlkPt
cmb = s->def;
if ( newMalBlkStmt(cmb,cmb->ssize) < 0 )
return 0;
- q= getInstrPtr(mb,pc);
- assert(q->token == ASSIGNsymbol);
- nrpack = q->retc;
+ nrpack= getInstrPtr(pmb,0)->retc;
pack = (InstrPtr *) GDKzalloc(sizeof(InstrPtr) * nrpack);
pushInstruction(cmb, copyInstruction(pmb->stmt[0]));
- call = copyInstruction(getInstrPtr(mb,0));
getFunctionId( getInstrPtr(cmb,0)) = putName(nme,strlen(nme));
insertSymbol(cntxt->nspace,s);
@@ -248,7 +139,7 @@ OPTpartitionCntrl(Client cntxt, MalBlkPt
}
pushInstruction(cmb,q);
}
- /* dataflow */
+ /* pack[i] := mat.pack(x1,...xn) */
if ( slices->column) {
p = getInstrPtr(pmb,0);
for ( k=0 ;k < nrpack ; k++){
@@ -259,27 +150,25 @@ OPTpartitionCntrl(Client cntxt, MalBlkPt
}
}
- if ( slicingLocal == 0){
- /* under dataflow control, initialize the variables */
- 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);
- }
+ /* under dataflow control, initialize the variables */
+ 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);
+ }
- /* mark start of dataflow block */
- q= newFcnCall(cmb,languageRef,dataflowRef);
- q->barrier= BARRIERsymbol;
- x = getArg(q,0);
- setVarType(cmb,x,TYPE_int);
- }
+ /* mark start of dataflow block */
+ q= newFcnCall(cmb,languageRef,dataflowRef);
+ q->barrier= BARRIERsymbol;
+ x = getArg(q,0);
+ setVarType(cmb,x,TYPE_int);
for ( i = 0; i < nrpeers ; i++) {
q= copyInstruction(getInstrPtr(pmb,0));
- q->argc = call->argc- call->retc + pmb->stmt[0]->retc;;
q->token = ASSIGNsymbol;
q->barrier = 0;
+ q->argc -= 2; /* remove the bounds */
for ( k=0 ; k < q->retc; k++) {
getArg(q,k) = newTmpVariable(cmb, getArgType(pmb,q,k));
pack[k] = pushArgument(cmb,pack[k], getArg(q,k));
@@ -295,42 +184,30 @@ OPTpartitionCntrl(Client cntxt, MalBlkPt
/* put all mat.pack instructions into the program
and make sure that they have contiguous void headed columns
*/
+ p = getInstrPtr(pmb,0);
if ( slices->column)
for ( k=0 ; k < nrpack; k++) {
pushInstruction(cmb, pack[k]);
- j = newTmpVariable(cmb,getArgType(cmb,pack[k],0));
q= newFcnCall(cmb,partitionRef,markHRef);
- getArg(q,0) = getArg(pack[k],0);
- q= pushArgument(cmb,q, j);
- getArg(pack[k],0) = j;
- pack[k] = q;
+ getArg(q,0) = getArg(p,k);
+ q= pushArgument(cmb,q, getArg(pack[k],0));
}
/* finalize the dataflow block */
- if ( slicingLocal == 0){
- q= newAssignment(cmb);
- q->barrier = EXITsymbol;
- getArg(q,0) = x;
- }
+ q= newAssignment(cmb);
+ q->barrier = EXITsymbol;
+ getArg(q,0) = x;
/* consolidate the result */
- p= getInstrPtr(mb,pc);
- q= getInstrPtr(cmb,0);
- while(q->retc > 0)
- delArgument(q,0);
- ret = newInstruction(NULL,ASSIGNsymbol);
+ ret = copyInstruction(getInstrPtr(cmb,0));
+ clrFunction(ret);
ret->barrier = RETURNsymbol;
- for( i = 0 ; i< p->retc; i++){
- cmb->stmt[0] = pushReturn(cmb, cmb->stmt[0], getArg(p,i));
- ret = pushReturn(cmb, ret, getArg(p,i));
- ret = pushArgument(cmb, ret, getArg(pack[i],0));
- }
- /* remove the splitter arguments */
- if ( slices->column){
- delArgument(q,q->argc-1);
- delArgument(q,q->argc-1);
- }
+ ret->argc = ret->retc;
+ /* make it a correct assignment to ensure ref counts */
+ for( k= 0; k< ret->retc; k++)
+ ret = pushArgument(cmb,ret,getArg(ret,k));
pushInstruction(cmb,ret);
+ getInstrPtr(cmb,0)->argc -= 2;
pushEndInstruction(cmb);
GDKfree(alias);
@@ -339,44 +216,6 @@ OPTpartitionCntrl(Client cntxt, MalBlkPt
return cmb;
}
-static char *
-OPTsliceDependency(MalBlkPtr mb, int pc)
-{
- char *vec;
- char *var;
- int i, j, fnd;
- InstrPtr p;
-
- vec= (char*) GDKzalloc(mb->ssize * 2);
- if( vec == 0)
- return 0;
- var= (char*) GDKzalloc(mb->vsize * 2);
- if ( var == 0)
- return 0;
-
- vec[0]= 1;
- p= getInstrPtr(mb,0);
- for ( i = p->retc; i < p->argc; i++)
- var[getArg(p,i)] = 1;
- p= getInstrPtr(mb,pc);
- for ( i = p->retc; i < p->argc; i++)
- var[getArg(p,i)] = 1;
- vec[pc] = 1;
- for ( i = pc -1; i >= 0; i--){
- p = getInstrPtr(mb,i);
- fnd = 0;
- for ( j = 0; j < p->argc; j++)
- fnd += var[getArg(p,j)];
- if ( fnd){
- vec[i] = 1;
- for( j = 0; j< p->argc; j++)
- var[getArg(p,j)] = 1;
- }
- }
- GDKfree(var);
- return vec;
-}
-
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list