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

Merge with Jul2012 branch.


diffs (truncated from 384 to 300 lines):

diff --git a/monetdb5/optimizer/opt_recycler.c 
b/monetdb5/optimizer/opt_recycler.c
--- a/monetdb5/optimizer/opt_recycler.c
+++ b/monetdb5/optimizer/opt_recycler.c
@@ -46,7 +46,7 @@
 #include "mal_instruction.h"
 
 static lng recycleSeq = 0;             /* should become part of MAL block 
basics */
-static bte baseTableMode = 1;  /* only recycle base tables */
+static bte baseTableMode = 0;  /* only recycle base tables */
 
 int
 OPTrecyclerImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
p)
@@ -62,151 +62,154 @@ OPTrecyclerImplementation(Client cntxt, 
        (void) cntxt;
        (void) stk;
 
-       limit= mb->stop;
+       limit = mb->stop;
        old = mb->stmt;
 
-       for (i = 1; i<limit; i++) {
+       for (i = 1; i < limit; i++) {
                p = old[i];
-               if (getModuleId(p)==sqlRef &&
-            (getFunctionId(p) == affectedRowsRef ||
-              getFunctionId(p) == exportOperationRef ||
-              getFunctionId(p) == appendRef ||
-              getFunctionId(p) == updateRef ||
-              getFunctionId(p) == deleteRef) )
+               if (getModuleId(p) == sqlRef &&
+                               (getFunctionId(p) == affectedRowsRef ||
+                                getFunctionId(p) == exportOperationRef ||
+                                getFunctionId(p) == appendRef ||
+                                getFunctionId(p) == updateRef ||
+                                getFunctionId(p) == deleteRef))
                        updstmt = 1;
        }
 
        span = setLifespan(mb);
-       if ( span == NULL)
+       if (span == NULL)
                return 0;
 
        /* watch out, newly created instructions may introduce new variables */
-       recycled= GDKzalloc(sizeof(char)*mb->vtop * 2);
-       if ( recycled == NULL)
+       recycled = GDKzalloc(sizeof(char) * mb->vtop * 2);
+       if (recycled == NULL)
                return 0;
-       if ( newMalBlkStmt(mb, mb->ssize) < 0){
+       if (newMalBlkStmt(mb, mb->ssize) < 0) {
                GDKfree(recycled);
                return 0;
        }
-       pushInstruction(mb,old[0]);
+       pushInstruction(mb, old[0]);
        mb->recid = recycleSeq++;
 
        /* create a handle for recycler */
-       (void) newFcnCall(mb,"recycle","prelude");
+       (void) newFcnCall(mb, "recycle", "prelude");
        in = 1;
-       for (i = 1; i<limit; i++) {
+       for (i = 1; i < limit; i++) {
                p = old[i];
-               if (hasSideEffects(p,TRUE) || isUpdateInstruction(p) || 
isUnsafeFunction(p)){
-                       if( getModuleId(p)== recycleRef ){ /*don't inline 
recycle instr. */
+               if (hasSideEffects(p, TRUE) || isUpdateInstruction(p) || 
isUnsafeFunction(p)) {
+                       if (getModuleId(p) == recycleRef) { /*don't inline 
recycle instr. */
                                freeInstruction(p);
                                continue;
                        }
-                       pushInstruction(mb,p);
-                               /*  update instructions are not recycled but 
monitored*/
-                       if( isUpdateInstruction(p)){
+                       pushInstruction(mb, p);
+                       /*  update instructions are not recycled but monitored*/
+                       if (isUpdateInstruction(p)) {
                                if (getModuleId(p) == batRef &&
-                                       (getArgType(mb,p,1)==TYPE_bat
-                                       || isaBatType(getArgType(mb, p,1)))){
-                                       recycled[getArg(p,1)]= 0;
-                                       q= newFcnCall(mb,"recycle","reset");
-                                       pushArgument(mb,q, getArg(p,1));
+                                       (getArgType(mb, p, 1) == TYPE_bat
+                                        || isaBatType(getArgType(mb, p, 1)))) {
+                                       recycled[getArg(p, 1)] = 0;
+                                       q = newFcnCall(mb, "recycle", "reset");
+                                       pushArgument(mb, q, getArg(p, 1));
                                        actions++;
                                }
-                               if (getModuleId(p) == sqlRef){
-                                       if (getFunctionId(p) == appendRef ){
-                                               if ( app_sc >= 0 )
+                               if (getModuleId(p) == sqlRef) {
+                                       if (getFunctionId(p) == appendRef) {
+                                               if (app_sc >= 0)
                                                        continue;
-                                               else app_sc = getArg(p,2);
+                                               else
+                                                       app_sc = getArg(p, 2);
                                        }
-                                       VALset(&cst,TYPE_int,&delta);
+                                       VALset(&cst, TYPE_int, &delta);
                                        c = defConstant(mb, TYPE_int, &cst);
-                                       q = newFcnCall(mb,"recycle","reset");
-                                       pushArgument(mb,q,c);
-                                       pushArgument(mb,q, getArg(p,2));
-                                       pushArgument(mb,q, getArg(p,3));
+                                       q = newFcnCall(mb, "recycle", "reset");
+                                       pushArgument(mb, q, c);
+                                       pushArgument(mb, q, getArg(p, 2));
+                                       pushArgument(mb, q, getArg(p, 3));
                                        if (getFunctionId(p) == updateRef)
-                                               pushArgument(mb,q, getArg(p,4));
+                                               pushArgument(mb, q, getArg(p, 
4));
                                        actions++;
                                }
                        }
                        /* take care of SQL catalog update instructions */
-                       if (getModuleId(p) == sqlRef && getFunctionId(p) == 
catalogRef ){
-                               tp = *(int*) getVarValue(mb,getArg(p,1)); 
+                       if (getModuleId(p) == sqlRef && getFunctionId(p) == 
catalogRef) {
+                               tp = *(int *) getVarValue(mb, getArg(p, 1));
                                if (tp == 22 || tp == 25) {
-                                       delta = 2; 
-                                       VALset(&cst,TYPE_int,&delta);
+                                       delta = 2;
+                                       VALset(&cst, TYPE_int, &delta);
                                        c = defConstant(mb, TYPE_int, &cst);
-                                       q = newFcnCall(mb,"recycle","reset");
-                                       pushArgument(mb,q,c);
-                                       pushArgument(mb,q, getArg(p,2));
-                                       if ( tp == 25 )
-                                               pushArgument(mb,q, getArg(p,3));
+                                       q = newFcnCall(mb, "recycle", "reset");
+                                       pushArgument(mb, q, c);
+                                       pushArgument(mb, q, getArg(p, 2));
+                                       if (tp == 25)
+                                               pushArgument(mb, q, getArg(p, 
3));
                                        actions++;
                                }
                        }
                        continue;
                }
-               if( p->token == ENDsymbol || p->barrier == RETURNsymbol ){ 
-                       if ( in ){
-                       /*      if ( updstmt && app_sc >= 0 ){
-                                       q= newFcnCall(mb,"recycle","reset");
-                                       pushArgument(mb,q, app_sc);
-                                       pushArgument(mb,q, app_tbl);
+               if (p->token == ENDsymbol || p->barrier == RETURNsymbol) {
+                       if (in) {
+                               /*
+                               if (updstmt && app_sc >= 0) {
+                                       q = newFcnCall(mb, "recycle", "reset");
+                                       pushArgument(mb, q, app_sc);
+                                       pushArgument(mb, q, app_tbl);
                                }
-                       */      (void) newFcnCall(mb,"recycle","epilogue");
+                                */
+                               (void) newFcnCall(mb, "recycle", "epilogue");
                                in = 0;
                        }
-                       pushInstruction(mb,p);
+                       pushInstruction(mb, p);
                        continue;
-               } 
+               }
 
-               if (p->barrier  && p->token != CMDcall){
+               if (p->barrier && p->token != CMDcall) {
                        /* never save a barrier unless it is a command and 
side-effect free */
-                       pushInstruction(mb,p);
+                       pushInstruction(mb, p);
                        continue;
                }
 
                /* don't change instructions in update statements */
-               if( updstmt){
-                       pushInstruction(mb,p);
+               if (updstmt) {
+                       pushInstruction(mb, p);
                        continue;
-               } 
+               }
 
                /* skip simple assignments */
-               if( p->token == ASSIGNsymbol){
-                       pushInstruction(mb,p);
+               if (p->token == ASSIGNsymbol) {
+                       pushInstruction(mb, p);
                        continue;
-               } 
+               }
 
-               if (getModuleId(p) == octopusRef && 
-                        ( getFunctionId(p) == bindRef || getFunctionId(p) == 
bindidxRef) ) {
-                               recycled[getArg(p,0)] = 1;
-                               p->recycle = recycleMaxInterest; 
-                               marks++;
+               if (getModuleId(p) == octopusRef &&
+                       (getFunctionId(p) == bindRef || getFunctionId(p) == 
bindidxRef)) {
+                       recycled[getArg(p, 0)] = 1;
+                       p->recycle = recycleMaxInterest;
+                       marks++;
                }
                /* During base table recycling skip marking instructions other 
than octopus.bind */
-               if( baseTableMode ){
-                       pushInstruction(mb,p);
+               if (baseTableMode) {
+                       pushInstruction(mb, p);
                        continue;
-               } 
+               }
 
-               /* general rule: all arguments are constants or recycled, 
-               ignore C pointer arguments from mvc*/
+               /* general rule: all arguments are constants or recycled,
+                  ignore C pointer arguments from mvc */
                cnt = 0;
-               for (j=p->retc; j<p->argc; j++)
-                       if( recycled[getArg(p,j)] || isVarConstant(mb, 
getArg(p,j))
-                               || ignoreVar(mb, getArg(p,j)) )
+               for (j = p->retc; j < p->argc; j++)
+                       if (recycled[getArg(p, j)] || isVarConstant(mb, 
getArg(p, j))
+                                       || ignoreVar(mb, getArg(p, j)))
                                cnt++;
-               if (cnt == p->argc-p->retc) {
-               OPTDEBUGrecycle {
-                       mnstr_printf(cntxt->fdout,"#recycle instruction\n");
-                       printInstruction(cntxt->fdout,mb, 0, p,LIST_MAL_ALL);
-               }
+               if (cnt == p->argc - p->retc) {
+                       OPTDEBUGrecycle {
+                               mnstr_printf(cntxt->fdout, "#recycle 
instruction\n");
+                               printInstruction(cntxt->fdout, mb, 0, p, 
LIST_MAL_ALL);
+                       }
                        marks++;
                        p->recycle = recycleMaxInterest; /* this instruction is 
to be monitored */
-                       for (j= 0; j < p->retc; j++)
-                               if (getLastUpdate(span, getArg(p,j)) == i)
-                                       recycled[getArg(p,j)] = 1;
+                       for (j = 0; j < p->retc; j++)
+                               if (getLastUpdate(span, getArg(p, j)) == i)
+                                       recycled[getArg(p, j)] = 1;
                }
                /*
                 * The expected gain is largest if we can re-use selections
@@ -219,66 +222,83 @@ OPTrecyclerImplementation(Client cntxt, 
                 */
                /* take care of semantic driven recyling */
                /* for selections check the bat argument only
-               the range is often template parameter*/
-               if(( getFunctionId(p)== selectRef || 
-                    getFunctionId(p)== antiuselectRef ||
-                    getFunctionId(p)== likeselectRef ||
-                    getFunctionId(p)== likeRef || 
-                getFunctionId(p)== thetaselectRef ) &&
-                recycled[getArg(p,1)] ){
+                  the range is often template parameter*/
+               if ((getFunctionId(p) == selectRef ||
+                                       getFunctionId(p) == antiuselectRef ||
+                                       getFunctionId(p) == likeselectRef ||
+                                       getFunctionId(p) == likeRef ||
+                                       getFunctionId(p) == thetaselectRef) &&
+                               recycled[getArg(p, 1)])
+               {
                        p->recycle = recycleMaxInterest;
-                       marks ++;
-                       if (getLastUpdate(span, getArg(p,0)) == i)
-                               recycled[getArg(p,0)] = 1;
+                       marks++;
+                       if (getLastUpdate(span, getArg(p, 0)) == i)
+                               recycled[getArg(p, 0)] = 1;
                }
-               if( ( getFunctionId(p) == uselectRef || getFunctionId(p) == 
thetauselectRef)
-                       && recycled[getArg(p,1)]) {
-                       if (!ATOMvarsized( getGDKType( getArgType(mb,p,2)))) { 
+               if ((getFunctionId(p) == uselectRef || getFunctionId(p) == 
thetauselectRef)
+                               && recycled[getArg(p, 1)])
+               {
+                       if (!ATOMvarsized(getGDKType(getArgType(mb, p, 2)))) {
                                q = copyInstruction(p);
-                               getArg(q,0)= newTmpVariable(mb,TYPE_any); 
-                               if ( getFunctionId(p) == uselectRef )
-                                       setFunctionId(q, selectRef); 
-                               else setFunctionId(q, thetaselectRef); 
+                               getArg(q, 0) = newTmpVariable(mb, TYPE_any);
+                               if (getFunctionId(p) == uselectRef)
+                                       setFunctionId(q, selectRef);
+                               else
+                                       setFunctionId(q, thetaselectRef);
                                q->recycle = recycleMaxInterest;
                                marks++;
-                               recycled[getArg(q,0)] = 1;
-                               pushInstruction(mb,q);
-                               getArg(p,1) = getArg(q,0);
-                               setFunctionId(p,projectRef);
+                               recycled[getArg(q, 0)] = 1;
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to