Changeset: 5208475be426 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5208475be426
Modified Files:
monetdb5/optimizer/opt_pipes.c
monetdb5/optimizer/opt_pipes.h
sql/backends/monet5/datacell/opt_datacell.c
sql/backends/monet5/sql.mx
sql/backends/monet5/sql_optimizer.c
sql/backends/monet5/sql_optimizer.h
sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:
User-specific optimizers
The optimizer pipeline is taken by default from the gdk environment variables.
It can be overruled on a per client base with a new pipe line.The prevalent
optimizer pipe is stored in a SQL global variable, which is user specific.
diffs (257 lines):
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
@@ -442,9 +442,11 @@ static int builtinoptimizers = 11;
/* the session_pipe is the one defined by the user */
str
-addPipeDefinition(str name, str pipe)
+addPipeDefinition(Client cntxt, str name, str pipe)
{
int i;
+ str msg;
+
for( i =0; i< MAXOPTPIPES && pipes[i].name; i++)
if ( pipes[i].name && strcmp(name,pipes[i].name)==0)
break;
@@ -465,7 +467,12 @@ addPipeDefinition(str name, str pipe)
pipes[i].def = GDKstrdup(pipe);
pipes[i].status = GDKstrdup("experimental");
pipes[i].mb = NULL;
- return MAL_SUCCEED;
+ msg = compileOptimizer(cntxt, name);
+ if ( msg){
+ GDKfree(pipes[i].status);
+ pipes[i].status = GDKstrdup(msg);
+ }
+ return msg;
}
int
@@ -601,20 +608,15 @@ validateOptimizerPipes(void){
* then copy the statements to the end of the MAL plan
*/
str
-addOptimizerPipe(Client cntxt, MalBlkPtr mb, str name){
- int i, j, k;
- InstrPtr p;
+compileOptimizer(Client cntxt, str name){
+ int i, j;
Symbol sym;
str msg = MAL_SUCCEED;
(void) cntxt;
for( i=0; i < MAXOPTPIPES && pipes[i].name; i++)
- if ( strcmp(pipes[i].name, name) == 0)
- break;
-
- /* compile pipes first */
- if ( pipes[i].mb == 0){
+ if ( strcmp(pipes[i].name, name) == 0 && pipes[i].mb == 0){
/* precompile the pipeline as MAL string */
Client c = MCinitClient((oid)1,0,0);
assert(c != NULL);
@@ -642,7 +644,23 @@ addOptimizerPipe(Client cntxt, MalBlkPtr
if ( msg != MAL_SUCCEED)
return msg;
}
+ return MAL_SUCCEED;
+}
+str
+addOptimizerPipe(Client cntxt, MalBlkPtr mb, str name){
+ int i, j, k;
+ InstrPtr p;
+
+ (void) cntxt;
+
+ for( i=0; i < MAXOPTPIPES && pipes[i].name; i++)
+ if ( strcmp(pipes[i].name, name) == 0)
+ break;
+
+ if ( pipes[i].mb == NULL)
+ (void) compileOptimizer(cntxt,name);
+
if ( pipes[i].mb) {
for ( j =1; j < pipes[i].mb->stop-1; j++) {
p = copyInstruction(pipes[i].mb->stmt[j]);
diff --git a/monetdb5/optimizer/opt_pipes.h b/monetdb5/optimizer/opt_pipes.h
--- a/monetdb5/optimizer/opt_pipes.h
+++ b/monetdb5/optimizer/opt_pipes.h
@@ -25,8 +25,9 @@
opt_export str getPipeDefinition(str name);
opt_export str getPipeCatalog(int *nme, int *def, int *stat);
-opt_export str addPipeDefinition(str name, str pipe);
+opt_export str addPipeDefinition(Client cntxt, str name, str pipe);
opt_export int isOptimizerPipe(str name);
opt_export str addOptimizerPipe(Client cntxt, MalBlkPtr mb, str name);
+opt_export str compileOptimizer(Client cntxt, str name);
#endif
diff --git a/sql/backends/monet5/datacell/opt_datacell.c
b/sql/backends/monet5/datacell/opt_datacell.c
--- a/sql/backends/monet5/datacell/opt_datacell.c
+++ b/sql/backends/monet5/datacell/opt_datacell.c
@@ -229,7 +229,7 @@ OPTdatacellImplementation(Client cntxt,
if (actions)
{
- addPipeDefinition("datacell_pipe",
+ addPipeDefinition(cntxt, "datacell_pipe",
"inline,remap,datacell,evaluate,costModel,coercions,emptySet,aliases,mitosis,"
"mergetable,deadcode,commonTerms,joinPath,reorder,deadcode,reduce,dataflow,"
"history,multiplex,accumulators,garbageCollector");
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -2664,18 +2664,15 @@ setVariable(Client cntxt, MalBlkPtr mb,
if (mtype < 0 || mtype >= 255)
throw(SQL, "sql.setVariable", "failed");
if ( strcmp("optimizer", varname)== 0) {
- str newopt;
- newopt = setOptimizer( *(str *) getArgReference(stk,pci,3));
- if ( newopt)
+ str newopt = *(str *) getArgReference(stk,pci,3);
+ if ( newopt) {
msg = addOptimizerPipe(cntxt, mb, newopt);
- if ( msg )
- return msg;
- if ( newopt != NULL ) {
+ if ( msg )
+ return msg;
if (stack_find_var(m, varname))
stack_set_string(m, varname, newopt);
- return MAL_SUCCEED;
}
- throw(SQL, "sql.setVariable", "Failed to initialize optimizer
pipeline");
+ return MAL_SUCCEED;
}
src = &stk->stk[getArg(pci, 3)];
if (stack_find_var(m, varname)) {
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
@@ -416,61 +416,39 @@ SQLgetStatistics(Client cntxt, mvc *m, M
optimizerCheck(cntxt,mb,"optimizer.SQLgetstatistics",actions,GDKusec()-clk,0);
}
/*
- * Optimizers steps are identified by a list of identifiers and given
- * a pipeline name. The default pipeline in the distribution has been
+ * Optimizers steps are identified by a pipeline name. The default pipeline in
the distribution has been
* tested extensively and should provide overall good performance.
* Additional pipelines are defined in the opt_pipes.mx file.
*
- * A few optimizations are always needed. First, the multiplex
- * code should be turned into a proper MAL blocks before
- * other optimizations take place.
- * And before we actually execute the program, we should
- * expand the macros (unless this has already been taken
- * care of.
- *
- * The first error in the optimizer string is shown.
- *
- * The prevalent optimizer pipeline is a global variable. Note, that no
concurrency
- * control is implemented to isolate the clients in playing with the
optimizers.
*/
-str optimizerpipe; /* the active pipeline */
+static str optimizerpipe; /* the active pipeline */
str
-setOptimizer(str newopt)
+initSQLoptimizer(void)
{
char *pipe;
/* do nothing if the pipe line is already set */
- if ( optimizerpipe && newopt && strcmp(optimizerpipe,newopt) == 0 )
- return GDKstrdup(optimizerpipe);
-
- if (newopt == NULL || *newopt == 0 ){
+ if (optimizerpipe == NULL ){
pipe = GDKgetenv("sql_optimizer");
if ( pipe == NULL)
- newopt = GDKstrdup("minimal_pipe");
- else newopt= GDKstrdup(pipe);
- } else {
- if ( optimizerpipe)
- GDKfree(optimizerpipe);
- /* add/test user defined optimizerpath */
- if ( !isOptimizerPipe(newopt) ) {
- addPipeDefinition("user", newopt);
- optimizerpipe = GDKstrdup("user");
- } else
- optimizerpipe = GDKstrdup(newopt);
+ optimizerpipe = GDKstrdup("default_pipe");
+ else optimizerpipe= GDKstrdup(pipe);
}
return GDKstrdup(optimizerpipe);
}
void
-addOptimizers(Client c, MalBlkPtr mb, int flag)
+addOptimizers(Client c, MalBlkPtr mb, backend *be)
{
int i;
InstrPtr q;
+ ValRecord *val;
- addOptimizerPipe(c, mb,optimizerpipe);
+ val = stack_get_var(be->mvc,"optimizer");
+ addOptimizerPipe(c, mb, val? val->val.sval:"default_pipe");
/* point queries do not require mitosis and dataflow */
- if ( flag)
+ if ( be->mvc->point_query)
for( i = mb->stop -1; i > 0; i--){
q= getInstrPtr(mb,i);
if (q->token == ENDsymbol)
@@ -514,7 +492,7 @@ addQueryToCache(Client c)
runMALDebugger(c,c->curprg);
return;
}
- addOptimizers(c,mb, be->mvc->point_query);
+ addOptimizers(c,mb, be);
SQLgetStatistics(c,(mvc *) c->state[MAL_SCENARIO_OPTIMIZE],mb);
if ( m->emod & mod_debug )
addtoMalBlkHistory(mb,"getStatistics");
diff --git a/sql/backends/monet5/sql_optimizer.h
b/sql/backends/monet5/sql_optimizer.h
--- a/sql/backends/monet5/sql_optimizer.h
+++ b/sql/backends/monet5/sql_optimizer.h
@@ -26,9 +26,8 @@
sql5_export void addQueryToCache(Client c);
sql5_export str SQLoptimizer(Client c);
sql5_export void SQLsetAccessMode(Client c);
-sql5_export str setOptimizer(str optimizer);
+sql5_export str initSQLoptimizer(void);
-sql5_export str optimizerpipe; /* the active pipeline */
-sql5_export void addOptimizers(Client c,MalBlkPtr mb, int flag);
+sql5_export void addOptimizers(Client c,MalBlkPtr mb, backend *be);
#endif /* _SQL_OPTIMIZER_H_ */
diff --git a/sql/backends/monet5/sql_scenario.c
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -278,7 +278,6 @@ global_variables(mvc *sql, char *user, c
bit T = TRUE;
bit F = FALSE;
ValRecord src;
- str optimizer;
typename = "int";
sql_find_subtype(&ctype, typename, 0, 0);
@@ -290,13 +289,7 @@ global_variables(mvc *sql, char *user, c
SQLglobal("current_user", user);
SQLglobal("current_role", user);
/* inherit the optimizer from the server */
- if (optimizerpipe )
- optimizer= optimizerpipe;
- else
- optimizer= GDKgetenv("sql_optimizer");
- if (optimizer == NULL)
- optimizer= "default_pipe";
- SQLglobal("optimizer", setOptimizer(optimizer));
+ SQLglobal("optimizer", initSQLoptimizer());
SQLglobal("trace","show,ticks,stmt");
typename = "sec_interval";
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list