Changeset: b06016bb60a1 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b06016bb60a1
Modified Files:
clients/Tests/exports.stable.out
clients/mapiclient/mclient.c
clients/mapilib/mapi.c
clients/mapilib/mapi.h
sql/backends/monet5/sql.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_result.h
Branch: default
Log Message:
Send execution time of query to client.
We extended some of the "&N" fields in the MAPI protocol header with
an extra field which contains the execution time of the query in
microseconds. Currently, only mclient does anything with this extra
information, and then only when the "timer" format is used (-ftimer
option or \ftimer command).
diffs (truncated from 435 to 300 lines):
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -533,6 +533,7 @@ char *mapi_get_monet_version(Mapi mid);
char *mapi_get_motd(Mapi mid);
char *mapi_get_name(MapiHdl hdl, int fnr);
char *mapi_get_query(MapiHdl hdl);
+int64_t mapi_get_querytime(MapiHdl hdl);
int mapi_get_querytype(MapiHdl hdl);
int64_t mapi_get_row_count(MapiHdl hdl);
int mapi_get_scale(MapiHdl hdl, int fnr);
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -295,18 +295,18 @@ timerHuman(void)
assert(th >= t0);
if (itimemode == T_MILLIS || (itimemode == T_HUMAN && t / 1000 < 950)) {
- snprintf(htimbuf, 32, TTFMT ".%03dms", t / 1000, (int) (t %
1000));
+ snprintf(htimbuf, sizeof(htimbuf), TTFMT ".%03dms", t / 1000,
(int) (t % 1000));
return(htimbuf);
}
t /= 1000;
if (itimemode == T_SECS || (itimemode == T_HUMAN && t / 1000 < 60)) {
- snprintf(htimbuf, 32, TTFMT ".%ds", t / 1000,
+ snprintf(htimbuf, sizeof(htimbuf), TTFMT ".%ds", t / 1000,
(int) ((t % 1000) / 100));
return(htimbuf);
}
t /= 1000;
/* itimemode == T_MINSECS || itimemode == T_HUMAN */
- snprintf(htimbuf, 32, TTFMT "m %ds", t / 60, (int) (t % 60));
+ snprintf(htimbuf, sizeof(htimbuf), TTFMT "m %ds", t / 60, (int) (t %
60));
return(htimbuf);
}
@@ -1301,11 +1301,11 @@ RAWrenderer(MapiHdl hdl)
}
static void
-TIMERrenderer(MapiHdl hdl)
+TIMERrenderer(MapiHdl hdl, int64_t querytime)
{
SQLqueryEcho(hdl);
mapi_next_result(hdl);
- printf("%s\n", timerHuman());
+ printf("%" PRId64 " %s\n", querytime, timerHuman());
}
@@ -1826,6 +1826,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
MapiMsg rc = MERROR;
int64_t aff, lid;
char *reply;
+ int64_t querytime;
#ifdef HAVE_POPEN
stream *saveFD;
@@ -1851,18 +1852,20 @@ format_result(Mapi mid, MapiHdl hdl, cha
}
timerHumanStop();
+ querytime = 0;
switch (mapi_get_querytype(hdl)) {
case Q_BLOCK:
case Q_PARSE:
/* should never see these */
continue;
case Q_UPDATE:
+ querytime = mapi_get_querytime(hdl);
SQLqueryEcho(hdl);
if (formatter == RAWformatter ||
formatter == TESTformatter)
mnstr_printf(toConsole, "[ %" PRId64 "\t]\n",
mapi_rows_affected(hdl));
else if (formatter == TIMERformatter)
- printf("%s\n", timerHuman());
+ printf("%" PRId64 " %s\n", querytime,
timerHuman());
else {
aff = mapi_rows_affected(hdl);
lid = mapi_get_last_id(hdl);
@@ -1883,6 +1886,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
}
continue;
case Q_SCHEMA:
+ querytime = mapi_get_querytime(hdl);
SQLqueryEcho(hdl);
if (formatter == TABLEformatter) {
mnstr_printf(toConsole, "operation successful");
@@ -1891,7 +1895,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
timerHuman());
mnstr_printf(toConsole, "\n");
} else if (formatter == TIMERformatter)
- printf("%s\n", timerHuman());
+ printf("%" PRId64 " %s\n", querytime,
timerHuman());
continue;
case Q_TRANS:
SQLqueryEcho(hdl);
@@ -1907,8 +1911,9 @@ format_result(Mapi mid, MapiHdl hdl, cha
"execute prepared statement "
"using: EXEC %d(...)\n",
mapi_get_tableid(hdl));
- /* fall through */
+ break;
case Q_TABLE:
+ querytime = mapi_get_querytime(hdl);
break;
default:
if (formatter == TABLEformatter && specials !=
DEBUGmodifier) {
@@ -1969,7 +1974,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
}
break;
case TIMERformatter:
- TIMERrenderer(hdl);
+ TIMERrenderer(hdl, querytime);
break;
case SAMformatter:
SAMrenderer(hdl);
diff --git a/clients/mapilib/mapi.c b/clients/mapilib/mapi.c
--- a/clients/mapilib/mapi.c
+++ b/clients/mapilib/mapi.c
@@ -884,6 +884,7 @@ struct MapiResultSet {
int64_t tuple_count;
int64_t row_count;
int64_t last_id;
+ int64_t querytime;
int fieldcnt;
int maxfields;
char *errorstr; /* error from server */
@@ -1448,6 +1449,7 @@ new_result(MapiHdl hdl)
result->tableid = -1;
result->querytype = -1;
result->errorstr = NULL;
+ result->querytime = 0;
memset(result->sqlstate, 0, sizeof(result->sqlstate));
result->tuple_count = 0;
@@ -3745,6 +3747,7 @@ parse_header_line(MapiHdl hdl, char *lin
if (line[0] == '&') {
char *nline = line;
int qt;
+ uint64_t queryid;
/* handle fields &qt */
@@ -3755,9 +3758,13 @@ parse_header_line(MapiHdl hdl, char *lin
result = new_result(hdl);
result->querytype = qt;
result->commentonly = 0;
+ result->querytime = 0;
nline++; /* skip space */
switch (qt) {
+ case Q_SCHEMA:
+ result->querytime = strtoll(nline, &nline, 10);
+ break;
case Q_TRANS:
if (*nline == 'f')
hdl->mid->auto_commit = 0;
@@ -3765,14 +3772,24 @@ parse_header_line(MapiHdl hdl, char *lin
hdl->mid->auto_commit = 1;
break;
case Q_UPDATE:
- result->row_count = strtoll(nline, &nline, 0);
- result->last_id = strtoll(nline, &nline, 0);
+ result->row_count = strtoll(nline, &nline, 10);
+ result->last_id = strtoll(nline, &nline, 10);
+ queryid = strtoll(nline, &nline, 10);
+ result->querytime = strtoll(nline, &nline, 10);
break;
case Q_TABLE:
- case Q_PREPARE:{
- sscanf(nline, "%d %" SCNd64 " %d %" SCNd64,
&result->tableid, &result->row_count, &result->fieldcnt, &result->tuple_count);
+ if (sscanf(nline, "%d %" SCNd64 " %d %" SCNd64 " %"
SCNu64 " %" SCNd64,
+ &result->tableid, &result->row_count,
+ &result->fieldcnt, &result->tuple_count,
+ &queryid, &result->querytime) < 6)
+ result->querytime = 0;
+ (void) queryid; /* ignored for now */
break;
- }
+ case Q_PREPARE:
+ sscanf(nline, "%d %" SCNd64 " %d %" SCNd64,
+ &result->tableid, &result->row_count,
+ &result->fieldcnt, &result->tuple_count);
+ break;
case Q_BLOCK:
/* Mapi ignores the Q_BLOCK header, so spoof the
querytype
* back to a Q_TABLE to let it go unnoticed */
@@ -5283,6 +5300,17 @@ mapi_rows_affected(MapiHdl hdl)
return result->row_count;
}
+int64_t
+mapi_get_querytime(MapiHdl hdl)
+{
+ struct MapiResultSet *result;
+
+ mapi_hdl_check(hdl, "mapi_get_querytime");
+ if ((result = hdl->result) == NULL)
+ return 0;
+ return result->querytime;
+}
+
char *
mapi_get_dbname(Mapi mid)
{
diff --git a/clients/mapilib/mapi.h b/clients/mapilib/mapi.h
--- a/clients/mapilib/mapi.h
+++ b/clients/mapilib/mapi.h
@@ -190,6 +190,7 @@ mapi_export int mapi_get_field_count(Map
mapi_export int64_t mapi_get_row_count(MapiHdl hdl);
mapi_export int64_t mapi_get_last_id(MapiHdl hdl);
mapi_export int64_t mapi_rows_affected(MapiHdl hdl);
+mapi_export int64_t mapi_get_querytime(MapiHdl hdl);
mapi_export char *mapi_fetch_field(MapiHdl hdl, int fnr);
mapi_export size_t mapi_fetch_field_len(MapiHdl hdl, int fnr);
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
@@ -1928,7 +1928,7 @@ mvc_result_set_wrap( Client cntxt, MalBl
BBPunfix(bid);
}
/* now send it to the channel cntxt->fdout */
- if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res))
+ if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res,
mb->starttime))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
wrapup_result_set:
if( tbl) BBPunfix(tblId);
@@ -2070,7 +2070,7 @@ mvc_export_table_wrap( Client cntxt, Mal
filename?filename:"stdout",
strerror(errnr));
goto wrapup_result_set1;
}
- if (mvc_export_result(cntxt->sqlcontext, s, res))
+ if (mvc_export_result(cntxt->sqlcontext, s, res, mb->starttime))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
if( s != cntxt->fdout)
close_stream(s);
@@ -2136,7 +2136,7 @@ mvc_row_result_wrap( Client cntxt, MalBl
if (mvc_result_value(m, tblname, colname, tpename, *digits++,
*scaledigits++, v, mtype))
throw(SQL, "sql.rsColumn", SQLSTATE(45000) "Result set
construction failed");
}
- if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res))
+ if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res,
mb->starttime))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
wrapup_result_set:
if( tbl) BBPunfix(tblId);
@@ -2270,7 +2270,7 @@ mvc_export_row_wrap( Client cntxt, MalBl
filename?filename:"stdout",
strerror(errnr));
goto wrapup_result_set;
}
- if (mvc_export_result(cntxt->sqlcontext, s, res))
+ if (mvc_export_result(cntxt->sqlcontext, s, res, mb->starttime))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
if( s != cntxt->fdout)
mnstr_close(s);
@@ -2336,7 +2336,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, "", mb->tag);
+ error = mvc_export_affrows(b, b->out, nr, "", mb->tag, mb->starttime);
if (error)
throw(SQL, "sql.affectedRows", SQLSTATE(45000) "Result set
construction failed");
return MAL_SUCCEED;
@@ -2355,7 +2355,7 @@ mvc_export_head_wrap(Client cntxt, MalBl
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
b = cntxt->sqlcontext;
- if (mvc_export_head(b, *s, res_id, FALSE, TRUE))
+ if (mvc_export_head(b, *s, res_id, FALSE, TRUE, mb->starttime))
throw(SQL, "sql.exportHead", SQLSTATE(45000) "Result set
construction failed");
return MAL_SUCCEED;
}
@@ -2375,9 +2375,9 @@ mvc_export_result_wrap(Client cntxt, Mal
b = cntxt->sqlcontext;
if( pci->argc > 5){
res_id = *getArgReference_int(stk, pci, 2);
- if (mvc_export_result(b, cntxt->fdout, res_id))
+ if (mvc_export_result(b, cntxt->fdout, res_id, mb->starttime))
throw(SQL, "sql.exportResult", SQLSTATE(45000) "Result
set construction failed");
- } else if (mvc_export_result(b, *s, res_id))
+ } else if (mvc_export_result(b, *s, res_id, mb->starttime))
throw(SQL, "sql.exportResult", SQLSTATE(45000) "Result set
construction failed");
return MAL_SUCCEED;
}
@@ -2414,13 +2414,12 @@ mvc_export_operation_wrap(Client cntxt,
backend *b = NULL;
str msg;
- (void) mb; /* NOT USED */
(void) stk; /* NOT USED */
(void) pci; /* NOT USED */
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
b = cntxt->sqlcontext;
- if (mvc_export_operation(b, b->out, ""))
+ if (mvc_export_operation(b, b->out, "", mb->starttime))
throw(SQL, "sql.exportOperation", SQLSTATE(45000) "Result set
construction failed");
return NULL;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list