Changeset: e33575e904c6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e33575e904c6
Added Files:
sql/test/Tests/fsum1.sql.src
sql/test/Tests/fsum1.stable.err.src
sql/test/Tests/fsum1.stable.out.src
sql/test/mergetables/Tests/sqlsmith.Bug-6451.sql
sql/test/mergetables/Tests/sqlsmith.Bug-6451.stable.err
sql/test/mergetables/Tests/sqlsmith.Bug-6451.stable.out
sql/test/mergetables/Tests/sqlsmith.Bug-6453.sql
sql/test/mergetables/Tests/sqlsmith.Bug-6453.stable.err
sql/test/mergetables/Tests/sqlsmith.Bug-6453.stable.out
sql/test/mergetables/Tests/sqlsmith.Bug-6455.sql
sql/test/mergetables/Tests/sqlsmith.Bug-6455.stable.err
sql/test/mergetables/Tests/sqlsmith.Bug-6455.stable.out
Modified Files:
gdk/gdk_aggr.c
gdk/gdk_group.c
gdk/gdk_hash.c
gdk/gdk_orderidx.c
sql/server/rel_dump.c
sql/server/rel_optimizer.c
sql/server/rel_rel.c
sql/server/rel_select.c
sql/test/Tests/All
sql/test/mergetables/Tests/All
Branch: default
Log Message:
Merge with Jul2017 branch.
diffs (truncated from 1048 to 300 lines):
diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c
--- a/gdk/gdk_aggr.c
+++ b/gdk/gdk_aggr.c
@@ -152,9 +152,13 @@ BATgroupaggrinit(BAT *b, BAT *g, BAT *e,
/* sum */
#if defined(_MSC_VER) && _MSC_VER < 1800
+#ifndef isnan
#define isnan(x) _isnan(x)
+#endif
+#ifndef isinf
#define isinf(x) (_fpclass(x) & (_FPCLASS_NINF | _FPCLASS_PINF))
#endif
+#endif
static inline int
samesign(double x, double y)
@@ -186,6 +190,7 @@ exchange(double *x, double *y)
*y = t;
}
+/* this function was adapted from https://bugs.python.org/file10357/msum4.py */
static BUN
dofsum(const void *restrict values, oid seqb, BUN start, BUN end,
void *restrict results, BUN ngrp, int tp1, int tp2,
diff --git a/gdk/gdk_group.c b/gdk/gdk_group.c
--- a/gdk/gdk_group.c
+++ b/gdk/gdk_group.c
@@ -88,7 +88,7 @@
} \
} \
if (extents) \
- exts[ngrp] = hseqb + p; \
+ exts[ngrp] = hseqb + p - lo; \
if (histo) \
cnts[ngrp] = 1; \
ngrps[r] = ngrp++; \
@@ -545,6 +545,7 @@ BATgroup_internal(BAT **groups, BAT **ex
bat parent;
#endif
BUN start, end, cnt;
+ BUN lo = 0;
const oid *restrict cand, *candend;
oid maxgrp = oid_nil; /* maximum value of g BAT (if subgrouping) */
PROPrec *prop;
@@ -1006,8 +1007,6 @@ BATgroup_internal(BAT **groups, BAT **ex
BATcheckhash(BBPdescriptor(parent)))
#endif
) {
- BUN lo;
-
/* we already have a hash table on b, or b is
* persistent and we could create a hash table, or b
* is a view on a bat that already has a hash table */
@@ -1034,11 +1033,8 @@ BATgroup_internal(BAT **groups, BAT **ex
bi = bat_iterator(b);
start += lo;
end += lo;
- } else
+ }
#endif
- {
- lo = 0;
- }
hs = b->thash;
gn->tsorted = 1; /* be optimistic */
diff --git a/gdk/gdk_hash.c b/gdk/gdk_hash.c
--- a/gdk/gdk_hash.c
+++ b/gdk/gdk_hash.c
@@ -273,44 +273,42 @@ BATcheckhash(BAT *b)
}
#ifdef PERSISTENTHASH
-struct hashsync {
- Heap *hp;
- bat id;
-};
-
static void
BAThashsync(void *arg)
{
- struct hashsync *hs = arg;
- Heap *hp = hs->hp;
+ BAT *b = arg;
+ Heap *hp;
int fd;
lng t0 = 0;
const char *failed = " failed";
ALGODEBUG t0 = GDKusec();
- if (HEAPsave(hp, hp->filename, NULL) == GDK_SUCCEED &&
- (fd = GDKfdlocate(hp->farmid, hp->filename, "rb+", NULL)) >= 0) {
- ((size_t *) hp->base)[0] |= 1 << 24;
- if (write(fd, hp->base, SIZEOF_SIZE_T) >= 0) {
- failed = ""; /* not failed */
- if (!(GDKdebug & FORCEMITOMASK)) {
+ MT_lock_set(&GDKhashLock(b->batCacheid));
+ if (b->thash != NULL && (hp = b->thash->heap) != NULL) {
+ if (HEAPsave(hp, hp->filename, NULL) == GDK_SUCCEED &&
+ (fd = GDKfdlocate(hp->farmid, hp->filename, "rb+", NULL))
>= 0) {
+ ((size_t *) hp->base)[0] |= 1 << 24;
+ if (write(fd, hp->base, SIZEOF_SIZE_T) >= 0) {
+ failed = ""; /* not failed */
+ if (!(GDKdebug & FORCEMITOMASK)) {
#if defined(NATIVE_WIN32)
- _commit(fd);
+ _commit(fd);
#elif defined(HAVE_FDATASYNC)
- fdatasync(fd);
+ fdatasync(fd);
#elif defined(HAVE_FSYNC)
- fsync(fd);
+ fsync(fd);
#endif
+ }
+ } else {
+ perror("write hash");
}
- } else {
- perror("write hash");
+ close(fd);
}
- close(fd);
+ ALGODEBUG fprintf(stderr, "#BAThash: persisting hash %s ("
LLFMT " usec)%s\n", hp->filename, GDKusec() - t0, failed);
}
- BBPunfix(hs->id);
- GDKfree(arg);
- ALGODEBUG fprintf(stderr, "#BAThash: persisting hash %s (" LLFMT "
usec)%s\n", hp->filename, GDKusec() - t0, failed);
+ MT_lock_unset(&GDKhashLock(b->batCacheid));
+ BBPunfix(b->batCacheid);
}
#endif
@@ -500,25 +498,19 @@ BAThash(BAT *b, BUN masksize)
memset((char *) h->Link + q * h->width, 0, (h->lim - q) *
h->width);
#endif
hp->parentid = b->batCacheid;
+ b->thash = h;
#ifdef PERSISTENTHASH
if (BBP_status(b->batCacheid) & BBPEXISTING) {
MT_Id tid;
- struct hashsync *hs = GDKmalloc(sizeof(*hs));
- if (hs != NULL) {
- BBPfix(b->batCacheid);
- hs->id = b->batCacheid;
- hs->hp = hp;
- if (MT_create_thread(&tid, BAThashsync, hs,
- MT_THR_DETACHED) < 0) {
- /* couldn't start thread: clean up */
- BBPunfix(b->batCacheid);
- GDKfree(hs);
- }
+ BBPfix(b->batCacheid);
+ if (MT_create_thread(&tid, BAThashsync, b,
+ MT_THR_DETACHED) < 0) {
+ /* couldn't start thread: clean up */
+ BBPunfix(b->batCacheid);
}
} else
ALGODEBUG fprintf(stderr, "#BAThash: NOT persisting
hash %d\n", b->batCacheid);
#endif
- b->thash = h;
ALGODEBUG {
t1 = GDKusec();
fprintf(stderr, "#BAThash: hash construction " LLFMT "
usec\n", t1 - t0);
@@ -575,27 +567,31 @@ void
HASHdestroy(BAT *b)
{
if (b) {
- if (b->thash == (Hash *) 1) {
+ Hash *hs;
+ MT_lock_set(&GDKhashLock(b->batCacheid));
+ hs = b->thash;
+ b->thash = NULL;
+ MT_lock_unset(&GDKhashLock(b->batCacheid));
+ if (hs == (Hash *) 1) {
GDKunlink(BBPselectfarm(b->batRole, b->ttype, hashheap),
BATDIR,
BBP_physical(b->batCacheid),
"thash");
- } else if (b->thash) {
+ } else if (hs) {
bat p = VIEWtparent(b);
BAT *hp = NULL;
if (p)
hp = BBP_cache(p);
- if ((!hp || b->thash != hp->thash) && b->thash != (Hash
*) -1) {
- ALGODEBUG if (*(size_t *) b->thash->heap->base
& (1 << 24))
+ if ((!hp || hs != hp->thash) && hs != (Hash *) -1) {
+ ALGODEBUG if (*(size_t *) hs->heap->base & (1
<< 24))
fprintf(stderr, "#HASHdestroy: removing
persisted hash %d\n", b->batCacheid);
- HEAPfree(b->thash->heap, 1);
- GDKfree(b->thash->heap);
- GDKfree(b->thash);
+ HEAPfree(hs->heap, 1);
+ GDKfree(hs->heap);
+ GDKfree(hs);
}
}
- b->thash = NULL;
}
}
diff --git a/gdk/gdk_orderidx.c b/gdk/gdk_orderidx.c
--- a/gdk/gdk_orderidx.c
+++ b/gdk/gdk_orderidx.c
@@ -13,44 +13,40 @@
#define ORDERIDX_VERSION ((oid) 3)
#ifdef PERSISTENTIDX
-struct idxsync {
- Heap *hp;
- bat id;
- const char *func;
-};
-
static void
BATidxsync(void *arg)
{
- struct idxsync *hs = arg;
- Heap *hp = hs->hp;
+ BAT *b = arg;
+ Heap *hp;
int fd;
lng t0 = 0;
ALGODEBUG t0 = GDKusec();
- if (HEAPsave(hp, hp->filename, NULL) != GDK_SUCCEED ||
- (fd = GDKfdlocate(hp->farmid, hp->filename, "rb+", NULL)) < 0) {
- BBPunfix(hs->id);
- GDKfree(arg);
- return;
- }
- ((oid *) hp->base)[0] |= (oid) 1 << 24;
- if (write(fd, hp->base, SIZEOF_SIZE_T) < 0)
- perror("write orderidx");
- if (!(GDKdebug & FORCEMITOMASK)) {
+ MT_lock_set(&GDKhashLock(b->batCacheid));
+ if ((hp = b->torderidx) != NULL) {
+ if (HEAPsave(hp, hp->filename, NULL) == GDK_SUCCEED &&
+ (fd = GDKfdlocate(hp->farmid, hp->filename, "rb+", NULL))
>= 0) {
+ ((oid *) hp->base)[0] |= (oid) 1 << 24;
+ if (write(fd, hp->base, SIZEOF_SIZE_T) >= 0) {
+ if (!(GDKdebug & FORCEMITOMASK)) {
#if defined(NATIVE_WIN32)
- _commit(fd);
+ _commit(fd);
#elif defined(HAVE_FDATASYNC)
- fdatasync(fd);
+ fdatasync(fd);
#elif defined(HAVE_FSYNC)
- fsync(fd);
+ fsync(fd);
#endif
+ }
+ } else {
+ perror("write orderidx");
+ }
+ close(fd);
+ }
+ ALGODEBUG fprintf(stderr, "#BATidxsync: persisting orderidx %s
(" LLFMT " usec)\n", hp->filename, GDKusec() - t0);
}
- close(fd);
- BBPunfix(hs->id);
- ALGODEBUG fprintf(stderr, "#%s: persisting orderidx %s (" LLFMT "
usec)\n", hs->func, hp->filename, GDKusec() - t0);
- GDKfree(arg);
+ MT_lock_unset(&GDKhashLock(b->batCacheid));
+ BBPunfix(b->batCacheid);
}
#endif
@@ -153,14 +149,9 @@ persistOIDX(BAT *b)
if ((BBP_status(b->batCacheid) & BBPEXISTING) &&
b->batInserted == b->batCount) {
MT_Id tid;
- struct idxsync *hs = GDKmalloc(sizeof(*hs));
- if (hs != NULL) {
- BBPfix(b->batCacheid);
- hs->id = b->batCacheid;
- hs->hp = b->torderidx;
- hs->func = "BATorderidx";
- MT_create_thread(&tid, BATidxsync, hs, MT_THR_DETACHED);
- }
+ BBPfix(b->batCacheid);
+ if (MT_create_thread(&tid, BATidxsync, b, MT_THR_DETACHED) < 0)
+ BBPunfix(b->batCacheid);
} else
ALGODEBUG fprintf(stderr, "#BATorderidx: NOT persisting index
%d\n", b->batCacheid);
#else
@@ -479,24 +470,19 @@ GDKmergeidx(BAT *b, BAT**a, int n_ar)
GDKfree(q);
}
+ b->torderidx = m;
#ifdef PERSISTENTIDX
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list