Changeset: 46ee757549a1 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=46ee757549a1
Modified Files:
monetdb5/extras/jaql/jaql.c
monetdb5/extras/jaql/jaqlscenario.c
monetdb5/mal/mal_client.h
sql/backends/monet5/sql.mx
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_optimizer.c
sql/backends/monet5/sql_scenario.c
Branch: default
Log Message:
Client struct: register SQL and JAQL contexts directly
Instead of hiding the SQL and JAQL context pointers in some state
fields, create a field in the Client struct to store the pointers. At
the moment SQL and JAQL both have a separate field, such that both
contexts can be loaded (and in use).
Adapted the SQL and JAQL code to set and retrieve the context pointers
from the sqlcontext and jaqlcontext fields from the Client struct.
Because SQL uses a backend struct and mvc struct, where the former has a
pointer to the latter, the SQL code was changed to only store the
backend struct pointer, and retrieve the mvc struct pointer via the
backend pointer.
diffs (truncated from 349 to 300 lines):
diff --git a/monetdb5/extras/jaql/jaql.c b/monetdb5/extras/jaql/jaql.c
--- a/monetdb5/extras/jaql/jaql.c
+++ b/monetdb5/extras/jaql/jaql.c
@@ -1670,7 +1670,7 @@ JAQLexecute(Client cntxt, MalBlkPtr mb,
if (j == NULL) {
j = GDKzalloc(sizeof(jc));
- cntxt->state[MAL_SCENARIO_OPTIMIZE] = j;
+ cntxt->jaqlcontext = j;
}
j->buf = jaql;
@@ -1742,7 +1742,7 @@ JAQLexecute(Client cntxt, MalBlkPtr mb,
str
getJAQLContext(Client cntxt, jc **c)
{
- *c = ((jc *) cntxt->state[MAL_SCENARIO_OPTIMIZE]);
+ *c = (jc *) cntxt->jaqlcontext;
if (*c == NULL)
throw(MAL, "jaql.context", "JAQL environment not found");
return MAL_SUCCEED;
diff --git a/monetdb5/extras/jaql/jaqlscenario.c
b/monetdb5/extras/jaql/jaqlscenario.c
--- a/monetdb5/extras/jaql/jaqlscenario.c
+++ b/monetdb5/extras/jaql/jaqlscenario.c
@@ -86,7 +86,8 @@ JAQLinitClient(Client c)
/* Set state, this indicates an initialized client scenario */
c->state[MAL_SCENARIO_READER] = c;
c->state[MAL_SCENARIO_PARSER] = c;
- c->state[MAL_SCENARIO_OPTIMIZE] = j;
+ c->state[MAL_SCENARIO_OPTIMIZE] = c;
+ c->jaqlcontext = j;
return msg;
}
@@ -94,8 +95,8 @@ JAQLinitClient(Client c)
str
JAQLexitClient(Client c)
{
- if (c->state[MAL_SCENARIO_OPTIMIZE] != NULL) {
- jc *j = (jc *) c->state[MAL_SCENARIO_OPTIMIZE];
+ if (c->jaqlcontext != NULL) {
+ jc *j = (jc *) c->jaqlcontext;
jaqllex_destroy(j->scanner);
j->scanner = NULL;
@@ -105,6 +106,7 @@ JAQLexitClient(Client c)
c->state[MAL_SCENARIO_READER] = NULL;
c->state[MAL_SCENARIO_PARSER] = NULL;
c->state[MAL_SCENARIO_OPTIMIZE] = NULL;
+ c->jaqlcontext = NULL;
}
return MAL_SUCCEED;
diff --git a/monetdb5/mal/mal_client.h b/monetdb5/mal/mal_client.h
--- a/monetdb5/mal/mal_client.h
+++ b/monetdb5/mal/mal_client.h
@@ -209,6 +209,14 @@ typedef struct CLIENT {
#endif
jmp_buf exception_buf;
int exception_buf_initialized;
+
+ /* These are pointers to scenario backends contexts. For the time
+ * being just SQL and JAQL. We need a pointer for each of them,
+ * since they have to be able to interoperate with each other, e.g.
+ * both contexts at the same time are in use.
+ */
+ void *sqlcontext;
+ void *jaqlcontext;
} *Client, ClientRec;
mal_export void MCinit(void);
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
@@ -1687,21 +1687,23 @@ sqlcleanup(mvc *c, int err)
* Failure to find the state descriptor aborts the session.
*/
str
-getSQLContext(Client cntxt, MalBlkPtr mb, mvc **c, backend **b )
-{
- (void)mb;
- if (cntxt == NULL )
- throw(SQL, "mvc","No client record");
- if (cntxt->state[MAL_SCENARIO_PARSER] == NULL ||
cntxt->state[MAL_SCENARIO_OPTIMIZE] == NULL)
- throw(SQL, "mvc","SQL module not initialized");
- if (c)
- *c = ((mvc *) cntxt ->state[MAL_SCENARIO_OPTIMIZE]);
- if (c && *c == 0)
- throw(SQL, "mvc","SQL module not initialized, mvc struct
missing");
+getSQLContext(Client cntxt, MalBlkPtr mb, mvc **c, backend **b)
+{
+ backend *be;
+ (void) mb;
+
+ if (cntxt == NULL)
+ throw(SQL, "mvc", "No client record");
+ if (cntxt->sqlcontext == NULL)
+ throw(SQL, "mvc", "SQL module not initialized");
+ be = (backend *) cntxt->sqlcontext;
+ if (c) {
+ *c = be->mvc;
+ if (*c == NULL)
+ throw(SQL, "mvc", "SQL module not initialized, mvc
struct missing");
+ }
if (b)
- *b = ((backend*) cntxt->state[MAL_SCENARIO_PARSER]);
- if (b && *b == 0)
- throw(SQL, "mvc","SQL module not initialized, backend struct
missing");
+ *b = be;
return MAL_SUCCEED;
}
diff --git a/sql/backends/monet5/sql_gencode.c
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -267,7 +267,7 @@ _create_relational_function(mvc *m, char
{
sql_rel *r;
Client c = MCgetClient(m->clientid);
- backend *be = ((backend *) c->state[MAL_SCENARIO_PARSER]);
+ backend *be = (backend *) c->sqlcontext;
MalBlkPtr curBlk = 0;
InstrPtr curInstr = 0;
Symbol backup = NULL;
@@ -2397,7 +2397,7 @@ monet5_create_table_function(ptr M, char
sql_rel *r;
mvc *m = (mvc*)M;
Client c = MCgetClient(m->clientid);
- backend *be = ((backend *) c->state[MAL_SCENARIO_PARSER]);
+ backend *be = (backend *) c->sqlcontext;
MalBlkPtr curBlk = 0;
InstrPtr curInstr = 0;
Symbol backup = NULL;
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
@@ -446,7 +446,7 @@ addOptimizers(Client c, MalBlkPtr mb)
ValRecord *val;
backend *be;
- be = ((backend *) c->state[MAL_SCENARIO_PARSER]);
+ be = (backend *) c->sqlcontext;
assert( be && be->mvc ); /* SQL clients should always have their
state set */
val = stack_get_var(be->mvc,"optimizer");
@@ -473,7 +473,7 @@ addQueryToCache(Client c)
c->blkmode = 0;
mb = c->curprg->def;
chkProgram(c->fdout, c->nspace, mb);
- m = ((mvc *) c->state[MAL_SCENARIO_OPTIMIZE]);
+ m = ((backend *)c->sqlcontext)->mvc;
#ifdef _SQL_OPTIMIZER_DEBUG
mnstr_printf(GDKout, "ADD QUERY TO CACHE\n");
printFunction(GDKout,mb,0,LIST_MAL_ALL);
@@ -485,8 +485,6 @@ addQueryToCache(Client c)
* to allow inspection.
*/
if (mb->errors) {
- mvc *m;
- m = ((mvc *) c->state[MAL_SCENARIO_OPTIMIZE]);
showErrors(c);
if (c->listing)
@@ -496,7 +494,7 @@ addQueryToCache(Client c)
return;
}
addOptimizers(c, mb);
- SQLgetStatistics(c,(mvc *) c->state[MAL_SCENARIO_OPTIMIZE],mb);
+ SQLgetStatistics(c,m,mb);
if ( m->emod & mod_debug )
addtoMalBlkHistory(mb,"getStatistics");
optimizeMALBlock(c,mb);
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
@@ -464,15 +464,15 @@ SQLinitClient(Client c)
bstream_next(fdin);
MCpushClientInput(c, fdin, 0, "");
}
- if (c->state[MAL_SCENARIO_PARSER] == 0) {
+ if (c->sqlcontext == 0) {
m = mvc_create(c->idx, 0, SQLdebug, c->fdin, c->fdout);
global_variables(m, "monetdb", "sys");
if (isAdministrator(c) || strcmp(c->scenario, "msql") == 0) /*
console should return everything */
m->reply_size = -1;
be = (void *) backend_create(m, c);
} else {
- m = c->state[MAL_SCENARIO_OPTIMIZE];
- be = c->state[MAL_SCENARIO_PARSER];
+ be = c->sqlcontext;
+ m = be->mvc;
mvc_reset(m, c->fdin, c->fdout, SQLdebug, NR_GLOBAL_VARS);
backend_reset(be);
}
@@ -490,8 +490,9 @@ SQLinitClient(Client c)
be->language = 'S';
/* Set state, this indicates an initialized client scenario */
c->state[MAL_SCENARIO_READER] = c;
- c->state[MAL_SCENARIO_PARSER] = be;
- c->state[MAL_SCENARIO_OPTIMIZE] = m;
+ c->state[MAL_SCENARIO_PARSER] = c;
+ c->state[MAL_SCENARIO_OPTIMIZE] = c;
+ c->sqlcontext = be;
initSQLreferences();
/* initialize the database with predefined SQL functions */
@@ -586,10 +587,13 @@ SQLexitClient(Client c)
#endif
if (SQLinitialized == FALSE)
throw(SQL, "SQLexitClient", "Catalogue not available");
- if (c->state[MAL_SCENARIO_PARSER] && c->state[MAL_SCENARIO_OPTIMIZE]) {
- mvc *m = (mvc *) c->state[MAL_SCENARIO_OPTIMIZE];
- if ( m == NULL)
+ if (c->sqlcontext) {
+ backend *be = NULL;
+ mvc *m = NULL;
+ if (c->sqlcontext == NULL)
throw(SQL, "SQLexitClient", "MVC catalogue not
available");
+ be = (backend *)c->sqlcontext;
+ m = be->mvc;
assert(m->session);
if (m->session->auto_commit && m->session->active) {
@@ -602,14 +606,11 @@ SQLexitClient(Client c)
res_tables_destroy(m->results);
m->results= NULL;
- {
- backend *be = c->state[MAL_SCENARIO_PARSER];
-
- mvc_destroy(m);
- backend_destroy(be);
- c->state[MAL_SCENARIO_OPTIMIZE] = NULL;
- c->state[MAL_SCENARIO_PARSER] = NULL;
- }
+ mvc_destroy(m);
+ backend_destroy(be);
+ c->state[MAL_SCENARIO_OPTIMIZE] = NULL;
+ c->state[MAL_SCENARIO_PARSER] = NULL;
+ c->sqlcontext = NULL;
}
c->state[MAL_SCENARIO_READER] = NULL;
return MAL_SUCCEED;
@@ -664,7 +665,7 @@ SQLstatementIntern(Client c, str *expr,
char *n;
stream *buf;
str msg = MAL_SUCCEED;
- backend *be, *sql = ((backend *) c->state[MAL_SCENARIO_PARSER]);
+ backend *be, *sql = (backend *) c->sqlcontext;
size_t len = strlen(*expr);
#ifdef _SQL_COMPILE
@@ -672,7 +673,7 @@ SQLstatementIntern(Client c, str *expr,
#endif
if (!sql) {
msg = SQLinitEnvironment(c);
- sql = ((backend *) c->state[MAL_SCENARIO_PARSER]);
+ sql = (backend *) c->sqlcontext;
}
if (msg)
throw(SQL, "SQLstatement", "Catalogue not available");
@@ -720,7 +721,7 @@ SQLstatementIntern(Client c, str *expr,
* System has been prepared to parse it and generate code.
* Scan the complete string for SQL statements, stop at the first error.
*/
- c->state[MAL_SCENARIO_PARSER] = sql;
+ c->sqlcontext = sql;
while( m->scanner.rs->pos < m->scanner.rs->len ){
sql_rel *r;
stmt *s;
@@ -810,7 +811,7 @@ endofcompile:
if (execute)
MSresetInstructions(c->curprg->def, 1);
- c->state[MAL_SCENARIO_PARSER] = be;
+ c->sqlcontext = be;
backend_destroy(sql);
GDKfree(n);
GDKfree(b);
@@ -872,29 +873,29 @@ SQLcompile(Client cntxt, MalBlkPtr mb, M
str
SQLinclude(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
{
- stream *fd;
+ stream *fd;
bstream *bfd;
- str *name = (str *) getArgReference(stk,pci,1);
+ str *name = (str *) getArgReference(stk, pci, 1);
str msg = MAL_SUCCEED, fullname;
str *expr;
mvc *m;
- fullname= MSP_locate_sqlscript(*name, 0);
- if ( fullname == NULL)
- fullname= *name;
+ fullname = MSP_locate_sqlscript(*name, 0);
+ if (fullname == NULL)
+ fullname = *name;
fd = open_rastream(fullname);
- if (mnstr_errnr(fd) == MNSTR_OPEN_ERROR) {
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list