Changeset: cd64e25b9540 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cd64e25b9540 Modified Files: monetdb5/optimizer/opt_matpack.c monetdb5/optimizer/opt_mergetable.c monetdb5/optimizer/opt_mitosis.c monetdb5/optimizer/opt_reorder.c monetdb5/optimizer/opt_support.c monetdb5/optimizer/opt_support.h Branch: default Log Message:
Implement optimizer dependency check diffs (251 lines): diff --git a/monetdb5/optimizer/opt_matpack.c b/monetdb5/optimizer/opt_matpack.c --- a/monetdb5/optimizer/opt_matpack.c +++ b/monetdb5/optimizer/opt_matpack.c @@ -24,6 +24,10 @@ OPTmatpackImplementation(Client cntxt, M lng usec = GDKusec(); str msg = MAL_SUCCEED; + if( isOptimizerUsed(mb, "mergetable") <= 0){ + goto wrapup; + } + //if ( !optimizerIsApplied(mb,"multiplex") ) //return 0; (void) pci; diff --git a/monetdb5/optimizer/opt_mergetable.c b/monetdb5/optimizer/opt_mergetable.c --- a/monetdb5/optimizer/opt_mergetable.c +++ b/monetdb5/optimizer/opt_mergetable.c @@ -1878,6 +1878,8 @@ OPTmergetableImplementation(Client cntxt lng usec = GDKusec(); str msg = MAL_SUCCEED; + if( isOptimizerUsed(mb,"mitosis") <= 0) + goto cleanup2; //if( optimizerIsApplied(mb, "mergetable") || !optimizerIsApplied(mb,"mitosis")) //return 0; old = mb->stmt; @@ -2372,6 +2374,7 @@ cleanup: if (!msg) msg = chkDeclarations(mb); } +cleanup2: /* keep all actions taken as a post block comment */ usec = GDKusec()- usec; snprintf(buf,256,"%-20s actions=%2d time=" LLFMT " usec","mergetable",actions, usec); diff --git a/monetdb5/optimizer/opt_mitosis.c b/monetdb5/optimizer/opt_mitosis.c --- a/monetdb5/optimizer/opt_mitosis.c +++ b/monetdb5/optimizer/opt_mitosis.c @@ -41,8 +41,10 @@ OPTmitosisImplementation(Client cntxt, M isVarConstant(mb, getArg(p, 2)) && getVarConstant(mb, getArg(p, 2)).val.sval != NULL && (strstr(getVarConstant(mb, getArg(p, 2)).val.sval, "PRIMARY KEY constraint") || - strstr(getVarConstant(mb, getArg(p, 2)).val.sval, "UNIQUE constraint"))) + strstr(getVarConstant(mb, getArg(p, 2)).val.sval, "UNIQUE constraint"))){ + pieces = 0; goto bailout; + } /* mitosis/mergetable bailout conditions */ @@ -59,8 +61,10 @@ OPTmitosisImplementation(Client cntxt, M getFunctionId(p) != maxRef && getFunctionId(p) != avgRef && getFunctionId(p) != sumRef && - getFunctionId(p) != prodRef) - goto bailout; + getFunctionId(p) != prodRef){ + pieces = 0; + goto bailout; + } /* do not split up floating point bat that is being summed */ if (p->retc == 1 && @@ -72,16 +76,22 @@ OPTmitosisImplementation(Client cntxt, M getFunctionId(p) == sumRef)) && isaBatType(getArgType(mb, p, p->retc)) && (getBatType(getArgType(mb, p, p->retc)) == TYPE_flt || - getBatType(getArgType(mb, p, p->retc)) == TYPE_dbl)) - goto bailout; + getBatType(getArgType(mb, p, p->retc)) == TYPE_dbl)){ + pieces = 0; + goto bailout; + } if (p->argc > 2 && (getModuleId(p) == capiRef || getModuleId(p) == rapiRef || getModuleId(p) == pyapi3Ref) && - getFunctionId(p) == subeval_aggrRef) - goto bailout; + getFunctionId(p) == subeval_aggrRef){ + pieces = 0; + goto bailout; + } /* Mergetable cannot handle intersect/except's for now */ - if (getModuleId(p) == algebraRef && getFunctionId(p) == groupbyRef) + if (getModuleId(p) == algebraRef && getFunctionId(p) == groupbyRef){ + pieces = 0; goto bailout; + } /* locate the largest non-partitioned table */ if (getModuleId(p) != sqlRef || (getFunctionId(p) != bindRef && getFunctionId(p) != bindidxRef)) @@ -106,8 +116,10 @@ OPTmitosisImplementation(Client cntxt, M r = 0; } } - if (target == 0) + if (target == 0){ + pieces = 0; goto bailout; + } /* * The number of pieces should be based on the footprint of the * queryplan, such that preferrably it can be handled without @@ -174,8 +186,10 @@ OPTmitosisImplementation(Client cntxt, M if (mito_size > 0) pieces = (int) ((rowcnt * row_size) / (mito_size * 1024)); - if (pieces <= 1) + if (pieces <= 1){ + pieces = 0; goto bailout; + } /* at this stage we have identified the #chunks to be used for the largest table */ limit = mb->stop; diff --git a/monetdb5/optimizer/opt_reorder.c b/monetdb5/optimizer/opt_reorder.c --- a/monetdb5/optimizer/opt_reorder.c +++ b/monetdb5/optimizer/opt_reorder.c @@ -27,6 +27,7 @@ * by giving preference to variables that are too far * away in the plan from their source. It is however not * explored. + * The reorder is only executed if the mergetable produced results. * * The secondary approach is to pull instructions to the * head of the plan if the dataflow such permits. @@ -274,7 +275,9 @@ OPTreorderImplementation(Client cntxt, M char buf[256]; lng usec= GDKusec(); str msg = MAL_SUCCEED; - + if( isOptimizerUsed(mb, "mergetable") <= 0){ + goto wrapup; + } (void) cntxt; (void) stk; dep = OPTdependencies(cntxt,mb,&uselist); @@ -332,6 +335,7 @@ OPTreorderImplementation(Client cntxt, M OPTremoveDep(dep, limit); GDKfree(uselist); GDKfree(old); +wrapup: (void) OPTpostponeAppends(cntxt, mb, 0, 0); /* Defense line against incorrect plans */ diff --git a/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c --- a/monetdb5/optimizer/opt_support.c +++ b/monetdb5/optimizer/opt_support.c @@ -18,7 +18,7 @@ #include "optimizer_private.h" #include "manifold.h" -/* some optimizers can only be applied once. +/* Some optimizers can/need only be applied once. * The optimizer trace at the end of the MAL block * can be used to check for this. */ @@ -35,6 +35,59 @@ optimizerIsApplied(MalBlkPtr mb, str opt return 0; } +/* + * Some optimizers are interdependent (e.g. mitosis ), which + * requires inspection of the pipeline attached to a MAL block. + */ +int +isOptimizerEnabled(MalBlkPtr mb, str opt) +{ + int i; + InstrPtr q; + + for (i= mb->stop-1; i > 0; i--){ + q= getInstrPtr(mb,i); + if ( q->token == ENDsymbol) + break; + if ( getModuleId(q) == optimizerRef && getFunctionId(q) == opt) + return 1; + } + return 0; +} + +/* + * Optimizers leave behind information on the number of actions taken. + * This information can be handy to avoid steps further down the pipeline. + */ +int +isOptimizerUsed(MalBlkPtr mb, str opt) +{ + int i, cnt; + char *s, *haystack; + InstrPtr q; + + for (i= mb->stop-1; i > 0; i--){ + q= getInstrPtr(mb,i); + if ( q->token == ENDsymbol) + break; + if (q && q->token == REMsymbol && getModuleId(q) == 0 && q->argc > 0){ + //decompose the message + haystack = getVarConstant(mb,getArg(q,0)).val.sval; + if ( ! haystack) + continue; + s = strstr(haystack, opt); + if( !s) + continue; + s = strstr(haystack, "actions="); + if( s){ + cnt = atoi(s + 8); + return cnt; + } + } + } + return 0; +} + /* Hypothetical, optimizers may massage the plan in such a way * that multiple passes are needed. * However, the current SQL driven approach only expects a single @@ -619,23 +672,3 @@ int isFragmentGroup(InstrPtr p){ )); } -/* - * Some optimizers are interdependent (e.g. mitosis ), which - * requires inspection of the pipeline attached to a MAL block. - */ -int -isOptimizerEnabled(MalBlkPtr mb, str opt) -{ - int i; - InstrPtr q; - - for (i= mb->stop-1; i > 0; i--){ - q= getInstrPtr(mb,i); - if ( q->token == ENDsymbol) - break; - if ( getModuleId(q) == optimizerRef && - getFunctionId(q) == opt) - return 1; - } - return 0; -} diff --git a/monetdb5/optimizer/opt_support.h b/monetdb5/optimizer/opt_support.h --- a/monetdb5/optimizer/opt_support.h +++ b/monetdb5/optimizer/opt_support.h @@ -51,6 +51,7 @@ mal_export int isSelect(InstrPtr q); mal_export int isSubJoin(InstrPtr q); mal_export int isMultiplex(InstrPtr q); mal_export int isOptimizerEnabled(MalBlkPtr mb, str opt); +mal_export int isOptimizerUsed(MalBlkPtr mb, str opt); #endif /* _OPT_SUPPORT_H */ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list