Changeset: df52ea969881 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=df52ea969881
Modified Files:
        clients/Tests/exports.stable.out
        gdk/gdk_batop.c
        gdk/gdk_join.c
        gdk/gdk_logger.c
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/kernel/algebra.h
        monetdb5/modules/kernel/algebra.mal
        monetdb5/modules/mal/pqueue.c
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_optimizer.c
        sql/benchmarks/tpch/Tests/02-explain.stable.out
        sql/benchmarks/tpch/Tests/03-explain.stable.out
        sql/benchmarks/tpch/Tests/10-explain.stable.out
        sql/benchmarks/tpch/Tests/18-explain.stable.out
        sql/benchmarks/tpch/Tests/21-explain.stable.out
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_storage.h
        
sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
        sql/test/leaks/Tests/temp2.stable.out
Branch: default
Log Message:

map mal leftfetchjoin onto BATproject, ie now leftfetchjoin's interface is 
void:oid, void:any -> void:any
Also BATslice on oid-dense heads now always returns a void head result.


diffs (truncated from 1172 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
@@ -769,7 +769,6 @@ str ALGkdiff(int *result, int *lid, int 
 str ALGkunion(int *result, int *lid, int *rid);
 str ALGkunique(int *result, int *bid);
 str ALGleftfetchjoin(int *result, int *lid, int *rid);
-str ALGleftfetchjoinestimate(int *result, int *lid, int *rid, lng *estimate);
 str ALGleftjoin(int *result, int *lid, int *rid);
 str ALGleftjoinestimate(int *result, int *lid, int *rid, lng *estimate);
 str ALGlike(int *ret, int *bid, str *k);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -790,7 +790,10 @@ BATslice(BAT *b, BUN l, BUN h)
        if (BAThrestricted(b) == BAT_READ && BATtrestricted(b) == BAT_READ) {
                BUN cnt = h - l;
 
-               bn = VIEWcreate_(b, b, TRUE);
+               if (BAThdense(b))
+                       bn = BATmirror(VIEWhead(BATmirror(b)));
+               else
+                       bn = VIEWcreate_(b, b, TRUE);
                bn->batFirst = bn->batDeleted = bn->batInserted = 0;
                bn->H->heap.base = (bn->htype) ? BUNhloc(bi, l) : NULL;
                bn->T->heap.base = (bn->ttype) ? BUNtloc(bi, l) : NULL;
@@ -805,11 +808,15 @@ BATslice(BAT *b, BUN l, BUN h)
                BUN p = (BUN) l;
                BUN q = (BUN) h;
 
-               bn = BATnew(b->htype, b->ttype, h - l);
+               bn = BATnew((BAThdense(b)?TYPE_void:b->htype), b->ttype, h - l);
                if (bn == NULL) {
                        return bn;
                }
-               if (b->htype != b->ttype || b->htype != TYPE_void) {
+               if (BAThdense(b) && b->ttype) {
+                       for (; p < q; p++) {
+                               bunfastins(bn, NULL, BUNtail(bi, p));
+                       }
+               } else if (b->htype != b->ttype || b->htype != TYPE_void) {
                        for (; p < q; p++) {
                                bunfastins(bn, BUNhead(bi, p), BUNtail(bi, p));
                        }
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -1851,6 +1851,7 @@ BATproject(BAT *l, BAT *r)
                          BATgetId(l), BATgetId(r), BATgetId(bn), BATcount(bn),
                          bn->tsorted ? "-sorted" : "",
                          bn->trevsorted ? "-revsorted" : "");
+               assert(bn->htype == TYPE_void);
                return bn;
        }
        if (l->ttype == TYPE_void || BATcount(l) == 0) {
@@ -1923,6 +1924,8 @@ BATproject(BAT *l, BAT *r)
        assert(n == BATcount(l));
        BATsetcount(bn, n);
        BATseqbase(bn, l->hseqbase);
+       if (!BATtdense(r))
+               BATseqbase(BATmirror(bn), oid_nil);
        ALGODEBUG fprintf(stderr, "#BATproject(l=%s,r=%s)=%s#"BUNFMT"%s%s\n",
                  BATgetId(l), BATgetId(r), BATgetId(bn), BATcount(bn),
                  bn->tsorted ? "-sorted" : "",
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -1777,6 +1777,7 @@ log_bat(logger *lg, BAT *b, char *name)
                        return LOG_ERR;
 
                if (b->htype == TYPE_void &&
+                   b->ttype > TYPE_void &&
                    b->ttype < TYPE_str &&
                    !isVIEW(b)) {
                        const void *t = BUNtail(bi, b->batInserted);
diff --git a/monetdb5/modules/kernel/algebra.c 
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -1513,15 +1513,9 @@ ALGleftjoin(bat *result, bat *lid, bat *
 }
 
 str
-ALGleftfetchjoinestimate(bat *result, bat *lid, bat *rid, lng *estimate)
-{
-       return ALGbinaryestimate(result, lid, rid, estimate, BATleftfetchjoin, 
"algebra.leftfetchjoin");
-}
-
-str
 ALGleftfetchjoin(bat *result, bat *lid, bat *rid)
 {
-       return ALGbinaryestimate(result, lid, rid, NULL, BATleftfetchjoin, 
"algebra.leftfetchjoin");
+       return ALGbinary(result, lid, rid, BATproject, "algebra.leftfetchjoin");
 }
 
 str
diff --git a/monetdb5/modules/kernel/algebra.h 
b/monetdb5/modules/kernel/algebra.h
--- a/monetdb5/modules/kernel/algebra.h
+++ b/monetdb5/modules/kernel/algebra.h
@@ -95,7 +95,6 @@ algebra_export str ALGjoinestimate(int *
 algebra_export str ALGjoin(int *result, int* lid, int *rid);
 algebra_export str ALGleftjoinestimate(int *result, int *lid, int *rid, lng 
*estimate);
 algebra_export str ALGleftjoin(int *result, int* lid, int *rid);
-algebra_export str ALGleftfetchjoinestimate(int *result, int *lid, int *rid, 
lng *estimate);
 algebra_export str ALGleftfetchjoin(int *result, int* lid, int *rid);
 algebra_export str ALGouterjoinestimate(int *result, int *lid, int *rid, lng 
*estimate);
 algebra_export str ALGouterjoin(int *result, int* lid, int *rid);
diff --git a/monetdb5/modules/kernel/algebra.mal 
b/monetdb5/modules/kernel/algebra.mal
--- a/monetdb5/modules/kernel/algebra.mal
+++ b/monetdb5/modules/kernel/algebra.mal
@@ -577,8 +577,8 @@ command join( left:bat[:any_1,:any_2], r
                estimate:lng) :bat[:any_1,:any_3]
 address ALGjoinestimate;
 
-command leftfetchjoin ( left:bat[:any_1,:oid], right:bat[:oid,:any_3] )
-               :bat[:any_1,:any_3]
+command leftfetchjoin ( left:bat[:oid,:oid], right:bat[:oid,:any_3] )
+               :bat[:oid,:any_3]
 address ALGleftfetchjoin
 comment "Hook directly into the left fetch join implementation.";
 
diff --git a/monetdb5/modules/mal/pqueue.c b/monetdb5/modules/mal/pqueue.c
--- a/monetdb5/modules/mal/pqueue.c
+++ b/monetdb5/modules/mal/pqueue.c
@@ -1148,24 +1148,34 @@ PQinit(int *ret, int *bid, wrd *maxsize)
        {                                                                       
                                                                \
                BUN n, i,j, cnt;                                                
                                                \
                BAT *a, *b,*bn = NULL;                                          
                                        \
+               oid id = 0;                                     \
                if ((a=BATdescriptor(*aid)) == NULL || (b=BATdescriptor(*bid)) 
== NULL) \
                        throw(MAL, "pqueue.topN", RUNTIME_OBJECT_MISSING);      
                \
-                                                                               
                                                                \
-               cnt = n = BATcount(a);                                          
                                        \
+               if (a->ttype == 0) {                    \
+                       assert(0);                      \
+                       *ret= a->batCacheid;            \
+                       BBPkeepref(*ret);               \
+                       BBPreleaseref(b->batCacheid);   \
+               }                                       \
+               id = a->hseqbase;                       \
+               cnt = n = BATcount(a);                  \
                if (*N != wrd_nil && *N >= 0 && *N <= (wrd) BUN_MAX && (BUN) *N 
< n) \
                        n = (BUN) *N;                                           
                                                \
                bn = BATnew(TYPE_oid, TYPE_oid, n);                             
                                \
-               for(i=0; i<n; ) {                                               
                                                \
+               for(i=0; i<n; id++) {                                           
                                                \
                        oid ov = * (oid *) Tloc(a, i);                          
                                \
                        for (j = i; j < cnt && * (oid *) Tloc(a, j) == ov; j++) 
        \
                                ;                                               
                                                                \
                        if (j == i+1) {                                         
                                                \
-                               BUNins(bn, Hloc(a,i), &ov, FALSE);              
                                \
+                               if (a->htype == 0)                      \
+                                       BUNins(bn, &id, &ov, FALSE);    \
+                               else                                    \
+                                       BUNins(bn, Hloc(a,i), &ov, FALSE);      
                                        \
                        } else {                                                
                                                        \
                                BAT *s = BATslice(b, i, j), *sbn = NULL;        
                        \
                                wrd nn = n-i;                                   
                                                \
                                                                                
                                                                \
-                               if ((b->htype == TYPE_void ? 
pqueue_topn_void##TYPE##K(&sbn,s,&nn) : pqueue_topn_##TYPE##K(&sbn,s,&nn)) == 
GDK_SUCCEED && sbn) { \
+                               if ((s->htype == TYPE_void ? 
pqueue_topn_void##TYPE##K(&sbn,s,&nn) : pqueue_topn_##TYPE##K(&sbn,s,&nn)) == 
GDK_SUCCEED && sbn) { \
                                        BATins(bn, sbn, FALSE);                 
                                        \
                                        BBPunfix(sbn->batCacheid);              
                                        \
                                        BBPunfix(s->batCacheid);                
                                        \
@@ -1190,24 +1200,35 @@ PQinit(int *ret, int *bid, wrd *maxsize)
        {                                                                       
                                                                \
                BUN n, i,j, cnt;                                                
                                                \
                BAT *a, *b,*bn = NULL;                                          
                                        \
+               oid id = 0;                                     \
                                                                                
                                                                \
                if ((a=BATdescriptor(*aid)) == NULL || (b=BATdescriptor(*bid)) 
== NULL) \
                        throw(MAL, "pqueue.topN", RUNTIME_OBJECT_MISSING);      
                \
-               cnt = n = BATcount(a);                                          
                                        \
+               if (a->ttype == 0) {                    \
+                       assert(0);                      \
+                       *ret= a->batCacheid;            \
+                       BBPkeepref(*ret);               \
+                       BBPreleaseref(b->batCacheid);   \
+               }                                       \
+               id = a->hseqbase;                       \
+               cnt = n = BATcount(a);                  \
                if (*N != wrd_nil && *N >= 0 && *N <= (wrd) BUN_MAX && (BUN) *N 
< n) \
                        n = (BUN) *N;                                           
                                                \
                bn = BATnew(TYPE_oid, TYPE_oid, n);                             
                                \
-               for(i=0; i<n; ) {                                               
                                                \
+               for(i=0; i<n; id++) {                                           
                                                \
                        oid ov = * (oid *) Tloc(a, i);                          
                                \
                        for (j = i; j < cnt && * (oid *) Tloc(a, j) == ov; j++) 
        \
                                ;                                               
                                                                \
                        if (j == i+1) {                                         
                                                \
-                               BUNins(bn, Hloc(a,i), &ov, FALSE);              
                                \
+                               if (a->htype == 0)                              
\
+                                       BUNins(bn, &id, &ov, FALSE);            
\
+                               else                                            
\
+                                       BUNins(bn, Hloc(a,i), &ov, FALSE);      
\
                        } else {                                                
                                                        \
                                BAT *s = BATslice(b, i, j), *sbn = NULL;        
                        \
                                wrd nn = n-i;                                   
                                                \
                                                                                
                                                                \
-                               if ((b->htype == TYPE_void ? 
pqueue_utopn_void##TYPE##K(&sbn,s,&nn) : pqueue_utopn_##TYPE##K(&sbn,s,&nn)) == 
GDK_SUCCEED && sbn) { \
+                               if ((s->htype == TYPE_void ? 
pqueue_utopn_void##TYPE##K(&sbn,s,&nn) : pqueue_utopn_##TYPE##K(&sbn,s,&nn)) == 
GDK_SUCCEED && sbn) { \
                                        BATins(bn, sbn, FALSE);                 
                                        \
                                        BBPunfix(sbn->batCacheid);              
                                        \
                                        BBPunfix(s->batCacheid);                
                                        \
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1958,7 +1958,7 @@ rel2bin_except( mvc *sql, sql_rel *rel, 
                s = stmt_binop(sql->sa, glcnt, grcnt, sub); /* use count */
 
                /* now we need to add the groups which weren't in B */
-               lcnt = stmt_project(sql->sa, stmt_reverse(sql->sa, lm), s);
+               lcnt = stmt_reorder_project(sql->sa, stmt_reverse(sql->sa, lm), 
s);
                s = stmt_union(sql->sa, ecnt, lcnt);
                o = stmt_mark_tail(sql->sa, lext, 0);
                s = stmt_reorder_project(sql->sa, stmt_reverse(sql->sa, o), s);
@@ -2258,14 +2258,15 @@ rel2bin_project( mvc *sql, sql_rel *rel,
                        if (!limit) {   /* topn based on a single column */
                                limit = stmt_limit(sql->sa, orderbycolstmt, 
stmt_atom_wrd(sql->sa, 0), l, LIMIT_DIRECTION(is_ascending(orderbycole), 1, 
inc));
                        } else {        /* topn based on 2 columns */
-                               stmt *obc = stmt_project(sql->sa, 
stmt_mirror(sql->sa, limit), orderbycolstmt);
+                               stmt *obc = stmt_reorder_project(sql->sa, 
stmt_mirror(sql->sa, limit), orderbycolstmt);
+
                                limit = stmt_limit2(sql->sa, limit, obc, 
stmt_atom_wrd(sql->sa, 0), l, LIMIT_DIRECTION(is_ascending(orderbycole), 1, 
inc));
                        }
                        if (!limit) 
                                return NULL;
                }
 
-               if (distinct) 
+               if (!distinct) 
                        limit = stmt_reverse(sql->sa, stmt_mark_tail(sql->sa, 
limit, 0));
                else    /* add limit to mark end of pqueue topns */
                        limit = stmt_limit(sql->sa, limit, 
stmt_atom_wrd(sql->sa, 0), l, LIMIT_DIRECTION(0, 0, 0));
@@ -3260,12 +3261,12 @@ update_check_ukey(mvc *sql, stmt **updat
 
                /* s should be empty */
                if (!isNew(k)) {
-                       //stmt *nu_tids = stmt_tdiff(sql->sa, dels, tids); /* 
not updated ids */
+                       stmt *nu_tids = stmt_tdiff(sql->sa, dels, tids); /* not 
updated ids */
                        assert (updates);
 
                        h = updates[c->c->colnr]->op2;
-                       o = stmt_diff(sql->sa, stmt_col(sql, c->c, dels), 
stmt_reverse(sql->sa, tids));
-                       //o = stmt_col(sql, c->c, nu_tids);
+                       //o = stmt_diff(sql->sa, stmt_col(sql, c->c, dels), 
stmt_reverse(sql->sa, tids));
+                       o = stmt_col(sql, c->c, nu_tids);
                        s = stmt_join(sql->sa, o, h, cmp_equal);
                        s = stmt_result(sql->sa, s, 0);
                        s = stmt_binop(sql->sa, stmt_aggr(sql->sa, s, NULL, 
NULL, cnt, 1, 0), stmt_atom_wrd(sql->sa, 0), ne);
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -887,25 +887,6 @@ static int
                                q = pushArgument(mb,q, l);
                                q = pushArgument(mb, q, topn);
                                l = getDestVar(q);
-
-                               /* pqueue doesn't handle offsets, ie use slice 
for this */
-
-                               /* since both arguments of algebra.slice are
-                                  inclusive correct the LIMIT value by
-                                  subtracting 1 */
-                               if (s->op2->op4.aval->data.val.wval) {
-                                       assert(0);
-                                       q = newStmt1(mb, calcRef, "-");
-                                       q = pushArgument(mb, q, topn);
-                                       q = pushInt(mb, q, 1);
-                                       len = getDestVar(q);
-
-                                       q = newStmt1(mb, algebraRef, "slice");
-                                       q = pushArgument(mb, q, l);
-                                       q = pushArgument(mb, q, offset);
-                                       q = pushArgument(mb, q, len);
-                                       l = getDestVar(q);
-                               }
                        } else {
                                q = newStmt1(mb, calcRef, "+");
                                q = pushArgument(mb, q, offset);
diff --git a/sql/backends/monet5/sql_optimizer.c 
b/sql/backends/monet5/sql_optimizer.c
--- a/sql/backends/monet5/sql_optimizer.c
+++ b/sql/backends/monet5/sql_optimizer.c
@@ -70,7 +70,8 @@ BATlocation(str *fnme, int *bid)
        BAT *b = BBPquickdesc(*bid, FALSE);
        char path[BUFSIZ], *s;
 
-       if (b == NULL)
+       *fnme = NULL;
+       if (b == NULL || (!b->T->heap.filename && !b->H->heap.filename))
                return 0;
 
        snprintf(path, BUFSIZ, "%s%c", GDKgetenv("gdk_dbpath"), DIR_SEP);
diff --git a/sql/benchmarks/tpch/Tests/02-explain.stable.out 
b/sql/benchmarks/tpch/Tests/02-explain.stable.out
--- a/sql/benchmarks/tpch/Tests/02-explain.stable.out
+++ b/sql/benchmarks/tpch/Tests/02-explain.stable.out
@@ -74,12 +74,12 @@ function user.s2_1{autoCommit=true}(A0:i
     X_18 := sql.projectdelta(X_7,X_10,X_13,r1_13,X_16);
     X_21 := sql.bind(X_6,"sys","region","r_name",0);
     X_19:bat[:oid,:oid]  := sql.tid(X_6,"sys","region");
-    X_324 := algebra.subselect(X_21,X_19,A3,A3,true,true,false);
+    X_326 := algebra.subselect(X_21,X_19,A3,A3,true,true,false);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to