Changeset: 9d1407697ceb for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9d1407697ceb
Modified Files:
clients/mapiclient/mclient.c
clients/mapilib/mapi.c
clients/mapilib/mapi.h
monetdb5/optimizer/opt_support.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_result.c
sql/backends/monet5/sql_result.h
Branch: default
Log Message:
Returning MAL optimizer cost
The total time spent by the MAL optimizers is gathered on a query basis.
It is returned to the frontend and currently made visible using the -ftimer
option.
sql>select * from tables;
12.120ms sql:0 opt:1269 run:5669
Remains to take care of is the sql optimizer phase
diffs (truncated from 377 to 300 lines):
diff --git a/clients/mapiclient/mclient.c b/clients/mapiclient/mclient.c
--- a/clients/mapiclient/mclient.c
+++ b/clients/mapiclient/mclient.c
@@ -1301,11 +1301,11 @@ RAWrenderer(MapiHdl hdl)
}
static void
-TIMERrenderer(MapiHdl hdl, int64_t querytime)
+TIMERrenderer(MapiHdl hdl, int64_t querytime, int64_t maloptimizertime)
{
SQLqueryEcho(hdl);
mapi_next_result(hdl);
- printf("%" PRId64 " %s\n", querytime, timerHuman());
+ printf("%s sql:0 opt:%" PRId64 " run:%" PRId64 "\n", timerHuman(),
maloptimizertime, querytime);
}
@@ -1827,6 +1827,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
int64_t aff, lid;
char *reply;
int64_t querytime;
+ int64_t maloptimizer;
#ifdef HAVE_POPEN
stream *saveFD;
@@ -1860,12 +1861,13 @@ format_result(Mapi mid, MapiHdl hdl, cha
continue;
case Q_UPDATE:
querytime = mapi_get_querytime(hdl);
+ maloptimizer = mapi_get_maloptimizertime(hdl);
SQLqueryEcho(hdl);
if (formatter == RAWformatter ||
formatter == TESTformatter)
mnstr_printf(toConsole, "[ %" PRId64 "\t]\n",
mapi_rows_affected(hdl));
else if (formatter == TIMERformatter)
- printf("%" PRId64 " %s\n", querytime,
timerHuman());
+ TIMERrenderer(hdl, querytime, maloptimizer);
else {
aff = mapi_rows_affected(hdl);
lid = mapi_get_last_id(hdl);
@@ -1887,6 +1889,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
continue;
case Q_SCHEMA:
querytime = mapi_get_querytime(hdl);
+ maloptimizer = mapi_get_maloptimizertime(hdl);
SQLqueryEcho(hdl);
if (formatter == TABLEformatter) {
mnstr_printf(toConsole, "operation successful");
@@ -1895,7 +1898,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
timerHuman());
mnstr_printf(toConsole, "\n");
} else if (formatter == TIMERformatter)
- printf("%" PRId64 " %s\n", querytime,
timerHuman());
+ TIMERrenderer(hdl, querytime, maloptimizer);
continue;
case Q_TRANS:
SQLqueryEcho(hdl);
@@ -1914,6 +1917,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
break;
case Q_TABLE:
querytime = mapi_get_querytime(hdl);
+ maloptimizer = mapi_get_maloptimizertime(hdl);
break;
default:
if (formatter == TABLEformatter && specials !=
DEBUGmodifier) {
@@ -1974,7 +1978,7 @@ format_result(Mapi mid, MapiHdl hdl, cha
}
break;
case TIMERformatter:
- TIMERrenderer(hdl, querytime);
+ TIMERrenderer(hdl, querytime, maloptimizer);
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
@@ -885,6 +885,7 @@ struct MapiResultSet {
int64_t row_count;
int64_t last_id;
int64_t querytime;
+ int64_t maloptimizertime;
int fieldcnt;
int maxfields;
char *errorstr; /* error from server */
@@ -1450,6 +1451,7 @@ new_result(MapiHdl hdl)
result->querytype = -1;
result->errorstr = NULL;
result->querytime = 0;
+ result->maloptimizertime = 0;
memset(result->sqlstate, 0, sizeof(result->sqlstate));
result->tuple_count = 0;
@@ -3759,6 +3761,7 @@ parse_header_line(MapiHdl hdl, char *lin
result->querytype = qt;
result->commentonly = 0;
result->querytime = 0;
+ result->maloptimizertime = 0;
nline++; /* skip space */
switch (qt) {
@@ -3776,13 +3779,16 @@ parse_header_line(MapiHdl hdl, char *lin
result->last_id = strtoll(nline, &nline, 10);
queryid = strtoll(nline, &nline, 10);
result->querytime = strtoll(nline, &nline, 10);
+ result->maloptimizertime = strtoll(nline, &nline, 10);
break;
case Q_TABLE:
- if (sscanf(nline, "%d %" SCNd64 " %d %" SCNd64 " %"
SCNu64 " %" SCNd64,
+ if (sscanf(nline, "%d %" SCNd64 " %d %" SCNd64 " %"
SCNu64 " %" SCNd64 " %" SCNd64,
&result->tableid, &result->row_count,
&result->fieldcnt, &result->tuple_count,
- &queryid, &result->querytime) < 6)
- result->querytime = 0;
+ &queryid, &result->querytime,
&result->maloptimizertime) < 7){
+ result->querytime = 0;
+ result->maloptimizertime = 0;
+ }
(void) queryid; /* ignored for now */
break;
case Q_PREPARE:
@@ -5311,6 +5317,17 @@ mapi_get_querytime(MapiHdl hdl)
return result->querytime;
}
+int64_t
+mapi_get_maloptimizertime(MapiHdl hdl)
+{
+ struct MapiResultSet *result;
+
+ mapi_hdl_check(hdl, "mapi_get_maloptimizertime");
+ if ((result = hdl->result) == NULL)
+ return 0;
+ return result->maloptimizertime;
+}
+
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
@@ -191,6 +191,7 @@ mapi_export int64_t mapi_get_row_count(M
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 int64_t mapi_get_maloptimizertime(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/monetdb5/optimizer/opt_support.c b/monetdb5/optimizer/opt_support.c
--- a/monetdb5/optimizer/opt_support.c
+++ b/monetdb5/optimizer/opt_support.c
@@ -97,6 +97,7 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
if ( mb->inlineProp)
return 0;
+ mb->optimize = 0;
if (mb->errors)
throw(MAL, "optimizer.MALoptimizer", "Start with inconsistent
MAL plan");
@@ -140,8 +141,10 @@ optimizeMALBlock(Client cntxt, MalBlkPtr
}
goto wrapup;
}
- if (cntxt->mode == FINISHCLIENT)
+ if (cntxt->mode == FINISHCLIENT){
+ mb->optimize = GDKusec() - clk;
throw(MAL, "optimizeMALBlock",
"prematurely stopped client");
+ }
pc= -1;
}
}
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
@@ -1929,7 +1929,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,
mb->starttime))
+ if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res,
mb->starttime, mb->optimize))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
wrapup_result_set:
if( tbl) BBPunfix(tblId);
@@ -2071,7 +2071,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, mb->starttime))
+ if (mvc_export_result(cntxt->sqlcontext, s, res, mb->starttime,
mb->optimize))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
if( s != cntxt->fdout)
close_stream(s);
@@ -2137,7 +2137,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,
mb->starttime))
+ if (mvc_export_result(cntxt->sqlcontext, cntxt->fdout, res,
mb->starttime, mb->optimize))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
wrapup_result_set:
if( tbl) BBPunfix(tblId);
@@ -2271,7 +2271,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, mb->starttime))
+ if (mvc_export_result(cntxt->sqlcontext, s, res, mb->starttime,
mb->optimize))
msg = createException(SQL, "sql.resultset", SQLSTATE(45000)
"Result set construction failed");
if( s != cntxt->fdout)
mnstr_close(s);
@@ -2337,7 +2337,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, mb->starttime);
+ error = mvc_export_affrows(b, b->out, nr, "", mb->tag, mb->starttime,
mb->optimize);
if (error)
throw(SQL, "sql.affectedRows", SQLSTATE(45000) "Result set
construction failed");
return MAL_SUCCEED;
@@ -2356,7 +2356,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, mb->starttime))
+ if (mvc_export_head(b, *s, res_id, FALSE, TRUE, mb->starttime,
mb->optimize))
throw(SQL, "sql.exportHead", SQLSTATE(45000) "Result set
construction failed");
return MAL_SUCCEED;
}
@@ -2376,9 +2376,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, mb->starttime))
+ if (mvc_export_result(b, cntxt->fdout, res_id, mb->starttime,
mb->optimize))
throw(SQL, "sql.exportResult", SQLSTATE(45000) "Result
set construction failed");
- } else if (mvc_export_result(b, *s, res_id, mb->starttime))
+ } else if (mvc_export_result(b, *s, res_id, mb->starttime,
mb->optimize))
throw(SQL, "sql.exportResult", SQLSTATE(45000) "Result set
construction failed");
return MAL_SUCCEED;
}
@@ -2420,7 +2420,7 @@ mvc_export_operation_wrap(Client cntxt,
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
b = cntxt->sqlcontext;
- if (mvc_export_operation(b, b->out, "", mb->starttime))
+ if (mvc_export_operation(b, b->out, "", mb->starttime, mb->optimize))
throw(SQL, "sql.exportOperation", SQLSTATE(45000) "Result set
construction failed");
return NULL;
}
@@ -2453,7 +2453,7 @@ mvc_scalar_value_wrap(Client cntxt, MalB
if (b->output_format == OFMT_NONE) {
return MAL_SUCCEED;
}
- if (mvc_export_result(b, b->out, res_id, mb->starttime) < 0) {
+ if (mvc_export_result(b, b->out, res_id, mb->starttime, mb->optimize) <
0) {
throw(SQL, "sql.exportValue", SQLSTATE(45000) "Result set
construction failed");
}
return MAL_SUCCEED;
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
@@ -2081,7 +2081,7 @@ export_length(stream *s, int mtype, int
}
int
-mvc_export_operation(backend *b, stream *s, str w, lng starttime)
+mvc_export_operation(backend *b, stream *s, str w, lng starttime, lng
mal_optimizer)
{
mvc *m = b->mvc;
@@ -2089,6 +2089,8 @@ mvc_export_operation(backend *b, stream
if (m->type == Q_SCHEMA) {
if (!s || mnstr_printf(s, "&3 " LLFMT "\n", starttime > 0 ?
GDKusec() - starttime : 0) < 0)
return -1;
+ if (!s || mnstr_printf(s, "&3 " LLFMT "\n", mal_optimizer) < 0)
+ return -1;
} else {
if (m->session->auto_commit) {
if (mnstr_write(s, "&4 t\n", 5, 1) != 1)
@@ -2105,7 +2107,7 @@ mvc_export_operation(backend *b, stream
}
int
-mvc_export_affrows(backend *b, stream *s, lng val, str w, oid query_id, lng
starttime)
+mvc_export_affrows(backend *b, stream *s, lng val, str w, oid query_id, lng
starttime, lng maloptimizer)
{
mvc *m = b->mvc;
/* if we don't have a stream, nothing can go wrong, so we return
@@ -2127,6 +2129,8 @@ mvc_export_affrows(backend *b, stream *s
!mvc_send_lng(s, (lng) query_id) ||
mnstr_write(s, " ", 1, 1) != 1 ||
!mvc_send_lng(s, starttime > 0 ? GDKusec() - starttime : 0) ||
+ mnstr_write(s, " ", 1, 1) != 1 ||
+ !mvc_send_lng(s, maloptimizer) ||
mnstr_write(s, "\n", 1, 1) != 1)
return -1;
if (mvc_export_warning(s, w) != 1)
@@ -2305,7 +2309,7 @@ cleanup:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list