Update of /cvsroot/monetdb/sql/src/backends/monet4
In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv23009/src/backends/monet4

Modified Files:
        sql_gencode.mx sql_result.mx sql_server.mx 
Log Message:
Many fixes

changed how we handle selections over multiple columns of a single table
(should solve the preformance problem reported by Venks)

added a way to bulk request sequence numbers. When loading (copying) data
into tables which have a auto_increment (or alike) column lots of time
was spend in the many calls to get all the sequence numbers (observed a
performance in crease of about 10x when loading pieces of 100K rows)

added support for TINYINT (we map this too 'bte')

improved mapping functions onto the same signature too improve cached 
function reuse



Index: sql_result.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet4/sql_result.mx,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- sql_result.mx       22 Jun 2007 07:08:56 -0000      1.59
+++ sql_result.mx       29 Jun 2007 11:28:42 -0000      1.60
@@ -104,8 +104,10 @@
 int
 dec_tostr(void *extra, char **Buf, int *len, int type, ptr a)
 {
-       /* support dec map to sht, int and lng */
-       if (type == TYPE_sht) {
+       /* support dec map to bte, sht, int and lng */
+       if (type == TYPE_bte) {
+               @:dec_tostr(bte)@
+       } else if (type == TYPE_sht) {
                @:dec_tostr(sht)@
        } else if (type == TYPE_int) {
                @:dec_tostr(int)@
@@ -282,6 +284,7 @@
        return ret;
 }
 @c
+@:bat_max_xlength(bte)@
 @:bat_max_xlength(sht)@
 @:bat_max_xlength(int)@
 @:bat_max_xlength(lng)@
@@ -346,10 +349,12 @@
 ptr *
 dec_frstr(void *extra, int type, char *s, char *e, char quote)
 {
-       /* support dec map to sht, int and lng */
+       /* support dec map to bte, sht, int and lng */
        (void) e;
        (void) quote;
-       if (type == TYPE_sht) {
+       if (type == TYPE_bte) {
+               @:dec_frstr(bte)@
+       } else if (type == TYPE_sht) {
                @:dec_frstr(sht)@
        } else if (type == TYPE_int) {
                @:dec_frstr(int)@
@@ -556,6 +561,7 @@
        return stream_write(s, b, 50- (b-buf),1)==1;
 }
 @c
+@:mvc_send(bte)@
 @:mvc_send(sht)@
 @:mvc_send(int)@
 @:mvc_send(lng)@
@@ -624,6 +630,9 @@
                ok = (stream_write(s, "NULL", sizeof("NULL") - 1, 1) == 1);
        } else {
                switch(mtype) {
+               case TYPE_bte:
+                       ok = mvc_send_bte(s, *(bte*)p);
+                       break;
                case TYPE_sht:
                        ok = mvc_send_sht(s, *(sht*)p);
                        break;
@@ -777,7 +786,9 @@
                if (bid) {
                        BAT *b = BATdescriptor(bid);
 
-                       if (mtype == TYPE_sht) {
+                       if (mtype == TYPE_bte) {
+                               count = bat_max_btelength(b);
+                       } else if (mtype == TYPE_sht) {
                                count = bat_max_shtlength(b);
                        } else if (mtype == TYPE_int) {
                                count = bat_max_intlength(b);
@@ -788,7 +799,9 @@
                } else {
                        if (p) {
                                lng val = 0;
-                               if (mtype == TYPE_sht) {
+                               if (mtype == TYPE_bte) {
+                                       val = *((bte *)p);
+                               } else if (mtype == TYPE_sht) {
                                        val = *((sht *)p);
                                } else if (mtype == TYPE_int) {
                                        val = *((int *)p);

Index: sql_server.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet4/sql_server.mx,v
retrieving revision 1.166
retrieving revision 1.167
diff -u -d -r1.166 -r1.167
--- sql_server.mx       23 May 2007 22:05:57 -0000      1.166
+++ sql_server.mx       29 Jun 2007 11:28:43 -0000      1.167
@@ -77,6 +77,9 @@
        .COMMAND mvc_next_value( mvc m, str sname, str seqname ) : lng = 
mvc_next_value;
                "return the next value of the sequence"
 
+       .COMMAND [mvc_next_value]( mvc m, BAT[oid,str] snames, str seqname ) : 
bat[oid,lng] = mvc_bat_next_value;
+               "return the next value of the sequence for the bat of schema 
names"
+
        .COMMAND mvc_get_value( mvc m, str sname, str sequence ) : lng = 
mvc_get_value;
                "return the current value of the sequence"
 
@@ -147,9 +150,11 @@
 
 @= mel_round
        .COMMAND dec_round( @1 v, @1 r ) : @1 = @1_dec_round_wrap; "round off 
the value v to nearests multiple of r"
-       .COMMAND round( @1 v, int d, int s, sht r ) : @1 = @1_round_wrap; 
"round off the decimal v(d,s) to r digits behind the dot (if r < 0, before the 
dot)"
+
+       .COMMAND round( @1 v, int d, int s, bte r ) : @1 = @1_round_wrap; 
"round off the decimal v(d,s) to r digits behind the dot (if r < 0, before the 
dot)"
 @m
 
+@:mel_round(bte)@
 @:mel_round(sht)@
 @:mel_round(int)@
 @:mel_round(lng)@
@@ -164,6 +169,7 @@
  .COMMAND @1( str v, int digits ) : @1 = [EMAIL PROTECTED]; "cast to @1 and 
check for overflow"
  .COMMAND @1( str v, int digits, int scale ) : @1 = [EMAIL PROTECTED]; "cast 
to dec(@1) and check for overflow"
 @m
+@:mel_cast(bte)@
 @:mel_cast(sht)@
 @:mel_cast(int)@
 @:mel_cast(lng)@
@@ -184,9 +190,11 @@
  .COMMAND @1( @2 v, int d2, int s2 ) : @1 = @[EMAIL PROTECTED]; "cast number 
to decimale(@1) and check for overflow"
 @m
 
+@:mel_cast_2dec(bte,flt)@
 @:mel_cast_2dec(sht,flt)@
 @:mel_cast_2dec(int,flt)@
 @:mel_cast_2dec(lng,flt)@
+@:mel_cast_2dec(bte,dbl)@
 @:mel_cast_2dec(sht,dbl)@
 @:mel_cast_2dec(int,dbl)@
 @:mel_cast_2dec(lng,dbl)@
@@ -201,18 +209,27 @@
 @:mel_cast_dec2(@1,@2)@
 @m
 
+@:mel_cast2(bte,bte)@
+@:mel_cast2(bte,sht)@
+@:mel_cast2(bte,int)@
+@:mel_cast2(bte,lng)@
+@:mel_cast2(sht,bte)@
 @:mel_cast2(sht,sht)@
 @:mel_cast2(sht,int)@
 @:mel_cast2(sht,lng)@
+@:mel_cast2(int,bte)@
 @:mel_cast2(int,sht)@
 @:mel_cast2(int,int)@
 @:mel_cast2(int,lng)@
+@:mel_cast2(lng,bte)@
 @:mel_cast2(lng,sht)@
 @:mel_cast2(lng,int)@
 @:mel_cast2(lng,lng)@
+@:mel_cast2(flt,bte)@
 @:mel_cast2(flt,sht)@
 @:mel_cast2(flt,int)@
 @:mel_cast2(flt,lng)@
+@:mel_cast2(dbl,bte)@
 @:mel_cast2(dbl,sht)@
 @:mel_cast2(dbl,int)@
 @:mel_cast2(dbl,lng)@
@@ -224,6 +241,7 @@
 @m
 
 @:mel_interval(str)@
+@:mel_interval(bte)@
 @:mel_interval(sht)@
 @:mel_interval(int)@
 @:mel_interval(lng)@
@@ -431,6 +449,61 @@
        }
        return GDK_FAIL;
 }
+
+int
+mvc_bat_next_value(BAT **res, mvc *C, BAT *snames, str seqname)
+{
+       mvc *c = *(mvc**)C;
+       int xx;
+       BAT *r;
+       BUN p,q;
+       sql_schema *s = NULL;
+       sql_sequence *seq = NULL;
+       seqbulk *sb = NULL;
+
+       r = BATnew(snames->htype, TYPE_lng, BATcount(snames));
+       if (!r) {
+               GDKerror("Cannot create bat");
+               return GDK_FAIL;
+       }
+
+       BATseqbase(r, snames->hseqbase);
+       if (!BATcount(snames)) {
+               *res = r;
+               return GDK_SUCCEED;
+       }
+
+       BATloopFast(snames,p,q,xx){
+               str sname = BUNtail(snames,BUNfirst(snames));
+               lng l;
+
+               if (!s || strcmp(s->base.name, sname) != 0) {
+                       if (sb)
+                               seqbulk_destroy(sb);
+                       s = mvc_bind_schema(c, sname);
+                       seq = NULL;
+                       if (!s || 
+                           (seq = find_sql_sequence(s, seqname)) == NULL ||
+                           !(sb = seqbulk_create(seq, BATcount(snames))) ) {
+                               BBPunfix(r->batCacheid);
+                               GDKerror("sql.next_value error");
+                               return GDK_FAIL;
+                       }
+               }
+               if (!seqbulk_next_value(sb, &l)) {
+                       BBPunfix(r->batCacheid);
+                       seqbulk_destroy(sb);
+                       GDKerror("sql.next_value error");
+                       return GDK_FAIL;
+               }
+               BUNins(r, BUNhead(snames,p), &l, FALSE);
+       }
+       if (sb) 
+               seqbulk_destroy(sb);
+       *res = r;
+       return GDK_SUCCEED;
+}
+
 int
 mvc_get_value(lng *res, mvc *C, str sname, str seqname)
 {
@@ -741,7 +814,7 @@
        return GDK_SUCCEED;
 }
 
-int @1_round_wrap( @1 *res, @1 *v, int *d, int *s, sht *r )
+int @1_round_wrap( @1 *res, @1 *v, int *d, int *s, bte *r )
 {
        /* shortcut nil */
        if (*v == @1_nil) {
@@ -814,6 +887,7 @@
        return [EMAIL PROTECTED]( res, v, len, &zero );
 }
 @c
+@:round(bte)@
 @:round(sht)@
 @:round(int)@
 @:round(lng)@
@@ -857,6 +931,7 @@
        return GDK_SUCCEED;
 }
 @c
+@:cast(bte)@
 @:cast(sht)@
 @:cast(int)@
 @:cast(lng)@
@@ -998,9 +1073,13 @@
        return GDK_SUCCEED;
 }
 @c
+@:numcastup(bte,bte)@
+@:numcastup(sht,bte)@
 @:numcastup(sht,sht)@
+@:numcastup(int,bte)@
 @:numcastup(int,sht)@
 @:numcastup(int,int)@
+@:numcastup(lng,bte)@
 @:numcastup(lng,sht)@
 @:numcastup(lng,int)@
 @:numcastup(lng,lng)@
@@ -1042,9 +1121,11 @@
        return GDK_SUCCEED;
 }
 @c
+@:fnumcastdown(bte,flt)@
 @:fnumcastdown(sht,flt)@
 @:fnumcastdown(int,flt)@
 @:fnumcastdown(lng,flt)@
+@:fnumcastdown(bte,dbl)@
 @:fnumcastdown(sht,dbl)@
 @:fnumcastdown(int,dbl)@
 @:fnumcastdown(lng,dbl)@
@@ -1112,9 +1193,11 @@
        return GDK_SUCCEED;
 }
 @c
+@:fnumcastup(flt,bte)@
 @:fnumcastup(flt,sht)@
 @:fnumcastup(flt,int)@
 @:fnumcastup(flt,lng)@
+@:fnumcastup(dbl,bte)@
 @:fnumcastup(dbl,sht)@
 @:fnumcastup(dbl,int)@
 @:fnumcastup(dbl,lng)@
@@ -1189,6 +1272,9 @@
        }
 }
 @c
+@:numcastdown(bte,sht)@
+@:numcastdown(bte,int)@
+@:numcastdown(bte,lng)@
 @:numcastdown(sht,int)@
 @:numcastdown(sht,lng)@
 @:numcastdown(int,lng)@
@@ -1245,6 +1331,7 @@
 }
 @c
 
+@:c_interval(bte)@
 @:c_interval(sht)@
 @:c_interval(int)@
 @:c_interval(lng)@
@@ -1375,6 +1462,11 @@
 #      return b1;
 }
 
+proc sql_semijoin (bat[oid,any::1] b1, bat[oid,any::2] b2) : bat[oid,any::1] {
+       var x := b2.mirror();
+       return x.join(b1);
+}
+
 proc log2(int i) : int {
   var n := 0;
   while(i > 1)  {
@@ -1389,6 +1481,9 @@
 proc next_value( str sname, str v ) : lng {
        return mvc_next_value(myc, sname, v);
 }
+proc [next_value]( bat[oid,str] snames, str v ) : lng {
+       return [mvc_next_value](myc, snames, v);
+}
 proc get_value( str sname, str v ) : lng {
        return mvc_get_value(myc, sname, v);
 }

Index: sql_gencode.mx
===================================================================
RCS file: /cvsroot/monetdb/sql/src/backends/monet4/sql_gencode.mx,v
retrieving revision 1.152
retrieving revision 1.153
diff -u -d -r1.152 -r1.153
--- sql_gencode.mx      26 Apr 2007 14:35:06 -0000      1.152
+++ sql_gencode.mx      29 Jun 2007 11:28:42 -0000      1.153
@@ -629,7 +629,10 @@
                        break;
                }
                case st_semijoin:
-                       dump_2(sql, s, "semijoin", nr);
+                       if (s->op1.stval->h && s->op1.stval->h == 
s->op2.stval->h)
+                               dump_2(sql, s, "sql_semijoin", nr);
+                       else
+                               dump_2(sql, s, "semijoin", nr);
                        break;
                case st_diff:
                        dump_2(sql, s, "kdiff", nr);
@@ -950,7 +953,7 @@
                        int l = backend_dumpstmt_(s->op1.stval, nr, sql);
                        size_t buflen = strlen(s->op4.aggrval->aggr->imp) + 
SMALLBUFSIZ;
                        char *aggrfunc = s->op4.aggrval->aggr->imp;
-                       sql_subtype *tpe = tail_type(s->op1.stval);
+                       sql_subtype *tpe = tail_type(s);
 
                        buf = NEW_ARRAY(char, buflen + 1);
 
@@ -1548,26 +1551,38 @@
 }
 
 static YYSTREE
-monet4_interpret(Cntxt procstk, mvc *c, char *name, int *err)
+monet4_interpret(Cntxt procstk, mvc *c, cq *q, int *err)
 {
        YYSTREE callnode;
        YYSTREE argtree;
        ValRecord v;
 
        v.vtype = TYPE_void;
-       callnode = milnode(TOK_FUNCTION, TYPE_str, _strdup(name));
+       callnode = milnode(TOK_FUNCTION, TYPE_str, _strdup(q->name));
        argtree = Myynode(0, 0);
        if (c->argc) {
                int i;
                for (i = 0; i < c->argc; i++){
                        atom *a = c->args[i];
                        YYSTREE arg;
+                       sql_subtype *pt = q->params+i;
 
+                       /*
                        if (atom_null(a)) {
                                if (a->data.vtype == TYPE_str && 
a->data.val.sval == NULL) {
                                        a->data.val.sval = GDKstrdup(str_nil);
                                }
                        }
+                       */
+                       
+                       if (!atom_cast(a, pt)) {
+                               char buf[BUFSIZ];
+
+                               snprintf(buf, BUFSIZ, "wrong argument for 
function call (expected %s instead of %s)\n", pt->type->sqlname, 
atom_type(a)->type->sqlname);
+                               sql_error(c, 003, buf);
+                               *err = -1;
+                               return NULL;
+                       }
                        arg = milnode2(&a->data);
                        argtree = Myyexpand(argtree, arg);
                }
@@ -1589,7 +1604,7 @@
        YYSTREE callnode;
 
        be->mvc->type = q->type;
-       callnode = monet4_interpret(procstk, c, q->name, &err);
+       callnode = monet4_interpret(procstk, c, q, &err);
 
        if (!err) {
                q->code = (backend_code) callnode;
@@ -1622,7 +1637,16 @@
 
                for (i = 1; i <= c->argc; i++) {
                        atom *a = c->args[i-1];
+                       sql_subtype *pt = q->params+i-1;
+
+                       if (!atom_cast(a, pt)) {
+                               char buf[BUFSIZ];
 
+                               snprintf(buf, BUFSIZ, "wrong argument for fast 
call (expected %s instead of %s)\n", pt->type->sqlname, 
atom_type(a)->type->sqlname);
+                               sql_error(c, 003, buf);
+                               return -1;
+                       }
+                       /*
                        if (atom_null(a)) {
                                int t = argv[i].vtype;
 
@@ -1636,7 +1660,6 @@
                                                a->data.val.pval = NULL;
                                        }
                                }
-                       /* cast DEC into FLT */
                        } else if (a->data.vtype != argv[i].vtype && 
argv[i].vtype == TYPE_dbl) { 
                                a->data.vtype = argv[i].vtype;
                                a->data.val.dval = a->d;
@@ -1644,6 +1667,8 @@
                                a->data.vtype = argv[i].vtype;
                                a->data.val.fval = a->d;
                        }
+                       */
+                       /* cast DEC into FLT */
                        argv[i] = a->data;
                }
        }


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Monetdb-sql-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/monetdb-sql-checkins

Reply via email to