Changeset: a93055ba1960 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a93055ba1960
Modified Files:
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_execute.h
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_scenario.c
sql/backends/monet5/sql_statement.c
Branch: jit
Log Message:
Use new api and make namespaces different
prepared blocks as marked as p%d_%d
diffs (300 lines):
diff --git a/sql/backends/monet5/sql_execute.c
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -188,6 +188,88 @@ SQLsetTrace(Client cntxt, MalBlkPtr mb)
chkTypes(cntxt->fdout, cntxt->nspace, mb, TRUE);
}
+/*
+ * Execution of the SQL program is delegated to the MALengine.
+ * Different cases should be distinguished. The default is to
+ * hand over the MAL block derived by the parser for execution.
+ * However, when we received an Execute call, we make a shortcut
+ * and prepare the stack for immediate execution
+ */
+static str
+SQLexecutePrepared(Client c, backend *be, MalBlkPtr mb)
+{
+ mvc *m = be->mvc;
+ int argc, parc;
+ ValPtr *argv, argvbuffer[MAXARG], v;
+ ValRecord *argrec, argrecbuffer[MAXARG];
+ MalStkPtr glb;
+ InstrPtr pci;
+ int i;
+ str ret;
+ cq *q= be->q;
+
+ pci = getInstrPtr(mb, 0);
+ if (pci->argc >= MAXARG)
+ argv = (ValPtr *) GDKmalloc(sizeof(ValPtr) * pci->argc);
+ else
+ argv = argvbuffer;
+
+ if (pci->retc >= MAXARG)
+ argrec = (ValRecord *) GDKmalloc(sizeof(ValRecord) * pci->retc);
+ else
+ argrec = argrecbuffer;
+
+ /* prepare the target variables */
+ for (i = 0; i < pci->retc; i++) {
+ argv[i] = argrec + i;
+ argv[i]->vtype = getVarGDKType(mb, i);
+ }
+
+ argc = m->argc;
+ parc = q->paramlen;
+
+ if (argc != parc) {
+ if (pci->argc >= MAXARG)
+ GDKfree(argv);
+ if (pci->retc >= MAXARG)
+ GDKfree(argrec);
+ throw(SQL, "sql.prepare", "07001!EXEC: wrong number of
arguments for prepared statement: %d, expected %d", argc, parc);
+ } else {
+ for (i = 0; i < m->argc; i++) {
+ atom *arg = m->args[i];
+ sql_subtype *pt = q->params + i;
+
+ if (!atom_cast(arg, pt)) {
+ /*sql_error(c, 003, buf); */
+ if (pci->argc >= MAXARG)
+ GDKfree(argv);
+ if (pci->retc >= MAXARG)
+ GDKfree(argrec);
+ throw(SQL, "sql.prepare", "07001!EXEC: wrong
type for argument %d of " "prepared statement: %s, expected %s", i + 1,
atom_type(arg)->type->sqlname, pt->type->sqlname);
+ }
+ argv[pci->retc + i] = &arg->data;
+ }
+ }
+ glb = (MalStkPtr) (q->stk);
+ ret = callMAL(c, mb, &glb, argv, (m->emod & mod_debug ? 'n' : 0));
+ /* cleanup the arguments */
+ for (i = pci->retc; i < pci->argc; i++) {
+ garbageElement(c, v = &glb->stk[pci->argv[i]]);
+ v->vtype = TYPE_int;
+ v->val.ival = int_nil;
+ }
+ if (glb && ret) /* error */
+ garbageCollector(c, mb, glb, glb != 0);
+ q->stk = (backend_stack) glb;
+ if (glb && SQLdebug & 1)
+ printStack(GDKstdout, mb, glb);
+ if (pci->argc >= MAXARG)
+ GDKfree(argv);
+ if (pci->retc >= MAXARG)
+ GDKfree(argrec);
+ return ret;
+}
+
static str
SQLrun(Client c, backend *be, mvc *m){
str msg= MAL_SUCCEED;
@@ -196,13 +278,20 @@ SQLrun(Client c, backend *be, mvc *m){
int i,j, retc;
ValPtr val;
+ if ( *m->errstr)
+ return createException(PARSE, "SQLparser", "%s", m->errstr);
// locate and inline the query template instruction
mb = copyMalBlk(c->curprg->def);
/* only consider a re-optimization when we are dealing with query
templates */
for ( i= 1; i < mb->stop;i++){
p=getInstrPtr(mb,i);
- if( (p->token == FCNcall || p->token == FUNCTIONsymbol) &&
p->blk && qc_isaquerytemplate(getFunctionId(p)) ) {
+ if( getFunctionId(p) &&
qc_isapreparedquerytemplate(getFunctionId(p) ) ){
+ msg = SQLexecutePrepared(c, be, p->blk);
+ freeMalBlk(mb);
+ return msg;
+ }
+ if( getFunctionId(p) && p->blk &&
qc_isaquerytemplate(getFunctionId(p)) ) {
mc= copyMalBlk(p->blk);
retc =p->retc;
freeMalBlk(mb);
@@ -495,95 +584,6 @@ endofcompile:
return msg;
}
-/*
- * Execution of the SQL program is delegated to the MALengine.
- * Different cases should be distinguished. The default is to
- * hand over the MAL block derived by the parser for execution.
- * However, when we received an Execute call, we make a shortcut
- * and prepare the stack for immediate execution
- */
-str
-SQLexecutePrepared(Client c, backend *be, cq *q)
-{
- mvc *m = be->mvc;
- int argc, parc;
- ValPtr *argv, argvbuffer[MAXARG], v;
- ValRecord *argrec, argrecbuffer[MAXARG];
- MalBlkPtr mb;
- MalStkPtr glb;
- InstrPtr pci;
- int i;
- str ret;
- Symbol qcode = q->code;
-
- if (!qcode || qcode->def->errors) {
- if (!qcode && *m->errstr)
- return createException(PARSE, "SQLparser", "%s",
m->errstr);
- throw(SQL, "SQLengine", "39000!program contains errors");
- }
- mb = qcode->def;
- pci = getInstrPtr(mb, 0);
- if (pci->argc >= MAXARG)
- argv = (ValPtr *) GDKmalloc(sizeof(ValPtr) * pci->argc);
- else
- argv = argvbuffer;
-
- if (pci->retc >= MAXARG)
- argrec = (ValRecord *) GDKmalloc(sizeof(ValRecord) * pci->retc);
- else
- argrec = argrecbuffer;
-
- /* prepare the target variables */
- for (i = 0; i < pci->retc; i++) {
- argv[i] = argrec + i;
- argv[i]->vtype = getVarGDKType(mb, i);
- }
-
- argc = m->argc;
- parc = q->paramlen;
-
- if (argc != parc) {
- if (pci->argc >= MAXARG)
- GDKfree(argv);
- if (pci->retc >= MAXARG)
- GDKfree(argrec);
- throw(SQL, "sql.prepare", "07001!EXEC: wrong number of
arguments for prepared statement: %d, expected %d", argc, parc);
- } else {
- for (i = 0; i < m->argc; i++) {
- atom *arg = m->args[i];
- sql_subtype *pt = q->params + i;
-
- if (!atom_cast(arg, pt)) {
- /*sql_error(c, 003, buf); */
- if (pci->argc >= MAXARG)
- GDKfree(argv);
- if (pci->retc >= MAXARG)
- GDKfree(argrec);
- throw(SQL, "sql.prepare", "07001!EXEC: wrong
type for argument %d of " "prepared statement: %s, expected %s", i + 1,
atom_type(arg)->type->sqlname, pt->type->sqlname);
- }
- argv[pci->retc + i] = &arg->data;
- }
- }
- glb = (MalStkPtr) (q->stk);
- ret = callMAL(c, mb, &glb, argv, (m->emod & mod_debug ? 'n' : 0));
- /* cleanup the arguments */
- for (i = pci->retc; i < pci->argc; i++) {
- garbageElement(c, v = &glb->stk[pci->argv[i]]);
- v->vtype = TYPE_int;
- v->val.ival = int_nil;
- }
- if (glb && ret) /* error */
- garbageCollector(c, mb, glb, glb != 0);
- q->stk = (backend_stack) glb;
- if (glb && SQLdebug & 1)
- printStack(GDKstdout, mb, glb);
- if (pci->argc >= MAXARG)
- GDKfree(argv);
- if (pci->retc >= MAXARG)
- GDKfree(argrec);
- return ret;
-}
-
str
SQLengineIntern(Client c, backend *be)
{
diff --git a/sql/backends/monet5/sql_execute.h
b/sql/backends/monet5/sql_execute.h
--- a/sql/backends/monet5/sql_execute.h
+++ b/sql/backends/monet5/sql_execute.h
@@ -12,7 +12,6 @@
sql5_export str SQLstatementREST(Client c, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str SQLstatementIntern(Client c, str *expr, str nme, bit execute,
bit output, res_table **result);
-sql5_export str SQLexecutePrepared(Client c, backend *be, cq *q);
sql5_export str SQLengineIntern(Client c, backend *be);
sql5_export str RAstatement(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
sql5_export str RAstatement2(Client cntxt, MalBlkPtr mb, MalStkPtr stk,
InstrPtr pci);
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
@@ -2930,7 +2930,8 @@ backend_dumpproc(backend *be, Client c,
if (cq){
SQLaddQueryToCache(c);
// optimize this code the 'old' way
- //SQLoptimizeFunction(c,c->curprg->def,be->mvc);
+ if ( m->emode == m_prepare)
+ SQLoptimizeFunction(c,c->curprg->def,m);
}
// restore the context for the wrapper code
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
@@ -1120,11 +1120,11 @@ SQLparser(Client c)
if (err == 0) {
/* no parsing error encountered, finalize the code of the query
wrapper */
if (be->q) {
- if (m->emode == m_prepare)
+ if (m->emode == m_prepare){
/* For prepared queries, return a table with
result set structure*/
/* optimize the code block and rename it */
err = mvc_export_prepare(m, c->fdout, be->q,
"");
- else if( m->emode == m_execute || m->emode == m_normal
|| m->emode == m_plan){
+ } else if( m->emode == m_execute || m->emode ==
m_normal || m->emode == m_plan){
/* call procedure generation (only in cache
mode) */
backend_call(be, c, be->q);
}
diff --git a/sql/backends/monet5/sql_statement.c
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -1709,24 +1709,24 @@ print_stmt(sql_allocator *sa, stmt *s)
switch (s->type) {
case st_var:
if (s->op1)
- printf("s%d := %s:%s\n", s->nr,
s->op1->op4.aval->data.val.sval, s->op4.typeval.type->base.name);
+ printf("z%d := %s:%s\n", s->nr,
s->op1->op4.aval->data.val.sval, s->op4.typeval.type->base.name);
else
- printf("s%d := A%d:%s\n", s->nr, s->flag,
s->op4.typeval.type->base.name);
+ printf("z%d := A%d:%s\n", s->nr, s->flag,
s->op4.typeval.type->base.name);
break;
case st_atom:
- printf("s%d := '%s':%s\n", s->nr, atom2string(sa, s->op4.aval),
s->op4.aval->tpe.type->base.name);
+ printf("z%d := '%s':%s\n", s->nr, atom2string(sa, s->op4.aval),
s->op4.aval->tpe.type->base.name);
break;
case st_list:{
node *n;
- printf("s%d := %s(", s->nr, st_type2string(s->type));
+ printf("z%d := %s(", s->nr, st_type2string(s->type));
for (n = s->op4.lval->h; n; n = n->next) {
stmt *e = n->data;
- printf("s%d%s", e->nr, n->next ? ", " : "");
+ printf("z%d%s", e->nr, n->next ? ", " : "");
}
printf(");\n");
} break;
default:
- printf("s%d := %s(", s->nr, st_type2string(s->type));
+ printf("z%d := %s(", s->nr, st_type2string(s->type));
switch (s->type) {
case st_temp:
case st_single:
@@ -1767,11 +1767,11 @@ print_stmt(sql_allocator *sa, stmt *s)
break;
}
if (s->op1)
- printf("s%d", s->op1->nr);
+ printf("z%d", s->op1->nr);
if (s->op2)
- printf(", s%d", s->op2->nr);
+ printf(", z%d", s->op2->nr);
if (s->op3)
- printf(", s%d", s->op3->nr);
+ printf(", z%d", s->op3->nr);
printf(");\n");
break;
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list