Update of /cvsroot/monetdb/sql/src/backends/monet5
In directory 23jxhf1.ch3.sourceforge.com:/tmp/cvs-serv14693/src/backends/monet5

Modified Files:
        sql.mx sql_gencode.mx sql_optimizer.mx sql_scenario.mx 
Log Message:
Commit of the intermediate state of the new history scheme.
The 'patch' to SQL to produces 'times' results have been removed.
The hardwired code and expensive SQL call to update the history
table has been changed into a more open infrastructure that will
rely on an upcall to two SQL procedures that are in control
of filtering and archiving the performance information.

Platform dependent tests may require separate approval.

Stress testing the updates in a parallel (dataflow) setting
is one of the open issues, because some spurious bat leaks
where noticed by playing with the commands in the history.sql
file only.


U sql_scenario.mx
Index: sql_scenario.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql_scenario.mx,v
retrieving revision 1.323
retrieving revision 1.324
diff -u -d -r1.323 -r1.324
--- sql_scenario.mx     29 Oct 2008 14:59:58 -0000      1.323
+++ sql_scenario.mx     3 Nov 2008 15:32:04 -0000       1.324
@@ -274,6 +274,7 @@
        stmt *r = NULL;
        lng sec = 0;
        bit T = TRUE;
+       bit F = FALSE;
        ValRecord src;
 
        typename = "int";
@@ -294,6 +295,7 @@
        typename = "boolean";
        sql_find_subtype(&ctype, typename, 0, 0);
        SQLglobal("cache", &T);
+       SQLglobal("history", &F);
        return 0;
 }
 
@@ -852,12 +854,12 @@
 }
 
 void
-SQLsetTimer(Client c, int onoff)
+SQLsetTrace(Client c, int onoff)
 {
        InstrPtr q;
 
        c->itrace='c';
-       q = newStmt(c->curprg->def,"mdb","setTimer");
+       q = newStmt(c->curprg->def,"mdb","setTrace");
        pushBit(c->curprg->def,q,onoff);
 //     q = newStmt(c->curprg->def,"mdb","setThread");
 //     pushBit(c->curprg->def,q,onoff);
@@ -911,6 +913,8 @@
        if (!m->sa)
                m->sa = sa_create();
 
+       if (m->history)
+               be->mvc->Tparse = GDKusec();
        m->emode = m_normal;
        m->emod = mod_none;
        if (be->language == 'X') {
@@ -1013,10 +1017,10 @@
                }
                m->emode = m_inplace;
        } else if ((be->q = qc_match(m->qc, m->sym, m->args, m->argc, 
m->scanner.key ^ m->session->schema->base.id))) {
-               if (m->emod & mod_trace)
-                       SQLsetTimer(c, TRUE);
                if (m->emod & mod_debug)
                        SQLsetDebugger(c, m, TRUE); 
+               if (m->emod & mod_trace)
+                       SQLsetTrace(c, TRUE);
                if (m->emode != m_explain && !(m->emod & (mod_debug|mod_trace)))
                        m->emode = m_inplace;
        } else {
@@ -1035,7 +1039,7 @@
                if (m->emode == m_explain)
                        SQLshowPlan(c);
                if (m->emod & mod_trace)
-                       SQLsetTimer(c, TRUE);
+                       SQLsetTrace(c, TRUE);
                if (m->emod & mod_debug)
                        SQLsetDebugger(c, m, TRUE); 
                if ((m->emode != m_inplace && m->emode != m_prepare && 
!m->cache && m->emode != m_explain) || s->type == st_none){
@@ -1081,15 +1085,10 @@
 @-
 In the final phase we add any debugging control
 @c
-       /* turn off debugger */
+       if (m->emod & mod_trace)
+               SQLsetTrace(c, FALSE);
        if (m->emod & mod_debug) 
                SQLsetDebugger(c, m, FALSE);
-       if (m->emod & mod_trace)
-               SQLsetTimer(c, FALSE);
-       if (m->emod & (mod_profile | mod_record)) {
-               be->mvc->Tparse = GDKusec() - be->mvc->Tparse;
-                be->qry = sql_escape_str(QUERY(m->scanner) + m->scanner.as);
-       }
        scanner_query_processed(&(m->scanner));
 
 @-
@@ -1233,27 +1232,7 @@
        char *q = query;
        char buf[BUFSIZ], *stmt = buf;
 
-#ifdef HAVE_TIMES      
-       if (emod & mod_profile) {
-#if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
-               int tcks_per_sec = sysconf(_SC_CLK_TCK);
-#else
-               int tcks_per_sec = CLK_TCK;
-#endif
-               struct tms t1;
-
-               times(&t1);
-               stream_printf(
-                       c->scanner.ws,
-                       "#times real " LLFMT ", user " LLFMT ", system " LLFMT 
", %d\n",
-                       total, 
-                       (lng) (t1.tms_utime - be->mvc->times.tms_utime),
-                       (lng) (t1.tms_stime - be->mvc->times.tms_stime),
-                       tcks_per_sec);
-       }
-#endif 
-
-       if (!(emod & mod_record))
+       if (!c->history )
                return msg;
 
        /* ltrim query */
@@ -1285,7 +1264,6 @@
        MalStkPtr oldglb = c->glb;
        char oldlang= be->language;
        mvc *m = be->mvc;
-       lng T0=0;
        InstrPtr p;
        MalBlkPtr mb;
 
@@ -1310,8 +1288,6 @@
                sqlcleanup(be->mvc, 0);
                return MAL_SUCCEED;
        }
-       if( m->emod & mod_record)
-               T0 = GDKusec();
        if (m->emode == m_inplace) {
                msg = SQLexecutePrepared(c, be, be->q );
                goto cleanup_engine;
@@ -1388,14 +1364,6 @@
 unless auto_commit has been set.
 @c
        c->glb = oldglb;
-       if (m->emod & (mod_profile | mod_record)) {
-               lng T1 = GDKusec();
-               lng tot = T1 - be->mvc->Tstart; 
-
-               be->mvc->Texec = T1 - T0;
-               msg = backend_record(be, be->qry, be->mvc->Tparse, 
be->mvc->Toptimize, be->mvc->Texec, tot);
-               be->qry = NULL;
-       }
        return msg;
 }
 

U sql_gencode.mx
Index: sql_gencode.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql_gencode.mx,v
retrieving revision 1.290
retrieving revision 1.291
diff -u -d -r1.290 -r1.291
--- sql_gencode.mx      28 Oct 2008 20:05:04 -0000      1.290
+++ sql_gencode.mx      3 Nov 2008 15:32:04 -0000       1.291
@@ -56,6 +56,7 @@
 #include "sql_config.h"
 #include "sql_gencode.h"
 #include "sql_optimizer.h"
+#include "sql_scenario.h"
 #include "sql_scope.h"
 #include "mal_namespace.h"
 #include "opt_prelude.h"
@@ -415,8 +416,7 @@
 }
 
 @-
-The big code generation switch. The sections are aligned to the
-Monet version4 code generation block for ease of comparison.
+The big code generation switch. 
 @c
 #define SMALLBUFSIZ 64
 static int 
@@ -1892,11 +1892,47 @@
        }
        return s->nr;
 }
[EMAIL PROTECTED]
+The kernel uses two calls to procedures defined in SQL.
+They have to be initialized, which is currently hacked
+by using the SQLstatment.
[EMAIL PROTECTED]
+static void
+initHistory(backend *be){
+       static int initdone=0;
+
+       if (initdone || be->mvc->history == 0) return;
+       if (findSymbol(userRef,"keepcall")== NULL){
+               be->mvc->history= 0;
+               showException(SQL,"sql","sql/history.sql script should be ran 
first.\n");
+       } else
+               initdone= 1;
+}
 
 static void backend_dumpstmt(backend *be, MalBlkPtr mb, stmt *s)
 {
        mvc *c = be->mvc;
        InstrPtr q;
+       char *t;
+
+       initHistory(be);
+       if ( c->history ){
+               c->history = (int) OIDnew((oid) 1);
+        q = newStmt(mb,sqlRef,"queryId");
+        q = pushInt(mb, q, c->history);        /* query identifier */
+               
+               if (be->qry==NULL)
+                       be->qry = sql_escape_str(QUERY(c->scanner) + 
c->scanner.as);
+               t= be->qry;
+               while( t && isspace((int) *t) ) t++;
+
+        q = newStmt(mb,sqlRef,"keepquery");
+               q= pushInt(mb,q,c->history);
+               q= pushStr(mb,q,t);
+               q= pushLng(mb,q,GDKusec() - be->mvc->Tparse);
+               q= pushLng(mb,q, GDKusec());
+               c->Tparse = 0;
+       }
 
        (void)_dumpstmt(be, mb, s);
        if (c->cache && (c->type == Q_SCHEMA || c->type == Q_TRANS)) {
@@ -1909,6 +1945,7 @@
                getArg(q,0) = getArg(getInstrPtr(mb,0),0);
                q->barrier = RETURNsymbol;
        }
+       
        pushEndInstruction(mb);
 }
 

U sql_optimizer.mx
Index: sql_optimizer.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql_optimizer.mx,v
retrieving revision 1.196
retrieving revision 1.197
diff -u -d -r1.196 -r1.197
--- sql_optimizer.mx    10 Oct 2008 08:54:35 -0000      1.196
+++ sql_optimizer.mx    3 Nov 2008 15:32:04 -0000       1.197
@@ -460,8 +460,10 @@
        "garbageCollector,"
        "dataflow,"
        //"octopus,"
+       "history,"
        "multiplex";
 static str minimalPlan=
+       "history,"
        "multiplex";
        
 

U sql.mx
Index: sql.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet5/sql.mx,v
retrieving revision 1.292
retrieving revision 1.293
diff -u -d -r1.292 -r1.293
--- sql.mx      2 Nov 2008 10:42:30 -0000       1.292
+++ sql.mx      3 Nov 2008 15:32:03 -0000       1.293
@@ -237,6 +237,41 @@
 command not_uniques( b:bat[:oid,:wrd]) :bat[:oid,:oid] 
 address not_unique_oids ;
 
+function times(elaps:int,inblock:lng, oublock:lng):void;
+       io.printf("#times %d ms",elaps);
+       io.printf(" %d reads",inblock);
+       io.printf(" %d writes\n",oublock);
+end times;
+
+factory times();
+       elaps:= alarm.time();
+       inblocks := bbp.getDiskReads();
+       oublocks := bbp.getDiskWrites();
+barrier goon:=true;
+       u1:= alarm.time();
+       i1 := bbp.getDiskReads();
+       o1 := bbp.getDiskWrites();
+       elaps:= u1-elaps;
+       inblocks := i1-inblocks;
+       oublocks := o1-oublocks;
+       io.printf("#times %d ms",elaps);
+       io.printf(" %d reads",inblocks);
+       io.printf(" %d writes\n",oublocks);
+       elaps := u1;
+       inblocks  := i1;
+       oublocks  := o1;
+       yield times;
+       redo goon:=true;
+exit goon;
+end times;
+
+pattern argRecord():str
+address SQLargRecord
+comment "Glue together the calling sequence";
+pattern argRecord(a:any...):str
+address SQLargRecord
+comment "Glue together the calling sequence";
+
 function sql_environment():bat[:str,:bat];
        b := bat.new(:str,:bat,2);
        e := inspect.getEnvironment();
@@ -763,6 +798,7 @@
 sql5_export str zero_or_one(ptr ret, int *bid);
 sql5_export str not_unique(bit *ret, int *bid);
 sql5_export str not_unique_oids(bat *ret, bat *bid);
+sql5_export str SQLargRecord(Client cntxt, MalBlkPtr mb, MalStkPtr stk, 
InstrPtr pci);
 sql5_export str month_interval_str( int *ret, str *s, int *ek, int *sk );
 sql5_export str second_interval_str( lng *res, str *s, int *ek, int *sk );
 sql5_export str dump_cache(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci);
@@ -915,6 +951,7 @@
 #include "sql_result.h"
 #include "sql_gencode.h"
 #include <sql_storage.h>
+#include <sql_scenario.h>
 #include <store_sequence.h>
 #include <sql_datetime.h>
 #include <rel_optimizer.h>
@@ -3626,3 +3663,13 @@
 @c
 @:rnk(,(void)c;nrank++,1)@
 @:rnk(dense_,nrank+=(c?1:0),2)@
+
+str SQLargRecord(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci){
+       str *ret;
+
+       (void) cntxt;
+       ret= (str *) getArgReference(stk,pci,0);
+       *ret = call2str(mb,stk,0,LIST_MAL_VALUE);
+       return MAL_SUCCEED;
+}
+


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to