Changeset: 9be7fa5d2693 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9be7fa5d2693
Modified Files:
gdk/gdk_aggr.c
gdk/gdk_bat.c
gdk/gdk_batop.c
gdk/gdk_bbp.c
gdk/gdk_group.c
gdk/gdk_imprints.c
gdk/gdk_join.c
gdk/gdk_private.h
gdk/gdk_select.c
gdk/gdk_strimps.c
monetdb5/mal/mal_profiler.c
monetdb5/modules/mal/remote.c
sql/backends/monet5/sql.c
sql/backends/monet5/sql_cat.c
sql/backends/monet5/sql_orderidx.c
sql/backends/monet5/sql_statistics.c
sql/storage/bat/bat_storage.c
Branch: default
Log Message:
Instead of "stealing" the parent BAT reference, fix/unfix the parent BAT.
diffs (truncated from 1378 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
@@ -3605,8 +3605,9 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
res = BUNtail(bi, bi.minpos);
} else {
oid pos;
- BAT *pb = NULL;
+ BAT *pb = BATdescriptor(VIEWtparent(b));
Heap *oidxh = NULL;
+ bool usepoidx = false;
if (BATcheckorderidx(b)) {
MT_lock_set(&b->batIdxLock);
@@ -3616,8 +3617,7 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
MT_lock_unset(&b->batIdxLock);
}
if (oidxh == NULL &&
- VIEWtparent(b) &&
- (pb = BBP_cache(VIEWtparent(b))) != NULL &&
+ pb != NULL &&
BATcheckorderidx(pb)) {
/* no lock on b needed since it's a view */
MT_lock_set(&pb->batIdxLock);
@@ -3627,6 +3627,7 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
pb->hseqbase == b->hseqbase &&
(oidxh = pb->torderidx) != NULL) {
HEAPincref(oidxh);
+ usepoidx = true;
}
MT_lock_unset(&pb->batIdxLock);
MT_lock_unset(&pb->theaplock);
@@ -3635,7 +3636,7 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
const oid *ords = (const oid *) oidxh->base +
ORDERIDXOFF;
BUN r;
if (!bi.nonil) {
- MT_thread_setalgorithm(pb ? "binsearch on
parent oidx" : "binsearch on oidx");
+ MT_thread_setalgorithm(usepoidx ? "binsearch on
parent oidx" : "binsearch on oidx");
r = binsearch(ords, 0, bi.type, bi.base,
bi.vh ? bi.vh->base : NULL,
bi.width, 0, bi.count,
@@ -3656,17 +3657,15 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
/* no non-nil values */
pos = oid_nil;
} else {
- MT_thread_setalgorithm(pb ? "using parent oidx"
: "using oidx");
+ MT_thread_setalgorithm(usepoidx ? "using parent
oidx" : "using oidx");
pos = ords[r];
}
HEAPdecref(oidxh, false);
} else {
Imprints *imprints = NULL;
- if ((VIEWtparent(b) == 0 ||
- bi.count == BATcount(BBP_cache(VIEWtparent(b)))) &&
+ if ((pb == NULL || bi.count == BATcount(pb)) &&
BATcheckimprints(b)) {
- if (VIEWtparent(b)) {
- BAT *pb = BBP_cache(VIEWtparent(b));
+ if (pb != NULL) {
MT_lock_set(&pb->batIdxLock);
imprints = pb->timprints;
if (imprints != NULL)
@@ -3712,10 +3711,8 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
MT_lock_set(&b->theaplock);
if (bi.count == BATcount(b) && bi.h == b->theap)
b->tminpos = bi.minpos;
- bat pbid = VIEWtparent(b);
MT_lock_unset(&b->theaplock);
- if (pbid) {
- BAT *pb = BBP_cache(pbid);
+ if (pb) {
MT_lock_set(&pb->theaplock);
if (bi.count == BATcount(pb) &&
bi.h == pb->theap)
@@ -3723,6 +3720,8 @@ BATmin_skipnil(BAT *b, void *aggr, bit s
MT_lock_unset(&pb->theaplock);
}
}
+ if (pb)
+ BBPunfix(pb->batCacheid);
}
if (aggr == NULL) {
s = ATOMlen(bi.type, res);
@@ -3756,24 +3755,26 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
{
const void *res = NULL;
size_t s;
- BATiter bi;
lng t0 = 0;
TRC_DEBUG_IF(ALGO) t0 = GDKusec();
if (!ATOMlinear(b->ttype)) {
+ /* there is no such thing as a largest value if you
+ * can't compare values */
GDKerror("non-linear type");
return NULL;
}
- bi = bat_iterator(b);
+ BATiter bi = bat_iterator(b);
if (bi.count == 0) {
res = ATOMnilptr(bi.type);
} else if (bi.maxpos != BUN_NONE) {
res = BUNtail(bi, bi.maxpos);
} else {
oid pos;
- BAT *pb = NULL;
+ BAT *pb = BATdescriptor(VIEWtparent(b));
Heap *oidxh = NULL;
+ bool usepoidx = false;
if (BATcheckorderidx(b)) {
MT_lock_set(&b->batIdxLock);
@@ -3783,8 +3784,7 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
MT_lock_unset(&b->batIdxLock);
}
if (oidxh == NULL &&
- VIEWtparent(b) &&
- (pb = BBP_cache(VIEWtparent(b))) != NULL &&
+ pb != NULL &&
BATcheckorderidx(pb)) {
/* no lock on b needed since it's a view */
MT_lock_set(&pb->batIdxLock);
@@ -3794,6 +3794,7 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
pb->hseqbase == b->hseqbase &&
(oidxh = pb->torderidx) != NULL) {
HEAPincref(oidxh);
+ usepoidx = true;
}
MT_lock_unset(&pb->batIdxLock);
MT_lock_unset(&pb->theaplock);
@@ -3801,7 +3802,7 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
if (oidxh != NULL) {
const oid *ords = (const oid *) oidxh->base +
ORDERIDXOFF;
- MT_thread_setalgorithm(pb ? "using parent oidx" :
"using oids");
+ MT_thread_setalgorithm(usepoidx ? "using parent oidx" :
"using oids");
pos = ords[bi.count - 1];
/* nils are first, ie !skipnil, check for nils */
if (!skipnil) {
@@ -3815,11 +3816,9 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
HEAPdecref(oidxh, false);
} else {
Imprints *imprints = NULL;
- if ((VIEWtparent(b) == 0 ||
- BATcount(b) ==
BATcount(BBP_cache(VIEWtparent(b)))) &&
+ if ((pb == NULL || bi.count == BATcount(pb)) &&
BATcheckimprints(b)) {
- if (VIEWtparent(b)) {
- BAT *pb = BBP_cache(VIEWtparent(b));
+ if (pb != NULL) {
MT_lock_set(&pb->batIdxLock);
imprints = pb->timprints;
if (imprints != NULL)
@@ -3865,15 +3864,17 @@ BATmax_skipnil(BAT *b, void *aggr, bit s
MT_lock_set(&b->theaplock);
if (bi.count == BATcount(b) && bi.h == b->theap)
b->tmaxpos = bi.maxpos;
- bat pbid = VIEWtparent(b);
- if (pbid) {
- BAT *pb = BBP_cache(pbid);
+ MT_lock_unset(&b->theaplock);
+ if (pb) {
+ MT_lock_set(&pb->theaplock);
if (bi.count == BATcount(pb) &&
bi.h == pb->theap)
pb->tmaxpos = bi.maxpos;
+ MT_lock_unset(&pb->theaplock);
}
- MT_lock_unset(&b->theaplock);
}
+ if (pb)
+ BBPunfix(pb->batCacheid);
}
if (aggr == NULL) {
s = ATOMlen(bi.type, res);
@@ -4151,19 +4152,21 @@ doBATgroupquantile(BAT *b, BAT *g, BAT *
}
if (oidxh == NULL &&
VIEWtparent(b) &&
- (pb = BBP_cache(VIEWtparent(b))) != NULL &&
- BATcheckorderidx(pb)) {
- /* no lock on b needed since it's a view */
- MT_lock_set(&pb->batIdxLock);
- MT_lock_set(&pb->theaplock);
- if (pb->tbaseoff == b->tbaseoff &&
- BATcount(pb) == BATcount(b) &&
- pb->hseqbase == b->hseqbase &&
- (oidxh = pb->torderidx) != NULL) {
- HEAPincref(oidxh);
+ (pb = BATdescriptor(VIEWtparent(b))) != NULL) {
+ if (BATcheckorderidx(pb)) {
+ /* no lock on b needed since it's a view */
+ MT_lock_set(&pb->batIdxLock);
+ MT_lock_set(&pb->theaplock);
+ if (pb->tbaseoff == b->tbaseoff &&
+ BATcount(pb) == BATcount(b) &&
+ pb->hseqbase == b->hseqbase &&
+ (oidxh = pb->torderidx) != NULL) {
+ HEAPincref(oidxh);
+ }
+ MT_lock_unset(&pb->batIdxLock);
+ MT_lock_unset(&pb->theaplock);
}
- MT_lock_unset(&pb->batIdxLock);
- MT_lock_unset(&pb->theaplock);
+ BBPunfix(pb->batCacheid);
}
if (oidxh != NULL) {
MT_thread_setalgorithm(pb ? "using parent oidx" :
"using oids");
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -805,7 +805,7 @@ COLcopy(BAT *b, int tt, bool writable, r
bi.restricted == BAT_READ &&
ATOMstorage(b->ttype) != TYPE_msk && /* no view on TYPE_msk */
(!VIEWtparent(b) ||
- BBP_cache(VIEWtparent(b))->batRestricted == BAT_READ)) {
+ BBP_desc(VIEWtparent(b))->batRestricted == BAT_READ)) {
bn = VIEWcreate(b->hseqbase, b);
if (bn == NULL) {
bat_iterator_end(&bi);
@@ -829,12 +829,12 @@ COLcopy(BAT *b, int tt, bool writable, r
/* oops, we need to fix/unfix atoms */
slowcopy = true;
} else if (bi.h && bi.h->parentid != b->batCacheid &&
- BATcapacity(BBP_cache(bi.h->parentid)) > bi.count +
bi.count) {
+ BATcapacity(BBP_desc(bi.h->parentid)) > bi.count +
bi.count) {
/* reduced slice view: do not copy too much
* garbage */
slowcopy = true;
} else if (bi.vh && bi.vh->parentid != b->batCacheid &&
- BATcount(BBP_cache(bi.vh->parentid)) > bi.count +
bi.count) {
+ BATcount(BBP_desc(bi.vh->parentid)) > bi.count +
bi.count) {
/* reduced vheap view: do not copy too much
* garbage; this really is a heuristic since the
* vheap could be used completely, even if the
@@ -1994,15 +1994,18 @@ BATkey(BAT *b, bool flag)
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));
- MT_lock_set(&bp->theaplock);
- if (BATcount(b) == BATcount(bp) &&
- ATOMtype(BATttype(b)) == ATOMtype(BATttype(bp)) &&
- !BATtkey(bp) &&
- ((BATtvoid(b) && BATtvoid(bp) && b->tseqbase ==
bp->tseqbase) ||
- BATcount(b) == 0))
- rc = BATkey(bp, true);
- MT_lock_unset(&bp->theaplock);
+ BAT *bp = BATdescriptor(VIEWtparent(b));
+ if (bp != NULL) {
+ MT_lock_set(&bp->theaplock);
+ if (BATcount(b) == BATcount(bp) &&
+ ATOMtype(BATttype(b)) == ATOMtype(BATttype(bp)) &&
+ !BATtkey(bp) &&
+ ((BATtvoid(b) && BATtvoid(bp) && b->tseqbase ==
bp->tseqbase) ||
+ BATcount(b) == 0))
+ rc = BATkey(bp, true);
+ MT_lock_unset(&bp->theaplock);
+ BBPunfix(bp->batCacheid);
+ }
}
return rc;
}
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -1801,7 +1801,7 @@ BATslice(BAT *b, BUN l, BUN h)
}
restrict_t prestricted;
if (bi.restricted == BAT_READ && VIEWtparent(b)) {
- BAT *pb = BBP_cache(VIEWtparent(b));
+ BAT *pb = BBP_desc(VIEWtparent(b));
MT_lock_set(&pb->theaplock);
prestricted = pb->batRestricted;
MT_lock_unset(&pb->theaplock);
@@ -2359,12 +2359,15 @@ BATsort(BAT **sorted, BAT **order, BAT *
return GDK_SUCCEED;
}
if (VIEWtparent(b)) {
- pb = BBP_cache(VIEWtparent(b));
- if (b->tbaseoff != pb->tbaseoff ||
- BATcount(b) != BATcount(pb) ||
- b->hseqbase != pb->hseqbase ||
- BATatoms[b->ttype].atomCmp != BATatoms[pb->ttype].atomCmp)
+ pb = BATdescriptor(VIEWtparent(b));
+ if (pb != NULL &&
+ (b->tbaseoff != pb->tbaseoff ||
+ BATcount(b) != BATcount(pb) ||
+ b->hseqbase != pb->hseqbase ||
+ BATatoms[b->ttype].atomCmp !=
BATatoms[pb->ttype].atomCmp)) {
+ BBPunfix(pb->batCacheid);
pb = NULL;
+ }
} else {
pb = b;
}
@@ -2448,6 +2451,8 @@ BATsort(BAT **sorted, BAT **order, BAT *
ALGOOPTBATPAR(g), reverse, nilslast, stable,
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]