Changeset: 7791d762b01b for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7791d762b01b Modified Files: monetdb5/optimizer/opt_commonTerms.mx Branch: default Log Message:
Better match statements with constants The optimizer built a list based on the last argument in each call. Mostly this is a variable with limited re-use. However, when it is a constant value, then there may be another version of it in the symbol table with a different varid. This means, that two instruction that match on value were not recognized. The solution is to keep a single list for all constants and try the out all. This is based on the assumption that the number of constants is mostly limited. It solves the repeatitive occurrences of sql.binds. diffs (51 lines): diff --git a/monetdb5/optimizer/opt_commonTerms.mx b/monetdb5/optimizer/opt_commonTerms.mx --- a/monetdb5/optimizer/opt_commonTerms.mx +++ b/monetdb5/optimizer/opt_commonTerms.mx @@ -35,6 +35,7 @@ @:exportOptimizer(commonTerms)@ +/* #define DEBUG_OPT_COMMONTERMS_MORE */ #define OPTDEBUGcommonTerms if ( optDebug & (1 <<DEBUG_OPT_COMMONTERMS) ) #endif @@ -115,6 +116,9 @@ int *alias; InstrPtr *old; int *list; + /* link all final constant expressions in a list */ + /* it will help to find duplicate sql.bind calls */ + int cstlist=0; int *vars; (void) cntxt; @@ -147,10 +151,15 @@ if ( alias[getArg(p,k)] ) getArg(p,k) = alias[getArg(p,k)]; - /* Link the statement to the previous use, based on the first argument.*/ + /* Link the statement to the previous use, based on the last argument.*/ if ( p->retc < p->argc ) { candidate = vars[getArg(p,p->argc-1)]; - list[i]= vars[ getArg(p,p->argc-1) ]; + if ( isVarConstant(mb, getArg(p,p->argc-1)) ){ + /* all instructions with constant tail are linked */ + list[i] = cstlist; + cstlist = i; + } else + list[i]= vars[ getArg(p,p->argc-1) ]; vars[getArg(p,p->argc-1)] = i; } else candidate = 0; @@ -188,8 +197,10 @@ printInstruction(cntxt->fdout, mb, 0, p, LIST_MAL_ALL); #endif prop = hasSideEffects(p,TRUE) || isUpdateInstruction(p); + j = isVarConstant(mb, getArg(p,p->argc-1))? cstlist: candidate; + if ( !prop) - for (j = candidate; j ; j = list[j]) + for (; j ; j = list[j]) if ( (q=getInstrPtr(mb,j))->fcn == p->fcn && !isUnsafeFunction(q)){ #ifdef DEBUG_OPT_COMMONTERMS_MORE mnstr_printf(cntxt->fdout,"#CANDIDATE %d, %d %d %d ", i, j, _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list