Changeset: c1c78349a3a4 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c1c78349a3a4 Modified Files: sql/backends/monet5/sql_optimizer.c Branch: default Log Message:
Decide on optimizer pipeline If the total footprint of the columns accessed in a query exceed the available memory, then switch to the volcano_pipe optimizer. diffs (96 lines): diff --git a/sql/backends/monet5/sql_optimizer.c b/sql/backends/monet5/sql_optimizer.c --- a/sql/backends/monet5/sql_optimizer.c +++ b/sql/backends/monet5/sql_optimizer.c @@ -35,7 +35,6 @@ /* * Cost-based optimization and semantic evaluations require statistics to work with. * They should come from the SQL catalog or the BATs themselves. - * The properties passed at this point are the number of rows. * A better way is to mark all BATs used as a constant, because that permits * access to all properties. However, this creates unnecessary locking during stack * initialization. Therfore, we store the BAT id as a property for the optimizer @@ -51,13 +50,14 @@ * common term optimizer, because the first bind has a side-effect. */ -static void SQLgetStatistics(Client cntxt, mvc *m, MalBlkPtr mb) +static size_t SQLgetStatistics(Client cntxt, mvc *m, MalBlkPtr mb) { InstrPtr *old = NULL; int oldtop, i, actions = 0, size = 0; lng clk = GDKusec(); sql_trans *tr = m->session->tr; str msg; + size_t space = 0; // sum the total amount of data potentially read old = mb->stmt; oldtop = mb->stop; @@ -93,6 +93,7 @@ static void SQLgetStatistics(Client cntx char *sname = getVarConstant(mb, getArg(p, 2 + upd)).val.sval; char *tname = getVarConstant(mb, getArg(p, 3 + upd)).val.sval; char *cname = NULL; + int mt_member = 0; BUN rows = 1; /* default to cope with delta bats */ int mode = 0; @@ -117,6 +118,10 @@ static void SQLgetStatistics(Client cntx b = store_funcs.bind_idx(m->session->tr, i, RDONLY); if (b) { cnt = BATcount(b); + if( mode == 0) { + space += getBatSpace(b); + //mnstr_printf(GDKout, "#space estimate %s.%s.%s mode %d "LLFMT"\n",sname,tname,cname, mode, getBatSpace(b)); + } BBPunfix(b->batCacheid); } rows = (BUN) cnt; @@ -134,6 +139,10 @@ static void SQLgetStatistics(Client cntx b = store_funcs.bind_col(m->session->tr, c, RDONLY); if (b) { cnt = BATcount(b); + if( mode == 0) { + space += getBatSpace(b); + //mnstr_printf(GDKout, "#space estimate %s.%s.%s mode %d "LLFMT"\n",sname,tname,cname, mode, getBatSpace(b)); + } BBPunfix(b->batCacheid); } rows = (BUN) cnt; @@ -155,6 +164,7 @@ static void SQLgetStatistics(Client cntx msg = optimizerCheck(cntxt, mb, "optimizer.SQLgetstatistics", actions, GDKusec() - clk); if (msg) /* what to do with an error? */ GDKfree(msg); + return space; } str @@ -175,11 +185,21 @@ addOptimizers(Client c, MalBlkPtr mb, ch InstrPtr q; backend *be; str msg; + size_t space; be = (backend *) c->sqlcontext; assert(be && be->mvc); /* SQL clients should always have their state set */ - msg = addOptimizerPipe(c, mb, pipe ? pipe : "default_pipe"); + space = SQLgetStatistics(c, be->mvc, mb); + if(space && (pipe == NULL || strcmp(pipe,"default_pipe")== 0)){ + if( space > MT_npages() * MT_pagesize()){ + pipe = "volcano_pipe"; + mnstr_printf(GDKout, "#use volcano optimizer pipeline? "SZFMT"\n", space); + }else + pipe = "default_pipe"; + } else + pipe = pipe? pipe: "default_pipe"; + msg = addOptimizerPipe(c, mb, pipe); if (msg) GDKfree(msg); /* what to do with an error? */ /* point queries do not require mitosis and dataflow */ @@ -192,7 +212,6 @@ addOptimizers(Client c, MalBlkPtr mb, ch q->token = REMsymbol; /* they are ignored */ } } - SQLgetStatistics(c, be->mvc, mb); if (be->mvc->emod & mod_debug) addtoMalBlkHistory(mb, "getStatistics"); } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list