Changeset: abe807bb1207 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=abe807bb1207 Added Files: monetdb5/optimizer/opt_emptybind.c monetdb5/optimizer/opt_emptybind.h Modified Files: monetdb5/mal/mal_private.h monetdb5/modules/mal/projectionpath.c monetdb5/optimizer/Makefile.ag monetdb5/optimizer/opt_candidates.c monetdb5/optimizer/opt_pipes.c monetdb5/optimizer/opt_prelude.c monetdb5/optimizer/opt_prelude.h monetdb5/optimizer/opt_support.c monetdb5/optimizer/opt_support.h monetdb5/optimizer/opt_wrapper.c monetdb5/optimizer/optimizer.mal sql/backends/monet5/sql.mal sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_optimizer.c sql/backends/monet5/sql_scenario.c Branch: jit Log Message:
Intermittent commit addition of the sql.bind optimizer diffs (truncated from 686 to 300 lines): diff --git a/monetdb5/mal/mal_private.h b/monetdb5/mal/mal_private.h --- a/monetdb5/mal/mal_private.h +++ b/monetdb5/mal/mal_private.h @@ -71,8 +71,6 @@ __attribute__((__visibility__("hidden"))); __hidden void malGarbageCollector(MalBlkPtr mb) __attribute__((__visibility__("hidden"))); -__hidden void listFunction(stream *fd, MalBlkPtr mb, MalStkPtr stk, int flg, int first, int step) - __attribute__((__visibility__("hidden"))); /* mal_http_daemon.h */ __hidden void startHttpdaemon(void) diff --git a/monetdb5/modules/mal/projectionpath.c b/monetdb5/modules/mal/projectionpath.c --- a/monetdb5/modules/mal/projectionpath.c +++ b/monetdb5/modules/mal/projectionpath.c @@ -15,7 +15,7 @@ ALGprojectionpath(Client cntxt, MalBlkPt int i, top = 0; bat *bid; bat *r = getArgReference_bat(stk, pci, 0); - BAT *b, **joins = (BAT**)GDKmalloc(pci->argc*sizeof(BAT*)); + BAT *b, **joins = (BAT**)GDKzalloc(pci->argc * sizeof(BAT*)); int error = 0; (void) mb; diff --git a/monetdb5/optimizer/Makefile.ag b/monetdb5/optimizer/Makefile.ag --- a/monetdb5/optimizer/Makefile.ag +++ b/monetdb5/optimizer/Makefile.ag @@ -26,6 +26,7 @@ lib_optimizer = { opt_costModel.c opt_costModel.h \ opt_dataflow.c opt_dataflow.h \ opt_deadcode.c opt_deadcode.h \ + opt_emptybind.c opt_emptybind.h \ opt_evaluate.c opt_evaluate.h \ opt_factorize.c opt_factorize.h \ opt_garbageCollector.c opt_garbageCollector.h \ diff --git a/monetdb5/optimizer/opt_candidates.c b/monetdb5/optimizer/opt_candidates.c --- a/monetdb5/optimizer/opt_candidates.c +++ b/monetdb5/optimizer/opt_candidates.c @@ -32,6 +32,8 @@ OPTcandidatesImplementation(Client cntxt setVarCList(mb,getArg(p,0)); if(getFunctionId(p) == subdeltaRef) setVarCList(mb,getArg(p,0)); + if(getFunctionId(p) == emptybindRef && p->retc == 2) + setVarCList(mb,getArg(p,0)); if(getFunctionId(p) == bindRef && p->retc == 2) setVarCList(mb,getArg(p,0)); } diff --git a/monetdb5/optimizer/opt_emptybind.c b/monetdb5/optimizer/opt_emptybind.c new file mode 100644 --- /dev/null +++ b/monetdb5/optimizer/opt_emptybind.c @@ -0,0 +1,160 @@ +/* + * The contents of this file are subject to the MonetDB Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.monetdb.org/Legal/MonetDBLicense + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is the MonetDB Database System. + * + * The Initial Developer of the Original Code is CWI. + * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + * Copyright August 2008-2016 MonetDB B.V. + * All Rights Reserved. + */ + +/* author M.Kersten + * This optimizer hunts for the empty persistent tables accessed + * and propagates them. + */ +#include "monetdb_config.h" +#include "opt_emptybind.h" +#include "opt_aliases.h" +#include "opt_deadcode.h" +#include "mal_builder.h" + +#define propagate(X) \ + do { \ + clrFunction(p); \ + getArg(p,1)= getArg(p,X); \ + p->argc = 2; \ + actions++; \ + } while (0) + +#define emptyresult(TPE) \ + do { \ + clrFunction(p); \ + setModuleId(p, batRef); \ + setFunctionId(p,newRef); \ + p->argc = 1; \ + cst.vtype=TYPE_void; \ + cst.val.oval= oid_nil; \ + cst.len = 0; \ + (void) convertConstant(TPE, &cst); \ + tmp = defConstant(mb,TPE,&cst); \ + p= pushArgument(mb, p, tmp); \ + actions++; \ + } while (0) + + +//#undef OPTDEBUGemptybind +//#define OPTDEBUGemptybind +int +OPTemptybindImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci) +{ + int i, actions = 0; + int *marked; + int limit = mb->stop, slimit= mb->ssize; + InstrPtr p, *old = mb->stmt; + + // use an instruction reference table to keep + // track of where 'emptybind' results are produced + marked = (int *) GDKzalloc(mb->vsize * sizeof(int)); + if ( marked == NULL) + return 0; + (void) stk; + /* Got an instructions V:= bat.new(:tpe) + * The form the initial family of marked sets. + */ + + (void) cntxt; + (void) pci; + + OPTDEBUGemptybind{ + mnstr_printf(GDKout, "Optimize Query Emptybind\n"); + printFunction(GDKout, mb, 0, LIST_MAL_DEBUG); + } + + if ( newMalBlkStmt(mb, mb->ssize) < 0) + return 0; + + /* Symbolic evaluation of the empty BAT variables */ + /* by looking at empty BAT arguments */ + for (i = 0; i < limit; i++) { + p = old[i]; + + pushInstruction(mb,p); + if (p->token == ENDsymbol){ + for(i++; i<limit; i++) + if (old[i]) + pushInstruction(mb,old[i]); + break; + } + + /* + * The bulk of the intelligence lies in inspecting calling + * sequences to filter and replace results + */ + if ( getModuleId(p) == batRef && getFunctionId(p) == newRef){ + OPTDEBUGemptybind + mnstr_printf(cntxt->fdout, "#empty bat pc %d var %d\n",i , getArg(p,0) ); + marked[getArg(p,0)] = i; + continue; + } + + /* restore the naming, dropping the runtime property 'marked' */ + if (getFunctionId(p) == emptybindRef) { + OPTDEBUGemptybind + mnstr_printf(cntxt->fdout, "#empty bind pc %d var %d\n",i , getArg(p,0) ); + setFunctionId(p,bindRef); + marked[getArg(p,0)] = i; + if( p->retc == 2){ + marked[getArg(p,1)] = i; + OPTDEBUGemptybind + mnstr_printf(cntxt->fdout, "#empty bind pc %d var %d\n",i , getArg(p,1) ); + } + continue; + } + + // delta operations without updates+ insert can be replaced by an assignment + if (getModuleId(p)== sqlRef && getFunctionId(p) == deltaRef && p->argc ==5){ + OPTDEBUGemptybind + mnstr_printf(cntxt->fdout, "#empty delta pc %d var %d,%d,%d\n",i ,marked[getArg(p,2)], marked[getArg(p,3)], marked[getArg(p,4)] ); + if( marked[getArg(p,2)] && marked[getArg(p,3)] && marked[getArg(p,4)] ){ + OPTDEBUGemptybind + mnstr_printf(cntxt->fdout, "#empty delta pc %d var %d\n",i , getArg(p,0) ); + clrFunction(p); + p->argc = 2; + marked[getArg(p,0)] = i; + } + continue; + } + + if (getModuleId(p)== sqlRef && getFunctionId(p) == projectdeltaRef) { + if( marked[getArg(p,3)] && marked[getArg(p,4)] ){ + OPTDEBUGemptybind + mnstr_printf(cntxt->fdout, "#empty projectdelta pc %d var %d\n",i , getArg(p,0) ); + setModuleId(p,algebraRef); + setFunctionId(p,projectionRef); + p->argc = 3; + } + continue; + } + } + for(; i<slimit; i++) + if (old[i]) + freeInstruction(old[i]); + + OPTDEBUGemptybind{ + mnstr_printf(GDKout, "Optimize Query Emptybind done\n"); + printFunction(GDKout, mb, 0, LIST_MAL_DEBUG); + } + + GDKfree(old); + GDKfree(marked); + return actions; +} diff --git a/monetdb5/optimizer/opt_emptybind.h b/monetdb5/optimizer/opt_emptybind.h new file mode 100644 --- /dev/null +++ b/monetdb5/optimizer/opt_emptybind.h @@ -0,0 +1,29 @@ +/* + * The contents of this file are subject to the MonetDB Public License + * Version 1.1 (the "License"); you may not use this file except in + * compliance with the License. You may obtain a copy of the License at + * http://www.monetdb.org/Legal/MonetDBLicense + * + * Software distributed under the License is distributed on an "AS IS" + * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + * License for the specific language governing rights and limitations + * under the License. + * + * The Original Code is the MonetDB Database System. + * + * The Initial Developer of the Original Code is CWI. + * Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + * Copyright August 2008-2014 MonetDB B.V. + * All Rights Reserved. + */ + +#ifndef _MAL_EMPTYBIND_ +#define _MAL_EMPTYBIND_ +#include "opt_prelude.h" +#include "opt_support.h" + +opt_export int OPTemptybindImplementation(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr p); + +#define OPTDEBUGemptybind if ( optDebug & ((lng) 1 <<DEBUG_OPT_EMPTYBIND) ) + +#endif diff --git a/monetdb5/optimizer/opt_pipes.c b/monetdb5/optimizer/opt_pipes.c --- a/monetdb5/optimizer/opt_pipes.c +++ b/monetdb5/optimizer/opt_pipes.c @@ -7,9 +7,7 @@ */ /* - * @f opt_pipes - * @a M.L. Kersten - * @- + * author M.L. Kersten * The default SQL optimizer pipeline can be set per server. See the * optpipe setting in monetdb(1) when using merovingian. During SQL * initialization, the optimizer pipeline is checked against the @@ -70,6 +68,7 @@ static struct PIPELINES { "optimizer.costModel();" "optimizer.coercions();" "optimizer.evaluate();" + "optimizer.emptybind();" "optimizer.pushselect();" "optimizer.aliases();" "optimizer.mitosis();" @@ -100,8 +99,9 @@ static struct PIPELINES { "optimizer.costModel();" "optimizer.coercions();" "optimizer.evaluate();" + "optimizer.emptybind();" + "optimizer.pushselect();" "optimizer.aliases();" - "optimizer.pushselect();" "optimizer.mitosis();" "optimizer.mergetable();" "optimizer.deadcode();" @@ -138,8 +138,9 @@ static struct PIPELINES { "optimizer.costModel();" "optimizer.coercions();" "optimizer.evaluate();" + "optimizer.emptybind();" + "optimizer.pushselect();" "optimizer.aliases();" - "optimizer.pushselect();" "optimizer.mergetable();" "optimizer.deadcode();" "optimizer.aliases();" @@ -174,8 +175,9 @@ static struct PIPELINES { "optimizer.costModel();" "optimizer.coercions();" "optimizer.evaluate();" + "optimizer.emptybind();" + "optimizer.pushselect();" "optimizer.aliases();" - "optimizer.pushselect();" "optimizer.mergetable();" "optimizer.deadcode();" _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list