Changeset: 7b05a869ea2a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7b05a869ea2a
Modified Files:
        gdk/ChangeLog.Dec2016
        gdk/gdk.h
        gdk/gdk_bat.c
        gdk/gdk_batop.c
        gdk/gdk_bbp.c
        monetdb5/modules/mal/tablet.c
Branch: Dec2016
Log Message:

Require that nokey values are not lying.
If key is 0 and both nokey values are 0, we don't know whether the BAT
has duplicates or not.  If key is 0 and at least one of the nokey
values is not 0, the nokey values are BUNs that point to proof that
there are duplicates.  As before, if key is not 0, there are no
duplicates (and the nokey values must both be 0).


diffs (140 lines):

diff --git a/gdk/ChangeLog.Dec2016 b/gdk/ChangeLog.Dec2016
--- a/gdk/ChangeLog.Dec2016
+++ b/gdk/ChangeLog.Dec2016
@@ -1,6 +1,10 @@
 # ChangeLog file for MonetDB
 # This file is updated with Maddlog
 
+* Thu Dec  1 2016 Sjoerd Mullender <sjo...@acm.org>
+- The tnokey values must now be 0 if it is not known whether all values
+  in a column are distinct.
+
 * Wed Oct 26 2016 Sjoerd Mullender <sjo...@acm.org>
 - Implemented conversion to str from any type (not just the internal
   types).
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -831,7 +831,7 @@ typedef struct {
         sorted:1,              /* column is sorted in ascending order */
         revsorted:1;           /* column is sorted in descending order */
        oid align;              /* OID for sync alignment */
-       BUN nokey[2];           /* positions that prove key ==FALSE */
+       BUN nokey[2];           /* positions that prove key==FALSE */
        BUN nosorted;           /* position that proves sorted==FALSE */
        BUN norevsorted;        /* position that proves revsorted==FALSE */
        BUN nodense;            /* position that proves dense==FALSE */
@@ -855,7 +855,8 @@ typedef struct {
 #define GDKLIBRARY_OLDWKB      061031  /* old geom WKB format */
 #define GDKLIBRARY_INSERTED    061032  /* inserted and deleted in BBP.dir */
 #define GDKLIBRARY_HEADED      061033  /* head properties are stored */
-#define GDKLIBRARY             061034
+#define GDKLIBRARY_NOKEY       061034  /* nokey values can't be trusted */
+#define GDKLIBRARY             061035
 
 typedef struct BAT {
        /* static bat properties */
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1454,6 +1454,8 @@ BATkey(BAT *b, int flag)
        b->tkey = flag;
        if (!flag)
                b->tdense = 0;
+       else
+               b->tnokey[0] = b->tnokey[1] = 0;
        if (flag && VIEWtparent(b)) {
                /* if a view is key, then so is the parent if the two
                 * are aligned */
@@ -2133,6 +2135,18 @@ BATassertProps(BAT *b)
                        assert(cmpf(BUNtail(bi, b->tnorevsorted - 1),
                                    BUNtail(bi, b->tnorevsorted)) < 0);
        }
+       /* if tkey property set, both tnokey values must be 0 */
+       assert(!b->tkey || (b->tnokey[0] == 0 && b->tnokey[1] == 0));
+       if (!b->tkey && (b->tnokey[0] != 0 || b->tnokey[1] != 0)) {
+               /* if tkey not set and tnokey indicates a proof of
+                * non-key-ness, make sure the tnokey values are in
+                * range and indeed provide a proof */
+               assert(b->tnokey[0] != b->tnokey[1]);
+               assert(b->tnokey[0] < b->batCount);
+               assert(b->tnokey[1] < b->batCount);
+               assert(cmpf(BUNtail(bi, b->tnokey[0]),
+                           BUNtail(bi, b->tnokey[1])) == 0);
+       }
        /* var heaps must have sane sizes */
        assert(b->tvheap == NULL || b->tvheap->free <= b->tvheap->size);
 
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -464,8 +464,11 @@ BATappend(BAT *b, BAT *n, bit force)
                        b->tdense = n->tdense;
                        b->tnodense = n->tnodense;
                        b->tkey |= (n->tkey & TRUE);
-                       b->tnokey[0] = n->tnokey[0];
-                       b->tnokey[1] = n->tnokey[1];
+                       /* if BOUND2BTRUE, uniqueness is guaranteed above */
+                       if ((b->tkey & BOUND2BTRUE) == 0) {
+                               b->tnokey[0] = n->tnokey[0];
+                               b->tnokey[1] = n->tnokey[1];
+                       }
                        b->tnonil = n->tnonil;
                } else {
                        BUN last = BUNlast(b) - 1;
@@ -485,7 +488,7 @@ BATappend(BAT *b, BAT *n, bit force)
                                b->trevsorted = FALSE;
                                b->tnorevsorted = 0;
                        }
-                       if (b->tkey &&
+                       if (b->tkey == 1 &&
                            (!(BATtordered(b) || BATtrevordered(b)) ||
                             n->tkey == 0 || xx == 0)) {
                                BATkey(b, FALSE);
@@ -542,7 +545,8 @@ BATappend(BAT *b, BAT *n, bit force)
                        }
                        i++;
                }
-               BATkey(b, FALSE);
+               if ((b->tkey & BOUND2BTRUE) == 0)
+                       BATkey(b, FALSE);
                b->tdense = b->tsorted = b->trevsorted = 0;
        }
        b->tnonil &= n->tnonil;
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -1155,6 +1155,13 @@ BBPreadEntries(FILE *fp, int oidsize, in
                                needcommit = 1;
                        }
                }
+               if (bbpversion <= GDKLIBRARY &&
+                   (bn->tnokey[0] != 0 || bn->tnokey[1] != 0)) {
+                       /* we don't trust the nokey values */
+                       bn->tnokey[0] = bn->tnokey[1] = 0;
+                       bn->batDirtydesc = 1;
+                       needcommit = 1;
+               }
 
                if (buf[nread] != '\n' && buf[nread] != ' ')
                        GDKfatal("BBPinit: invalid format for BBP.dir\n%s", 
buf);
@@ -1206,6 +1213,7 @@ BBPheader(FILE *fp, oid *BBPoid, int *OI
                exit(1);
        }
        if (bbpversion != GDKLIBRARY &&
+           bbpversion != GDKLIBRARY_NOKEY &&
            bbpversion != GDKLIBRARY_SORTEDPOS &&
            bbpversion != GDKLIBRARY_OLDWKB &&
            bbpversion != GDKLIBRARY_INSERTED &&
diff --git a/monetdb5/modules/mal/tablet.c b/monetdb5/modules/mal/tablet.c
--- a/monetdb5/modules/mal/tablet.c
+++ b/monetdb5/modules/mal/tablet.c
@@ -75,7 +75,7 @@ void_bat_create(int adt, BUN nr)
        b->tnodense = 0;
        b->tkey = FALSE;
        b->tnokey[0] = 0;
-       b->tnokey[1] = 1;
+       b->tnokey[1] = 0;
        return b;
 }
 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to