Changeset: adb12089c465 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=adb12089c465
Modified Files:
gdk/gdk.h
gdk/gdk_bat.c
gdk/gdk_bbp.c
monetdb5/ChangeLog.Apr2019
monetdb5/modules/atoms/blob.c
sql/test/orderidx/Tests/imprints_all_types.stable.out
sql/test/orderidx/Tests/oidx_all_types.stable.out
Branch: default
Log Message:
Merge with Apr2019 branch.
diffs (truncated from 328 to 300 lines):
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -774,7 +774,8 @@ typedef struct {
#define GDKLIBRARY_TALIGN 061036U /* talign field in BBP.dir */
#define GDKLIBRARY_NIL_NAN 061037U /* flt/dbl NIL not represented by NaN */
-#define GDKLIBRARY 061040U
+#define GDKLIBRARY_BLOB_SORT 061040U /* blob compare changed */
+#define GDKLIBRARY 061041U
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
@@ -929,7 +929,12 @@ setcolprops(BAT *b, const void *x)
if (b->ttype == TYPE_oid) {
b->tseqbase = * (const oid *) x;
}
+ if (!isnil && ATOMlinear(b->ttype)) {
+ BATsetprop(b, GDK_MAX_VALUE, b->ttype, x);
+ BATsetprop(b, GDK_MIN_VALUE, b->ttype, x);
+ }
}
+ return;
} else if (b->ttype == TYPE_void) {
/* not the first value in a VOID column: we keep the
* seqbase, and x is not used, so only some properties
@@ -950,7 +955,10 @@ setcolprops(BAT *b, const void *x)
b->tnil = true;
b->tnonil = false;
}
- } else {
+ return;
+ } else if (ATOMlinear(b->ttype)) {
+ PROPrec *prop;
+
bi = bat_iterator(b);
pos = BUNlast(b);
prv = BUNtail(bi, pos - 1);
@@ -969,24 +977,52 @@ setcolprops(BAT *b, const void *x)
b->tnokey[1] = pos;
}
}
- if (b->tsorted && cmp > 0) {
- /* out of order */
- b->tsorted = false;
- b->tnosorted = pos;
+ if (b->tsorted) {
+ if (cmp > 0) {
+ /* out of order */
+ b->tsorted = false;
+ b->tnosorted = pos;
+ } else if (cmp < 0 && !isnil) {
+ /* new largest value */
+ BATsetprop(b, GDK_MAX_VALUE, b->ttype, x);
+ }
+ } else if (!isnil &&
+ (prop = BATgetprop(b, GDK_MAX_VALUE)) != NULL &&
+ ATOMcmp(b->ttype, VALptr(&prop->v), x) < 0) {
+ BATsetprop(b, GDK_MAX_VALUE, b->ttype, x);
}
- if (b->trevsorted && cmp < 0) {
- /* out of order */
- b->trevsorted = false;
- b->tnorevsorted = pos;
+ if (b->trevsorted) {
+ if (cmp < 0) {
+ /* out of order */
+ b->trevsorted = false;
+ b->tnorevsorted = pos;
+ /* if there is a nil in the BAT, it is
+ * the smallest, but that doesn't
+ * count for the property, so the new
+ * value may still be smaller than the
+ * smallest non-nil so far */
+ if (!b->tnonil && !isnil &&
+ (prop = BATgetprop(b, GDK_MIN_VALUE)) !=
NULL &&
+ ATOMcmp(b->ttype, VALptr(&prop->v), x) > 0)
{
+ BATsetprop(b, GDK_MIN_VALUE, b->ttype,
x);
+ }
+ } else if (cmp > 0 && !isnil) {
+ /* new smallest value */
+ BATsetprop(b, GDK_MIN_VALUE, b->ttype, x);
+ }
+ } else if (!isnil &&
+ (prop = BATgetprop(b, GDK_MIN_VALUE)) != NULL &&
+ ATOMcmp(b->ttype, VALptr(&prop->v), x) > 0) {
+ BATsetprop(b, GDK_MIN_VALUE, b->ttype, x);
}
if (BATtdense(b) && (cmp >= 0 || * (const oid *) prv + 1 != *
(const oid *) x)) {
assert(b->ttype == TYPE_oid);
b->tseqbase = oid_nil;
}
- if (isnil) {
- b->tnonil = false;
- b->tnil = true;
- }
+ }
+ if (isnil) {
+ b->tnonil = false;
+ b->tnil = true;
}
}
@@ -1046,37 +1082,17 @@ BUNappend(BAT *b, const void *t, bool fo
IMPSdestroy(b); /* no support for inserts in imprints yet */
OIDXdestroy(b);
- if (b->ttype != TYPE_void
- && ATOMlinear(b->ttype)
- && ATOMcmp(b->ttype, t, ATOMnilptr(b->ttype)) != 0) {
- PROPrec *prop;
-
- if (b->batCount == 1) {
- BATsetprop(b, GDK_MAX_VALUE, b->ttype, t);
- BATsetprop(b, GDK_MIN_VALUE, b->ttype, t);
- } else {
- if ((prop = BATgetprop(b, GDK_MAX_VALUE)) != NULL &&
- ATOMcmp(b->ttype, VALptr(&prop->v), t) < 0) {
- BATsetprop(b, GDK_MAX_VALUE, b->ttype, t);
+#if 0 /* enable if we have more properties than just min/max */
+ PROPrec *prop;
+ do {
+ for (prop = b->tprops; prop; prop = prop->next)
+ if (prop->id != GDK_MAX_VALUE &&
+ prop->id != GDK_MIN_VALUE) {
+ BATrmprop(b, prop->id);
+ break;
}
- if ((prop = BATgetprop(b, GDK_MIN_VALUE)) != NULL &&
- ATOMcmp(b->ttype, VALptr(&prop->v), t) > 0) {
- BATsetprop(b, GDK_MIN_VALUE, b->ttype, t);
- }
- }
-#if 0 /* enable if we have more properties than just min/max */
- do {
- for (prop = b->tprops; prop; prop = prop->next)
- if (prop->id != GDK_MAX_VALUE &&
- prop->id != GDK_MIN_VALUE) {
- BATrmprop(b, prop->id);
- break;
- }
- } while (prop);
+ } while (prop);
#endif
- } else {
- PROPdestroy(b);
- }
if (b->thash == (Hash *) 1 ||
(b->thash && ((size_t *) b->thash->heap.base)[0] & (1 << 24))) {
/* don't bother first loading the hash to then change
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -689,6 +689,13 @@ heapinit(BAT *b, const char *buf, int *h
b->theap.newstorage = (storage_t) storage;
b->theap.farmid = BBPselectfarm(PERSISTENT, b->ttype, offheap);
b->theap.dirty = false;
+#ifdef GDKLIBRARY_BLOB_SORT
+ if (bbpversion <= GDKLIBRARY_BLOB_SORT && strcmp(type, "blob") == 0) {
+ b->tsorted = b->trevsorted = false;
+ b->tnosorted = b->tnorevsorted = 0;
+ OIDXdestroy(b);
+ }
+#endif
if (b->theap.free > b->theap.size) {
GDKerror("BBPinit: \"free\" value larger than \"size\" in heap
of bat %d\n", (int) bid);
return -1;
@@ -913,6 +920,7 @@ BBPheader(FILE *fp)
return 0;
}
if (bbpversion != GDKLIBRARY &&
+ bbpversion != GDKLIBRARY_BLOB_SORT &&
bbpversion != GDKLIBRARY_NIL_NAN &&
bbpversion != GDKLIBRARY_TALIGN) {
GDKerror("BBPinit: incompatible BBP version: expected 0%o, got
0%o.\n"
diff --git a/monetdb5/ChangeLog.Apr2019 b/monetdb5/ChangeLog.Apr2019
--- a/monetdb5/ChangeLog.Apr2019
+++ b/monetdb5/ChangeLog.Apr2019
@@ -1,6 +1,10 @@
# ChangeLog file for MonetDB5
# This file is updated with Maddlog
+* Fri Feb 8 2019 Sjoerd Mullender <[email protected]>
+- Changed the way blobs are ordered. Before, shorter blobs came before
+ longer, now the contents is compared first.
+
* Wed Jan 23 2019 Sjoerd Mullender <[email protected]>
- Removed function blob.tostring() since it cannot guarantee that the
resulting string is properly encoded in UTF-8.
diff --git a/monetdb5/modules/atoms/blob.c b/monetdb5/modules/atoms/blob.c
--- a/monetdb5/modules/atoms/blob.c
+++ b/monetdb5/modules/atoms/blob.c
@@ -84,15 +84,21 @@ static char hexit[] = "0123456789ABCDEF"
int
BLOBcmp(const blob *l, const blob *r)
{
- size_t len = l->nitems;
-
- if (len != r->nitems)
- return len < r->nitems ? -1 : len > r->nitems ? 1 : 0;
-
- if (len == ~(size_t) 0)
- return (0);
-
- return memcmp(l->data, r->data, len);
+ int c;
+ if (r->nitems == ~(size_t)0)
+ return l->nitems != ~(size_t)0;
+ if (l->nitems == ~(size_t)0)
+ return -1;
+ if (l->nitems < r->nitems) {
+ c = memcmp(l->data, r->data, l->nitems);
+ if (c == 0)
+ return -1;
+ } else {
+ c = memcmp(l->data, r->data, r->nitems);
+ if (c == 0)
+ return l->nitems > r->nitems;
+ }
+ return c;
}
void
diff --git a/sql/test/orderidx/Tests/imprints_all_types.stable.out
b/sql/test/orderidx/Tests/imprints_all_types.stable.out
--- a/sql/test/orderidx/Tests/imprints_all_types.stable.out
+++ b/sql/test/orderidx/Tests/imprints_all_types.stable.out
@@ -580,19 +580,19 @@ COMMIT;
% blob # name
% blob # type
% 0 # length
+[ 01234567 ]
+[ 01234567 ]
[ 123456 ]
[ 123456 ]
-[ 01234567 ]
-[ 01234567 ]
#select "blob100" from all_types order by "blob100" ASC;
% sys.all_types # table_name
% blob100 # name
% blob # type
% 0 # length
+[ 01234567 ]
+[ 01234567 ]
[ 123456 ]
[ 123456 ]
-[ 01234567 ]
-[ 01234567 ]
#select "clob" from all_types order by "clob" ASC;
% sys.all_types # table_name
% clob # name
@@ -1021,19 +1021,19 @@ COMMIT;
% blob # name
% blob # type
% 0 # length
+[ 123456 ]
+[ 123456 ]
[ 01234567 ]
[ 01234567 ]
-[ 123456 ]
-[ 123456 ]
#select "blob100" from all_types order by "blob100" DESC;
% sys.all_types # table_name
% blob100 # name
% blob # type
% 0 # length
+[ 123456 ]
+[ 123456 ]
[ 01234567 ]
[ 01234567 ]
-[ 123456 ]
-[ 123456 ]
#select "clob" from all_types order by "clob" DESC;
% sys.all_types # table_name
% clob # name
diff --git a/sql/test/orderidx/Tests/oidx_all_types.stable.out
b/sql/test/orderidx/Tests/oidx_all_types.stable.out
--- a/sql/test/orderidx/Tests/oidx_all_types.stable.out
+++ b/sql/test/orderidx/Tests/oidx_all_types.stable.out
@@ -772,19 +772,19 @@ COMMIT;
% blob # name
% blob # type
% 0 # length
+[ 01234567 ]
+[ 01234567 ]
[ 123456 ]
[ 123456 ]
-[ 01234567 ]
-[ 01234567 ]
#select "blob100" from all_types order by "blob100" ASC;
% sys.all_types # table_name
% blob100 # name
% blob # type
% 0 # length
+[ 01234567 ]
+[ 01234567 ]
[ 123456 ]
[ 123456 ]
-[ 01234567 ]
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list