Changeset: 5ff665109dfb for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5ff665109dfb
Modified Files:
        monetdb5/modules/mal/querylog.c
        monetdb5/modules/mal/querylog.h
        monetdb5/modules/mal/querylog.mal
        monetdb5/optimizer/opt_querylog.c
        sql/backends/monet5/sql.mx
        sql/scripts/15_querylog.sql
Branch: default
Log Message:

Extend query log with MAL column
The MAL column contains the hint on the total number of MAL instructions.


diffs (199 lines):

diff --git a/monetdb5/modules/mal/querylog.c b/monetdb5/modules/mal/querylog.c
--- a/monetdb5/modules/mal/querylog.c
+++ b/monetdb5/modules/mal/querylog.c
@@ -75,6 +75,7 @@ static BAT *QLOG_cat_user = 0;
 static BAT *QLOG_cat_defined = 0;
 static BAT *QLOG_cat_query = 0;
 static BAT *QLOG_cat_pipe = 0;
+static BAT *QLOG_cat_mal = 0;
 static BAT *QLOG_cat_optimize = 0;
 
 static BAT *QLOG_calls_id = 0;
@@ -92,7 +93,7 @@ void
 QLOGcatalog(BAT **r)
 {
        int i;
-       for ( i=0;i < 6; i++)
+       for ( i=0;i < 7; i++)
                r[i]=0;
     if (initQlog())
         return ;
@@ -102,7 +103,8 @@ QLOGcatalog(BAT **r)
        r[2] = BATcopy(QLOG_cat_defined, TYPE_oid, QLOG_cat_defined->ttype,0);
        r[3] = BATcopy(QLOG_cat_query, TYPE_oid, QLOG_cat_query->ttype,0);
        r[4] = BATcopy(QLOG_cat_pipe, TYPE_oid, QLOG_cat_pipe->ttype,0);
-       r[5] = BATcopy(QLOG_cat_optimize, TYPE_oid, QLOG_cat_optimize->ttype,0);
+       r[5] = BATcopy(QLOG_cat_mal, TYPE_oid, QLOG_cat_mal->ttype,0);
+       r[6] = BATcopy(QLOG_cat_optimize, TYPE_oid, QLOG_cat_optimize->ttype,0);
     MT_lock_unset(&mal_profileLock, "querylogLock");
 }
 
@@ -155,7 +157,7 @@ QLOGcreate(str hnme, str tnme, int tt)
     return b;
 }
 
-#define cleanup(X)  if (X) { BBPdecref((X)->batCacheid, TRUE); 
(X)->batPersistence = TRANSIENT; } (X) = NULL;
+#define cleanup(X)  if (X) { (X)->batPersistence = TRANSIENT; 
BBPdecref((X)->batCacheid, TRUE); } (X) = NULL;
 
 static void
 _QLOGcleanup(void)
@@ -165,6 +167,7 @@ _QLOGcleanup(void)
        cleanup(QLOG_cat_defined);
        cleanup(QLOG_cat_query);
        cleanup(QLOG_cat_pipe);
+       cleanup(QLOG_cat_mal);
        cleanup(QLOG_cat_optimize);
        
        cleanup(QLOG_calls_id);
@@ -187,6 +190,7 @@ _initQlog(void)
        QLOG_cat_defined = QLOGcreate("cat","defined",TYPE_lng);
        QLOG_cat_query = QLOGcreate("cat","query",TYPE_str);
        QLOG_cat_pipe = QLOGcreate("cat","pipe",TYPE_str);
+       QLOG_cat_mal = QLOGcreate("cat","mal",TYPE_int);
        QLOG_cat_optimize = QLOGcreate("cat","optimize",TYPE_lng);
        
        QLOG_calls_id = QLOGcreate("calls","id",TYPE_oid);
@@ -254,6 +258,13 @@ QLOGissetFcn(int *ret)
        return MAL_SUCCEED;
 }
 
+/*static void 
+QLOGreclaim(BAT *b){
+    BATmode(b, TRANSIENT);
+       BBPreleaseref(b->batCacheid);
+}
+
+*/
 str
 QLOGreset(int *ret)
 {
@@ -261,31 +272,17 @@ QLOGreset(int *ret)
        initQlog();
     MT_lock_set(&mal_profileLock, "querylog.reset");
     /* drop all querylog tables */
-       BBPclear(QLOG_cat_id->batCacheid);
-       BBPclear(QLOG_cat_user->batCacheid);
-       BBPclear(QLOG_cat_defined->batCacheid);
-       BBPclear(QLOG_cat_query->batCacheid);
-       BBPclear(QLOG_cat_pipe->batCacheid);
-       BBPclear(QLOG_cat_optimize->batCacheid);
-       
-       BBPclear(QLOG_calls_id->batCacheid);
-       BBPclear(QLOG_calls_start->batCacheid);
-       BBPclear(QLOG_calls_stop->batCacheid);
-       BBPclear(QLOG_calls_arguments->batCacheid);
-       BBPclear(QLOG_calls_tuples->batCacheid);
-       BBPclear(QLOG_calls_exec->batCacheid);
-       BBPclear(QLOG_calls_result->batCacheid);
-       BBPclear(QLOG_calls_cpuload->batCacheid);
-       BBPclear(QLOG_calls_iowait->batCacheid);
-       BBPclear(QLOG_calls_space->batCacheid);
+
+       _QLOGcleanup();
     QLOG_init = 0;
+
+       TMsubcommit_list(commitlist, committop);
     MT_lock_unset(&mal_profileLock, "querylog.reset");
-       TMsubcommit_list(commitlist, committop);
        return MAL_SUCCEED;
 }
 
 str
-QLOGdefine(oid *ret, oid *idx, str *q, str *pipe, lng *optimize, str  *usr, 
lng *tick)
+QLOGdefine(oid *ret, oid *idx, str *q, str *pipe, lng *optimize, str  *usr, 
lng *tick, int *mal)
 {
        oid o;
        initQlog();
@@ -296,6 +293,7 @@ QLOGdefine(oid *ret, oid *idx, str *q, s
                QLOG_cat_id = BUNappend(QLOG_cat_id,idx,FALSE);
                QLOG_cat_query = BUNappend(QLOG_cat_query,*q,FALSE);
                QLOG_cat_pipe = BUNappend(QLOG_cat_pipe,*pipe,FALSE);
+               QLOG_cat_mal = BUNappend(QLOG_cat_mal,mal,FALSE);
                QLOG_cat_optimize = BUNappend(QLOG_cat_optimize,optimize,FALSE);
                QLOG_cat_user = BUNappend(QLOG_cat_user,*usr,FALSE);
                QLOG_cat_defined = BUNappend(QLOG_cat_defined,tick,FALSE);
diff --git a/monetdb5/modules/mal/querylog.h b/monetdb5/modules/mal/querylog.h
--- a/monetdb5/modules/mal/querylog.h
+++ b/monetdb5/modules/mal/querylog.h
@@ -40,7 +40,7 @@ qlog_export str QLOGdone(int *ret);
 qlog_export int QLOGisset(void);
 qlog_export str QLOGissetFcn(int *ret);
 qlog_export str QLOGreset(int *ret);
-qlog_export str QLOGdefine(oid *ret, oid *idx, str *q, str *pipe, lng 
*optimize, str  *usr, lng *tick);
+qlog_export str QLOGdefine(oid *ret, oid *idx, str *q, str *pipe, lng 
*optimize, str  *usr, lng *tick, int *mal);
 qlog_export str QLOGcall(int *ret, oid *idx, lng *tick1, lng *tick2, str *arg, 
wrd *tuples, lng *xtime, lng *rtime, int *cpu, int *iowait, lng *space);
 
 #endif /* _QLOG_H */
diff --git a/monetdb5/modules/mal/querylog.mal 
b/monetdb5/modules/mal/querylog.mal
--- a/monetdb5/modules/mal/querylog.mal
+++ b/monetdb5/modules/mal/querylog.mal
@@ -20,7 +20,7 @@ command reset()
 address QLOGreset
 comment "Clear the query log tables";
 
-command define(id:oid, q:str, pipe:str, optimize:lng, usr:str, 
tick:timestamp):oid
+command define(id:oid, q:str, pipe:str, optimize:lng, usr:str, tick:timestamp, 
size:int):oid
 address QLOGdefine
 comment "Add a new query call to the query log";
 
diff --git a/monetdb5/optimizer/opt_querylog.c 
b/monetdb5/optimizer/opt_querylog.c
--- a/monetdb5/optimizer/opt_querylog.c
+++ b/monetdb5/optimizer/opt_querylog.c
@@ -63,6 +63,7 @@ OPTquerylogImplementation(Client cntxt, 
        q = newStmt(mb, "mtime", "current_timestamp");
        start= getArg(q,0)= newVariable(mb,GDKstrdup("start"),TYPE_any);
        defineQuery = pushArgument(mb,defineQuery,start);
+       defineQuery = pushInt(mb,defineQuery,limit + 17 /* what we add here */);
        pushInstruction(mb, defineQuery);
 
        q = newStmt1(mb, sqlRef, "argRecord");
@@ -107,11 +108,13 @@ OPTquerylogImplementation(Client cntxt, 
                        q = newStmt(mb, "alarm", "usec");
                        rtime= getArg(q,0)= 
newVariable(mb,GDKstrdup("rtime"),TYPE_lng);
                        pushInstruction(mb,p);
-                       if (idcmp(getFunctionId(p),"resultSet")==0 ){
-                               q = newStmt(mb, "aggr", "count");
-                               getArg(q,0) = tuples;
-                               (void) pushArgument(mb,q, getArg(p,3));
-                       }
+                       continue;
+               }
+               if ( getModuleId(p) == sqlRef && 
idcmp(getFunctionId(p),"resultSet")==0 ){
+                       q = newStmt(mb, "aggr", "count");
+                       getArg(q,0) = tuples;
+                       (void) pushArgument(mb,q, getArg(p,3));
+                       pushInstruction(mb,p);
                        continue;
                }       
                if ( p->token== ENDsymbol || p->barrier == RETURNsymbol || 
p->barrier == YIELDsymbol){
diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -547,6 +547,7 @@ user:bat[:oid,:str],
 defined:bat[:oid,:timestamp],
 query:bat[:oid,:str],
 pipe:bat[:oid,:str],
+mal:bat[:oid,:int],
 optimize:bat[:oid,:lng]
 )
 address sql_querylog_catalog
@@ -6459,7 +6460,7 @@ sql_querylog_catalog(Client cntxt, MalBl
 
        (void)cntxt; (void)mb;
        QLOGcatalog(t);
-       for (i = 0; i < 6; i++) {
+       for (i = 0; i < 7; i++) {
                int id = t[i]->batCacheid;
 
                *(int *) getArgReference(stk, pci, i) = id;
diff --git a/sql/scripts/15_querylog.sql b/sql/scripts/15_querylog.sql
--- a/sql/scripts/15_querylog.sql
+++ b/sql/scripts/15_querylog.sql
@@ -28,6 +28,7 @@ returns table(
        defined timestamp,
        query string,
        pipe string,
+       mal int,                        -- size of MAL plan
        optimize bigint         -- time in usec
 )
 external name sql.querylog_catalog;
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to