Changeset: 96778c0a89aa for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=96778c0a89aa
Modified Files:
        gdk/ChangeLog
        gdk/gdk.h
        gdk/gdk_align.c
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_delta.c
        monetdb5/extras/sphinx/sphinx.c
        monetdb5/mal/mal_authorize.c
        monetdb5/modules/kernel/algebra.c
        monetdb5/modules/kernel/bat5.c
        monetdb5/modules/kernel/batmmath.c
        monetdb5/modules/kernel/microbenchmark.c
        monetdb5/modules/mal/mkey.c
        monetdb5/modules/mal/pcre.c
        sql/backends/monet5/UDF/udf.c
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_cast_impl_down_from_int.h
        sql/backends/monet5/sql_cast_impl_up_to_flt.h
        sql/backends/monet5/sql_cast_impl_up_to_int.h
        sql/backends/monet5/sql_fround_impl.h
        sql/backends/monet5/sql_round_impl.h
        sql/backends/monet5/vaults/netcdf/netcdf.c
        sql/storage/bat/bat_storage.c
Branch: default
Log Message:

BATkey now works on the TAIL column instead of the HEAD column.


diffs (truncated from 572 to 300 lines):

diff --git a/gdk/ChangeLog b/gdk/ChangeLog
--- a/gdk/ChangeLog
+++ b/gdk/ChangeLog
@@ -2,6 +2,7 @@
 # This file is updated with Maddlog
 
 * Mon Jun 27 2016 Sjoerd Mullender <[email protected]>
+- BATkey now works on the TAIL column instead of the HEAD column.
 - Replaced BATseqbase with BAThseqbase and BATtseqbase, the former for
   setting the seqbase on the HEAD, the latter for setting the seqbase
   on the TAIL.
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2822,14 +2822,6 @@ gdk_export void ALIGNsetT(BAT *b1, BAT *
 #define VIEWtparent(x) ((x)->T->heap.parentid)
 #define VIEWvtparent(x)        
(((x)->T->vheap==NULL||(x)->T->vheap->parentid==abs((x)->batCacheid))?0:(x)->T->vheap->parentid)
 
-/* VIEWparentcol(b) tells whether the head column was inherited from
- * the parent "as is". We must check whether the type was not
- * overridden in the view.
- */
-#define VIEWparentcol(b)                                       \
-       ((VIEWhparent(b) && (b)->htype                          \
-         && (b)->htype == BBP_cache(VIEWhparent(b))->htype)    \
-        ?VIEWhparent(b):0)
 /*
  * @+ BAT Iterators
  *  @multitable @columnfractions 0.15 0.7
diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -138,7 +138,7 @@ ALIGNsetT(BAT *b1, BAT *b2)
                b1->T->nonil = b2->T->nonil;
        } else if (BATtkey(b2))
                BATtseqbase(b1, 0);
-       BATkey(BATmirror(b1), BATtkey(b2));
+       BATkey(b1, BATtkey(b2));
        b1->tsorted = BATtordered(b2);
        b1->trevsorted = BATtrevordered(b2);
        b1->talign = b2->talign;
@@ -165,27 +165,12 @@ ALIGNsynced(BAT *b1, BAT *b2)
        BATcheck(b1, "ALIGNsynced: bat 1 required", 0);
        BATcheck(b2, "ALIGNsynced: bat 2 required", 0);
 
-       /* first try to prove head columns are not in sync */
-       if (BATcount(b1) != BATcount(b2))
-               return 0;
-       if (ATOMtype(BAThtype(b1)) != ATOMtype(BAThtype(b2)))
-               return 0;
-       if (BAThvoid(b1) && BAThvoid(b2))
-               return (b1->hseqbase == b2->hseqbase);
+       assert(b1->htype == TYPE_void);
+       assert(b2->htype == TYPE_void);
+       assert(b1->hseqbase != oid_nil);
+       assert(b2->hseqbase != oid_nil);
 
-       /* then try that they are */
-       if (b1->batCacheid == b2->batCacheid)
-               return 1;       /* same bat. trivial case */
-       if (BATcount(b1) == 0)
-               return 1;       /* empty bats of same type. trivial case */
-       if (b1->halign && b1->halign == b2->halign)
-               return 1;       /* columns marked as equal by algorithmics */
-       if (VIEWparentcol(b1) && ALIGNsynced(BBPcache(VIEWhparent(b1)), b2))
-               return 1;       /* view on same bat --- left recursive def.. */
-       if (VIEWparentcol(b2) && ALIGNsynced(b1, BBPcache(VIEWhparent(b2))))
-               return 1;       /* view on same bat --- right recursive def.. */
-
-       return 0;               /* we simply don't know */
+       return BATcount(b1) == BATcount(b2) && b1->hseqbase == b2->hseqbase;
 }
 
 /*
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -808,7 +808,7 @@ COLcopy(BAT *b, int tt, int writable, in
                bn->trevsorted = b->trevsorted;
                bn->tdense = b->tdense && ATOMtype(bn->ttype) == TYPE_oid;
                if (b->tkey)
-                       BATkey(BATmirror(bn), TRUE);
+                       BATkey(bn, TRUE);
                bn->T->nonil = b->T->nonil;
                if (b->T->nosorted > l && b->T->nosorted < h)
                        bn->T->nosorted = b->T->nosorted - l + BUNfirst(bn);
@@ -1188,7 +1188,7 @@ BUNinplace(BAT *b, BUN p, const void *t,
        } else if (b->T->norevsorted >= p)
                b->T->norevsorted = 0;
        if (((b->ttype != TYPE_void) & b->tkey & !(b->tkey & BOUND2BTRUE)) && 
b->batCount > 1) {
-               BATkey(BATmirror(b), FALSE);
+               BATkey(b, FALSE);
        }
        if (b->T->nonil)
                b->T->nonil = t && atom_CMP(t, ATOMnilptr(b->ttype), b->ttype) 
!= 0;
@@ -1450,33 +1450,41 @@ BATmemsize(BAT *b, int dirty)
 gdk_return
 BATkey(BAT *b, int flag)
 {
-       bat parent;
-
        BATcheck(b, "BATkey", GDK_FAIL);
-       parent = VIEWparentcol(b);
-       if (b->htype == TYPE_void) {
-               if (b->hseqbase == oid_nil && flag == BOUND2BTRUE) {
+       assert(b->batCacheid > 0);
+       if (b->ttype == TYPE_void) {
+               if (b->tseqbase == oid_nil && flag == BOUND2BTRUE) {
                        GDKerror("BATkey: nil-column cannot be kept unique.\n");
                        return GDK_FAIL;
                }
-               if (b->hseqbase != oid_nil && flag == FALSE) {
+               if (b->tseqbase != oid_nil && flag == FALSE) {
                        GDKerror("BATkey: dense column must be unique.\n");
                        return GDK_FAIL;
                }
-               if (b->hseqbase == oid_nil && flag == TRUE && b->batCount > 1) {
+               if (b->tseqbase == oid_nil && flag == TRUE && b->batCount > 1) {
                        GDKerror("BATkey: void column cannot be unique.\n");
                        return GDK_FAIL;
                }
        }
        if (flag)
-               flag |= (1 | b->hkey);
-       if (b->hkey != flag)
+               flag |= (1 | b->tkey);
+       if (b->tkey != flag)
                b->batDirtydesc = TRUE;
-       b->hkey = flag;
+       b->tkey = flag;
        if (!flag)
-               b->hdense = 0;
-       if (flag && parent && ALIGNsynced(b, BBP_cache(parent)))
-               return BATkey(BBP_cache(parent), TRUE);
+               b->tdense = 0;
+       if (flag && VIEWtparent(b)) {
+               /* if a view is key, then so is the parent if the two
+                * are aligned */
+               BAT *bp = BBP_cache(-VIEWtparent(b));
+               if (BATcount(b) == BATcount(bp) &&
+                   ATOMtype(BATttype(b)) == ATOMtype(BATttype(bp)) &&
+                   !BATtkey(bp) &&
+                   ((BATtvoid(b) && BATtvoid(bp) && b->tseqbase == 
bp->tseqbase) ||
+                    BATcount(b) == 0 ||
+                    (b->talign && b->talign == bp->talign)))
+                       return BATkey(bp, TRUE);
+       }
        return GDK_SUCCEED;
 }
 
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -454,7 +454,7 @@ BATappend(BAT *b, BAT *n, bit force)
                        if (b->tkey &&
                            (!(BATtordered(b) || BATtrevordered(b)) ||
                             n->tkey == 0 || xx == 0)) {
-                               BATkey(BATmirror(b), FALSE);
+                               BATkey(b, FALSE);
                        }
                        if (b->ttype != TYPE_void && b->tsorted && b->tdense &&
                            (BATtdense(n) == 0 ||
@@ -520,7 +520,7 @@ BATappend(BAT *b, BAT *n, bit force)
                                }
                                i++;
                        }
-                       BATkey(BATmirror(b), FALSE);
+                       BATkey(b, FALSE);
                        b->tdense = b->tsorted = b->trevsorted = 0;
                }
        }
@@ -782,13 +782,13 @@ BATslice(BAT *b, BUN l, BUN h)
                bn->tsorted = ATOMlinear(b->ttype);
                bn->hrevsorted = 1;
                bn->trevsorted = ATOMlinear(b->ttype);
-               BATkey(BATmirror(bn), 1);
+               BATkey(bn, 1);
        } else {
                bn->tsorted = b->tsorted;
                bn->hrevsorted = 0;
                bn->H->norevsorted = BUNfirst(bn) + 1;
                bn->trevsorted = b->trevsorted;
-               BATkey(BATmirror(bn), BATtkey(b));
+               BATkey(bn, BATtkey(b));
        }
        bn->T->nonil = b->T->nonil || bn->batCount == 0;
        bn->T->nil = 0;         /* we just don't know */
diff --git a/gdk/gdk_delta.c b/gdk/gdk_delta.c
--- a/gdk/gdk_delta.c
+++ b/gdk/gdk_delta.c
@@ -158,7 +158,7 @@ BATundo(BAT *b)
                b->tsorted = 0;
                b->trevsorted = 0;
                if (b->tkey)
-                       BATkey(BATmirror(b), FALSE);
+                       BATkey(b, FALSE);
                HASHdestroy(b);
        }
        b->batFirst = b->batDeleted;
diff --git a/monetdb5/extras/sphinx/sphinx.c b/monetdb5/extras/sphinx/sphinx.c
--- a/monetdb5/extras/sphinx/sphinx.c
+++ b/monetdb5/extras/sphinx/sphinx.c
@@ -59,7 +59,7 @@ sphinx_searchIndexLimit(BAT **ret, /* pu
        bn->T->sorted = 0;
        bn->T->revsorted = 0;
        bn->T->nonil = 1;
-       BATkey(BATmirror(bn), FALSE);
+       BATkey(bn, FALSE);
 
        *ret = bn;
        return MAL_SUCCEED;
diff --git a/monetdb5/mal/mal_authorize.c b/monetdb5/mal/mal_authorize.c
--- a/monetdb5/mal/mal_authorize.c
+++ b/monetdb5/mal/mal_authorize.c
@@ -161,7 +161,7 @@ AUTHinitTables(str *passwd) {
                if (user == NULL)
                        throw(MAL, "initTables.user", MAL_MALLOC_FAIL " user 
table");
 
-               BATkey(BATmirror(user), TRUE);
+               BATkey(user, TRUE);
                BBPrename(BBPcacheid(user), "M5system_auth_user");
                BATmode(user, PERSISTENT);
        } else {
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
@@ -1103,7 +1103,7 @@ str ALGreuse(bat *ret, const bat *bid)
                        BATsetcount(bn,BATcount(b));
                        bn->tsorted = FALSE;
                        bn->trevsorted = FALSE;
-                       BATkey(BATmirror(bn),FALSE);
+                       BATkey(bn,FALSE);
                }
                BBPkeepref(*ret= bn->batCacheid);
                BBPunfix(b->batCacheid);
diff --git a/monetdb5/modules/kernel/bat5.c b/monetdb5/modules/kernel/bat5.c
--- a/monetdb5/modules/kernel/bat5.c
+++ b/monetdb5/modules/kernel/bat5.c
@@ -516,7 +516,7 @@ BKCsetkey(bat *res, const bat *bid, cons
        if ((b = BATdescriptor(*bid)) == NULL) {
                throw(MAL, "bat.setKey", RUNTIME_OBJECT_MISSING);
        }
-       BATkey(BATmirror(b), *param ? BOUND2BTRUE :FALSE);
+       BATkey(b, *param ? BOUND2BTRUE :FALSE);
        *res = b->batCacheid;
        BBPkeepref(b->batCacheid);
        return MAL_SUCCEED;
diff --git a/monetdb5/modules/kernel/batmmath.c 
b/monetdb5/modules/kernel/batmmath.c
--- a/monetdb5/modules/kernel/batmmath.c
+++ b/monetdb5/modules/kernel/batmmath.c
@@ -73,7 +73,7 @@ str CMDscience_bat_##TYPE##_##FUNC(bat *
        bn->trevsorted = 0;                                                     
                                        \
        bn->T->nil = b->T->nil;                                                 
                                \
        bn->T->nonil = b->T->nonil;                                             
                                \
-       BATkey(BATmirror(bn), 0);                                               
                                \
+       BATkey(bn, 0);                                                          
                                        \
        if (!(bn->batDirty&2))                                                  
                                \
                BATsetaccess(bn, BAT_READ);                                     
                                \
        BBPkeepref(*ret = bn->batCacheid);                                      
                        \
@@ -118,7 +118,7 @@ str CMDscience_bat_cst_##FUNC##_##TYPE(b
        bn->trevsorted = 0;                                                     
                                                \
        bn->T->nil = b->T->nil;                                                 
                                        \
        bn->T->nonil = b->T->nonil;                                             
                                        \
-       BATkey(BATmirror(bn),0);                                                
                                        \
+       BATkey(bn,0);                                                           
                                                \
        if (!(bn->batDirty&2))                                                  
                                        \
                BATsetaccess(bn, BAT_READ);                                     
                                        \
        BBPkeepref(*ret = bn->batCacheid);                                      
                                \
@@ -162,7 +162,7 @@ str CMDscience_cst_bat_##FUNC##_##TYPE(b
        bn->trevsorted = 0;                                                     
                                                \
        bn->T->nil = b->T->nil;                                                 
                                        \
        bn->T->nonil = b->T->nonil;                                             
                                        \
-       BATkey(BATmirror(bn),0);                                                
                                        \
+       BATkey(bn,0);                                                           
                                                \
        if (!(bn->batDirty&2))                                                  
                                        \
                BATsetaccess(bn, BAT_READ);                                     
                                        \
        BBPkeepref(*ret = bn->batCacheid);                                      
                                \
diff --git a/monetdb5/modules/kernel/microbenchmark.c 
b/monetdb5/modules/kernel/microbenchmark.c
--- a/monetdb5/modules/kernel/microbenchmark.c
+++ b/monetdb5/modules/kernel/microbenchmark.c
@@ -50,7 +50,7 @@ BATrandom(BAT **bn, oid *base, lng *size
                b->tsorted = 1;
                b->trevsorted = 0;
                b->tdense = FALSE;
-               BATkey(BATmirror(b), TRUE);
+               BATkey(b, TRUE);
                *bn = b;
                return GDK_SUCCEED;
        }
@@ -79,7 +79,7 @@ BATrandom(BAT **bn, oid *base, lng *size
        b->tsorted = FALSE;
        b->trevsorted = FALSE;
        b->tdense = FALSE;
-       BATkey(BATmirror(b), FALSE);
+       BATkey(b, FALSE);
        *bn = b;
        return GDK_SUCCEED;
 }
@@ -110,7 +110,7 @@ BATuniform(BAT **bn, oid *base, lng *siz
                b->tsorted = 1;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to