Changeset: 70ed4b302a50 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=70ed4b302a50
Modified Files:
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_gencode.c
sql/backends/monet5/sql_user.c
Branch: port-monetdblite
Log Message:
Backported SQL plan output and SQL user administration
diffs (truncated from 513 to 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
@@ -33,10 +33,12 @@
#include "rel_rel.h"
#include "rel_exp.h"
#include "rel_dump.h"
-#include "mal_debugger.h"
#include "mtime.h"
#include "optimizer.h"
#include "opt_inline.h"
+#ifndef HAVE_EMBEDDED
+#include "mal_debugger.h"
+#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
@@ -64,6 +66,7 @@
* is executed within the client context specified. This leads to context
juggling.
*/
+#ifndef HAVE_EMBEDDED
/*
* The trace operation collects the events in the BATs
* and creates a secondary result set upon termination
@@ -190,6 +193,7 @@ SQLsetTrace(Client cntxt, MalBlkPtr mb)
return msg;
}
+#endif
/*
* Execution of the SQL program is delegated to the MALengine.
@@ -269,8 +273,10 @@ SQLexecutePrepared(Client c, backend *be
v->val.ival = int_nil;
}
q->stk = (backend_stack) glb; /* save garbageCollected stack */
+#ifndef HAVE_EMBEDDED
if (glb && SQLdebug & 1)
printStack(GDKstdout, mb, glb);
+#endif
if (pci->argc >= MAXARG && argv != argvbuffer)
GDKfree(argv);
if (pci->retc >= MAXARG && argrec != argrecbuffer)
@@ -364,18 +370,20 @@ SQLrun(Client c, backend *be, mvc *m)
if (m->emod & mod_explain) {
if (c->curprg->def)
printFunction(c->fdout, mb, 0, LIST_MAL_NAME |
LIST_MAL_VALUE | LIST_MAL_TYPE | LIST_MAL_MAPI);
- } else if( m->emod & mod_debug) {
+ }
+#ifndef HAVE_EMBEDDED
+ else if( m->emod & mod_debug) {
msg = runMALDebugger(c, mb);
- } else {
- if( m->emod & mod_trace){
- if((msg = SQLsetTrace(c,mb)) == MAL_SUCCEED) {
- msg = runMAL(c, mb, 0, 0);
- stopTrace(0);
- }
- } else {
+ } else if( m->emod & mod_trace){
+ if((msg = SQLsetTrace(c,mb)) == MAL_SUCCEED) {
msg = runMAL(c, mb, 0, 0);
+ stopTrace(0);
}
}
+#endif
+ else {
+ msg = runMAL(c, mb, 0, 0);
+ }
// release the resources
freeMalBlk(mb);
@@ -592,6 +600,43 @@ SQLstatementIntern(Client c, str *expr,
mnstr_printf(c->fdout, "#SQLstatement:\n");
#endif
scanner_query_processed(&(m->scanner));
+
+#ifdef HAVE_EMBEDDED
+ // PLAN output
+ if (m->emode == m_plan && mvc_status(m) == 0) {
+ list *refs = sa_list(m->sa);
+ stream *s;
+ buffer *b = buffer_create(16364); /* hopefully enough */
+ if (!b) {
+ msg = createException(PARSE, "SQLparser",
"Memory allocation failed");
+ goto endofcompile;
+ }
+ s = buffer_wastream(b, "SQL Plan");
+ if (!s) {
+ msg = createException(PARSE, "SQLparser",
"Memory allocation failed");
+ buffer_destroy(b);
+ goto endofcompile;
+ }
+
+ rel_print_refs(m, s, r, 0, refs, 1);
+ rel_print_(m, s, r, 0, refs, 1);
+ mnstr_printf(s, "\n");
+ mnstr_writeBte(s, 0);
+
+ *result = res_table_create(m->session->tr,
m->result_id++, 1, 1, 1, NULL, NULL);
+ if (!*result) {
+ msg = createException(PARSE, "SQLparser",
"Memory allocation failed");
+ } else {
+ res_col_create(m->session->tr, *result, "plan",
"plan", "varchar", 0, 0, TYPE_str, b->buf);
+ }
+
+ mnstr_close(s);
+ mnstr_destroy(s);
+ buffer_destroy(b);
+
+ goto endofcompile;
+ }
+#endif
if ((err = mvc_status(m)) ) {
if (strlen(m->errstr) > 6 && m->errstr[5] ==
'!')
msg = createException(PARSE,
"SQLparser", "%s", m->errstr);
@@ -620,8 +665,9 @@ SQLstatementIntern(Client c, str *expr,
mnstr_printf(c->fdout, "#SQLstatement:post-compile\n");
printFunction(c->fdout, c->curprg->def, 0, LIST_MAL_NAME |
LIST_MAL_VALUE | LIST_MAL_MAPI);
#endif
+#ifndef HAVE_EMBEDDED
msg = SQLoptimizeFunction(c, c->curprg->def);
-
+#endif
if (err || c->curprg->def->errors || msg) {
/* restore the state */
MSresetInstructions(c->curprg->def, oldstop);
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
@@ -36,9 +36,13 @@
#include "sql_optimizer.h"
#include "mal_namespace.h"
#include "opt_prelude.h"
+#include "mal_builder.h"
+
+#ifndef HAVE_EMBEDDED
+#include "muuid.h"
#include "querylog.h"
-#include "mal_builder.h"
#include "mal_debugger.h"
+#endif
#include "rel_select.h"
#include "rel_optimizer.h"
@@ -52,8 +56,6 @@
#include "rel_dump.h"
#include "rel_remote.h"
-#include "muuid.h"
-
int
constantAtom(backend *sql, MalBlkPtr mb, atom *a)
{
@@ -269,6 +271,7 @@ cleanup:
return res;
}
+#ifndef HAVE_EMBEDDED
/* stub and remote function */
static int
_create_relational_remote(mvc *m, const char *mod, const char *name, sql_rel
*rel, stmt *call, prop *prp)
@@ -574,16 +577,18 @@ static int
GDKfree(lname); /* make sure stub is called */
return 0;
}
+#endif
int
monet5_create_relational_function(mvc *m, const char *mod, const char *name,
sql_rel *rel, stmt *call, list *rel_ops, int inline_func)
{
prop *p = NULL;
+#ifndef HAVE_EMBEDDED
if (rel && (p = find_prop(rel->p, PROP_REMOTE)) != NULL)
return _create_relational_remote(m, mod, name, rel, call, p);
- else
- return _create_relational_function(m, mod, name, rel, call,
rel_ops, inline_func);
+#endif
+ return _create_relational_function(m, mod, name, rel, call, rel_ops,
inline_func);
}
/*
@@ -601,7 +606,38 @@ sql_relation2stmt(backend *be, sql_rel *
return NULL;
} else {
if (c->emode == m_plan) {
+#ifdef HAVE_EMBEDDED
+ list *refs = sa_list(c->sa);
+ stream *s;
+ buffer *b = buffer_create(16364); /* hopefully enough */
+ if (!b)
+ return NULL;
+ s = buffer_wastream(b, "SQL Plan");
+ if (!s) {
+ buffer_destroy(b);
+ return NULL;
+ }
+
+ rel_print_refs(c, s, r, 0, refs, 1);
+ rel_print_(c, s, r, 0, refs, 1);
+ mnstr_printf(s, "\n");
+ mnstr_writeBte(s, 0);
+
+ c->results = res_table_create(c->session->tr,
c->result_id++, 1, 1, 1, NULL, NULL);
+ if (!c->results) {
+ mnstr_close(s);
+ mnstr_destroy(s);
+ buffer_destroy(b);
+ return NULL;
+ } else {
+ res_col_create(c->session->tr, c->results,
"plan", "plan", "varchar", 0, 0, TYPE_str, b->buf);
+ }
+
+ close_stream(s);
+ buffer_destroy(b);
+#else
rel_print(c, r, 0);
+#endif
} else {
s = output_rel_bin(be, r);
}
@@ -619,7 +655,7 @@ backend_dumpstmt(backend *be, MalBlkPtr
stmt *s;
// Always keep the SQL query around for monitoring
-
+#ifndef HAVE_EMBEDDED
if (query) {
while (*query && isspace((unsigned char) *query))
query++;
@@ -636,7 +672,9 @@ backend_dumpstmt(backend *be, MalBlkPtr
return -1;
}
}
-
+#else
+ (void) query;
+#endif
/* announce the transaction mode */
q = newStmt(mb, sqlRef, "mvc");
if (q == NULL)
@@ -1219,6 +1257,7 @@ void
mnstr_printf(GDKstdout, "\n");
}
+#ifndef HAVE_EMBEDDED
void
rel_print(mvc *sql, sql_rel *rel, int depth)
{
@@ -1266,4 +1305,4 @@ rel_print(mvc *sql, sql_rel *rel, int de
close_stream(s);
buffer_destroy(b);
}
-
+#endif
diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c
--- a/sql/backends/monet5/sql_user.c
+++ b/sql/backends/monet5/sql_user.c
@@ -22,7 +22,9 @@
#include "bat5.h"
#include "mal_interpreter.h"
#include "mal_authorize.h"
+#ifndef HAVE_EMBEDDED
#include "mcrypt.h"
+#endif
#if 0
int
@@ -53,6 +55,11 @@ static int
monet5_drop_user(ptr _mvc, str user)
{
mvc *m = (mvc *) _mvc;
+#ifdef HAVE_EMBEDDED
+ (void) user;
+ (void) sql_error(m, 02, SQLSTATE(42000) "DROP USER: user administration
not available in MonetDBLite version");
+ return FALSE;
+#else
oid rid;
sql_schema *sys;
sql_table *users;
@@ -62,7 +69,7 @@ monet5_drop_user(ptr _mvc, str user)
err = AUTHremoveUser(c, user);
if (err !=MAL_SUCCEED) {
- (void) sql_error(m, 02, "DROP USER: %s",
getExceptionMessage(err));
+ (void) sql_error(m, 02, SQLSTATE(42000) "DROP USER: %s",
getExceptionMessage(err));
_DELETE(err);
return FALSE;
}
@@ -80,11 +87,22 @@ monet5_drop_user(ptr _mvc, str user)
* administration. */
return TRUE;
+#endif
}
static str
monet5_create_user(ptr _mvc, str user, str passwd, char enc, str fullname,
sqlid schema_id, sqlid grantorid)
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list