Changeset: 6774196d9fba for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6774196d9fba
Modified Files:
monetdb5/mal/mal_runtime.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_result.h
sql/include/sql_catalog.h
sql/storage/bat/res_table.c
sql/storage/sql_storage.h
Branch: queryid2
Log Message:
queryid re-implementation
diffs (287 lines):
diff --git a/monetdb5/mal/mal_runtime.c b/monetdb5/mal/mal_runtime.c
--- a/monetdb5/mal/mal_runtime.c
+++ b/monetdb5/mal/mal_runtime.c
@@ -82,6 +82,7 @@ runtimeProfileInit(Client cntxt, MalBlkP
// add new invokation
QRYqueue[i].mb = mb;
QRYqueue[i].tag = qtag++;
+ mb->tag = QRYqueue[i].tag;
QRYqueue[i].stk = stk; // for status pause
'p'/running '0'/ quiting 'q'
QRYqueue[i].start = (lng)time(0);
QRYqueue[i].runtime = mb->runtime; // the estimated execution time
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -1705,7 +1705,7 @@ mvc_result_set_wrap( Client cntxt, MalBl
b = BATdescriptor(bid);
if ( b == NULL)
throw(MAL,"sql.resultset","Failed to access order column");
- res = *res_id = mvc_result_table(m, pci->argc - (pci->retc + 5), 1, b);
+ res = *res_id = mvc_result_table(m, mb->tag, pci->argc - (pci->retc +
5), 1, b);
if (res < 0)
msg = createException(SQL, "sql.resultSet", "failed");
BBPunfix(b->batCacheid);
@@ -1796,7 +1796,7 @@ mvc_export_table_wrap( Client cntxt, Mal
order = BATdescriptor(bid);
if ( order == NULL)
throw(MAL,"sql.resultset","Failed to access order column");
- res = *res_id = mvc_result_table(m, pci->argc - (pci->retc + 11), 1,
order);
+ res = *res_id = mvc_result_table(m, mb->tag, pci->argc - (pci->retc +
11), 1, order);
t = m->results;
if (res < 0){
msg = createException(SQL, "sql.resultSet", "failed");
@@ -1895,7 +1895,7 @@ mvc_row_result_wrap( Client cntxt, MalBl
return msg;
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
- res = *res_id = mvc_result_table(m, pci->argc - (pci->retc + 5), 1,
NULL);
+ res = *res_id = mvc_result_table(m, mb->tag, pci->argc - (pci->retc +
5), 1, NULL);
tbl = BATdescriptor(tblId);
atr = BATdescriptor(atrId);
@@ -1970,7 +1970,7 @@ mvc_export_row_wrap( Client cntxt, MalBl
return msg;
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
- res = *res_id = mvc_result_table(m, pci->argc - (pci->retc + 11), 1,
NULL);
+ res = *res_id = mvc_result_table(m, mb->tag, pci->argc - (pci->retc +
11), 1, NULL);
t = m->results;
if (res < 0){
@@ -2071,7 +2071,7 @@ mvc_table_result_wrap(Client cntxt, MalB
if ((order = BATdescriptor(*order_bid)) == NULL) {
throw(SQL, "sql.resultSet", "Cannot access descriptor");
}
- *res_id = mvc_result_table(m, *nr_cols, *qtype, order);
+ *res_id = mvc_result_table(m, mb->tag, *nr_cols, *qtype, order);
if (*res_id < 0)
res = createException(SQL, "sql.resultSet", "failed");
BBPunfix(order->batCacheid);
@@ -2203,7 +2203,7 @@ mvc_affected_rows_wrap(Client cntxt, Mal
assert(mtype == TYPE_lng);
nr = *getArgReference_lng(stk, pci, 2);
b = cntxt->sqlcontext;
- error = mvc_export_affrows(b, b->out, nr, "");
+ error = mvc_export_affrows(b, b->out, nr, "", mb->tag);
if (error)
throw(SQL, "sql.affectedRows", "failed");
return MAL_SUCCEED;
@@ -2301,12 +2301,11 @@ mvc_scalar_value_wrap(Client cntxt, MalB
str *type = getArgReference_str(stk, pci, 3);
int *digits = getArgReference_int(stk, pci, 4);
int *scale = getArgReference_int(stk, pci, 5);
- int *eclass = getArgReference_int(stk, pci, 6);
ptr p = getArgReference(stk, pci, 7);
int mtype = getArgType(mb, pci, 7);
str msg;
backend *b = NULL;
-
+ int res_id;
(void) mb; /* NOT USED */
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
@@ -2315,13 +2314,14 @@ mvc_scalar_value_wrap(Client cntxt, MalB
p = *(ptr *) p;
// scalar values are single-column result sets
- mvc_result_table(b->mvc, 1, 1, NULL);
+ res_id = mvc_result_table(b->mvc, mb->tag, 1, 1, NULL);
mvc_result_value(b->mvc, *tn, *cn, *type, *digits, *scale, p, mtype);
if (b->output_format == OFMT_NONE) {
return MAL_SUCCEED;
}
- if (b->out == NULL || mvc_export_value(b, b->out, 1, *tn, *cn, *type,
*digits, *scale, *eclass, p, mtype, "", "NULL") != SQL_OK)
+ if (mvc_export_result(b, b->out, res_id) < 0) {
throw(SQL, "sql.exportValue", "failed");
+ }
return MAL_SUCCEED;
}
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
@@ -505,7 +505,6 @@ SQLstatementIntern(Client c, str *expr,
sql->out = NULL; /* no output stream */
if (execute)
msg = SQLrun(c,be,m);
-
MSresetInstructions(c->curprg->def, oldstop);
freeVariables(c, c->curprg->def, NULL, oldvtop);
@@ -521,7 +520,7 @@ SQLstatementIntern(Client c, str *expr,
int ncol = 0;
res_table *res;
for (n = r->exps->h; n; n = n->next) ncol++;
- res = res_table_create(m->session->tr,
m->result_id++, ncol, 1, NULL, NULL);
+ res = res_table_create(m->session->tr,
m->result_id++, 0, ncol, 1, NULL, NULL);
for (n = r->exps->h; n; n = n->next) {
const char *name, *rname;
sql_exp *e = n->data;
diff --git a/sql/backends/monet5/sql_result.c b/sql/backends/monet5/sql_result.c
--- a/sql/backends/monet5/sql_result.c
+++ b/sql/backends/monet5/sql_result.c
@@ -1583,55 +1583,6 @@ export_length(stream *s, int mtype, int
}
int
-mvc_export_value(backend *b, stream *s, int qtype, str tn, str cn, str type,
int d, int sc, int eclass, ptr p, int mtype, str w, str ns)
-{
- mvc *m = b->mvc;
- char *buf = NULL;
- int len = 0;
- int ok = 1;
- char *rsep = "\t]\n";
- int csv = (b->output_format == OFMT_CSV);
- int json = (b->output_format == OFMT_JSON);
-
-#ifdef NDEBUG
- (void) qtype; /* pacify compiler in case asserts are disabled
*/
-#endif
- assert(qtype == Q_TABLE);
-
- if (csv &&
- (mnstr_write(s, "&1 0 1 1 1\n", 11, 1) != 1 ||
- /* fallback to default tuplecount (1) and id (0) */
- /* TODO first header name then values */
- mnstr_write(s, "% ", 2, 1) != 1 ||
- mnstr_write(s, tn, strlen(tn), 1) != 1 ||
- mnstr_write(s, " # table_name\n% ", 16, 1) != 1 ||
- mnstr_write(s, cn, strlen(cn), 1) != 1 ||
- mnstr_write(s, " # name\n% ", 10, 1) != 1 ||
- mnstr_write(s, type, strlen(type), 1) != 1 ||
- mnstr_write(s, " # type\n% ", 10, 1) != 1 ||
- !export_length(s, mtype, eclass, d, sc, has_tz(eclass, type), 0, p)
||
- mnstr_write(s, " # length\n[ ", 12, 1) != 1))
- ok = 0;
- if (ok) {
- if (json) {
- mnstr_write(s, cn, strlen(cn), 1);
- mnstr_write(s, ": ", 2, 1);
- }
- ok = export_value(m, s, eclass, type, d, sc, p, mtype, &buf,
&len, ns);
- }
-
- if (ok && !json)
- ok = (mnstr_write(s, rsep, strlen(rsep), 1) == 1);
-
- if (buf)
- _DELETE(buf);
-
- if (ok)
- ok = mvc_export_warning(s, w);
- return ok;
-}
-
-int
mvc_export_operation(backend *b, stream *s, str w)
{
mvc *m = b->mvc;
@@ -1656,7 +1607,7 @@ mvc_export_operation(backend *b, stream
}
int
-mvc_export_affrows(backend *b, stream *s, lng val, str w)
+mvc_export_affrows(backend *b, stream *s, lng val, str w, oid query_id)
{
mvc *m = b->mvc;
/* if we don't have a stream, nothing can go wrong, so we return
@@ -1670,7 +1621,9 @@ mvc_export_affrows(backend *b, stream *s
m->rowcnt = val;
stack_set_number(m, "rowcnt", m->rowcnt);
- if (mnstr_write(s, "&2 ", 3, 1) != 1 || !mvc_send_lng(s, val) ||
mnstr_write(s, " ", 1, 1) != 1 || !mvc_send_lng(s, m->last_id) ||
mnstr_write(s, "\n", 1, 1) != 1)
+ if (mnstr_write(s, "&2 ", 3, 1) != 1 || !mvc_send_lng(s, val) ||
mnstr_write(s, " ", 1, 1) != 1
+ || !mvc_send_lng(s, m->last_id) || mnstr_write(s, " ",
1, 1) != 1
+ || !mvc_send_lng(s, (lng) query_id) || mnstr_write(s,
"\n", 1, 1) != 1)
return -1;
if (mvc_export_warning(s, w) != 1)
return -1;
@@ -1730,6 +1683,10 @@ mvc_export_head(backend *b, stream *s, i
if (!mvc_send_int(s, (m->reply_size >= 0 && (BUN) m->reply_size <
count) ? m->reply_size : (int) count))
return -1;
+ // export query id
+ if (mnstr_write(s, " ", 1, 1) != 1 || !mvc_send_lng(s, (lng)
t->query_id))
+ return -1;
+
if (mnstr_write(s, "\n% ", 3, 1) != 1)
return -1;
for (i = 0; i < t->nr_cols; i++) {
@@ -1959,9 +1916,9 @@ mvc_export_chunk(backend *b, stream *s,
int
-mvc_result_table(mvc *m, int nr_cols, int type, BAT *order)
+mvc_result_table(mvc *m, oid query_id, int nr_cols, int type, BAT *order)
{
- res_table *t = res_table_create(m->session->tr, m->result_id++,
nr_cols, type, m->results, order);
+ res_table *t = res_table_create(m->session->tr, m->result_id++,
query_id, nr_cols, type, m->results, order);
m->results = t;
return t->id;
}
diff --git a/sql/backends/monet5/sql_result.h b/sql/backends/monet5/sql_result.h
--- a/sql/backends/monet5/sql_result.h
+++ b/sql/backends/monet5/sql_result.h
@@ -17,9 +17,8 @@
#include <sql_qc.h>
#include <sql_parser.h> /* sql_error */
-extern int mvc_export_affrows(backend *b, stream *s, lng val, str w);
+extern int mvc_export_affrows(backend *b, stream *s, lng val, str w, oid
query_id);
extern int mvc_export_operation(backend *b, stream *s, str w);
-extern int mvc_export_value(backend *b, stream *s, int qtype, str tn, str cn,
str type, int d, int sc, int eclass, ptr p, int mtype, str w, str ns);
extern int mvc_export_result(backend *b, stream *s, int res_id);
extern int mvc_export_head(backend *b, stream *s, int res_id, int only_header);
extern int mvc_export_chunk(backend *b, stream *s, int res_id, BUN offset, BUN
nr);
@@ -27,7 +26,7 @@ extern int mvc_export_chunk(backend *b,
extern int mvc_export_prepare(mvc *c, stream *s, cq *q, str w);
extern str mvc_import_table(Client cntxt, BAT ***bats, mvc *c, bstream *s,
sql_table *t, char *sep, char *rsep, char *ssep, char *ns, lng nr, lng offset,
int locked, int best);
-extern int mvc_result_table(mvc *m, int nr_cols, int type, BAT *order);
+extern int mvc_result_table(mvc *m, oid query_id, int nr_cols, int type, BAT
*order);
extern int mvc_result_column(mvc *m, char *tn, char *name, char *typename, int
digits, int scale, BAT *b);
extern int mvc_result_value(mvc *m, char *tn, char *name, char *typename, int
digits, int scale, ptr *p, int mtype);
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -520,6 +520,7 @@ typedef struct res_col {
typedef struct res_table {
int id;
+ oid query_id;
int query_type;
int nr_cols;
int cur_col;
diff --git a/sql/storage/bat/res_table.c b/sql/storage/bat/res_table.c
--- a/sql/storage/bat/res_table.c
+++ b/sql/storage/bat/res_table.c
@@ -24,14 +24,14 @@ bat_decref(bat bid)
res_table *
-res_table_create(sql_trans *tr, int res_id, int nr_cols, int type, res_table
*next, void *O)
+res_table_create(sql_trans *tr, int res_id, oid query_id, int nr_cols, int
type, res_table *next, void *O)
{
BAT *order = (BAT*)O;
res_table *t = ZNEW(res_table);
(void) tr;
t->id = res_id;
-
+ t->query_id = query_id;
t->query_type = type;
t->nr_cols = nr_cols;
t->cur_col = 0;
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -312,7 +312,7 @@ sqlstore_export logger_functions logger_
/* we need to add an interface for result_tables later */
-extern res_table *res_table_create(sql_trans *tr, int res_id, int nr_cols, int
querytype, res_table *next, void *order);
+extern res_table *res_table_create(sql_trans *tr, int res_id, oid query_id,
int nr_cols, int querytype, res_table *next, void *order);
extern res_col *res_col_create(sql_trans *tr, res_table *t, const char *tn,
const char *name, const char *typename, int digits, int scale, int mtype, void
*v);
extern void res_table_destroy(res_table *t);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list