Changeset: 299d31cf61cf for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/299d31cf61cf
Modified Files:
        gdk/gdk_private.h
        sql/backends/monet5/sql.c
        sql/test/BugTracker-2022/Tests/All
Branch: default
Log Message:

Merge with Jan2022 branch.


diffs (truncated from 400 to 300 lines):

diff --git a/gdk/gdk_align.c b/gdk/gdk_align.c
--- a/gdk/gdk_align.c
+++ b/gdk/gdk_align.c
@@ -100,17 +100,15 @@ VIEWcreate(oid seq, BAT *b)
         * because in case of a mark, we are going to override a
         * column with a void. Take care to zero the accelerator data,
         * though. */
+       MT_lock_set(&b->theaplock);
        bn->batInserted = b->batInserted;
        bn->batCount = b->batCount;
        bn->batCapacity = b->batCapacity;
-       MT_lock_set(&b->theaplock);
        bn->T = b->T;
        tp = VIEWtparent(b);
        if (tp == 0 && b->ttype != TYPE_void)
                tp = b->batCacheid;
        assert(b->ttype != TYPE_void || !tp);
-       /* copy again now we have the correct lock */
-       bn->theap = b->theap;
        HEAPincref(b->theap);
        if (b->tvheap)
                HEAPincref(b->tvheap);
diff --git a/gdk/gdk_bbp.c b/gdk/gdk_bbp.c
--- a/gdk/gdk_bbp.c
+++ b/gdk/gdk_bbp.c
@@ -2830,7 +2830,6 @@ incref(bat i, bool logical, bool lock)
        int refs;
        bat tp = i, tvp = i;
        BAT *b, *pb = NULL, *pvb = NULL;
-       bool load = false;
 
        if (!BBPcheck(i))
                return 0;
@@ -2890,40 +2889,12 @@ incref(bat i, bool logical, bool lock)
        } else {
                assert(tp >= 0);
                refs = ++BBP_refs(i);
-               unsigned flag = BBPHOT;
-               if (refs == 1 && (tp != i || tvp != i)) {
-                       /* If this is a view, we must load the parent
-                        * BATs, but we must do that outside of the
-                        * lock.  Set the BBPLOADING flag so that
-                        * other threads will wait until we're
-                        * done. */
-                       flag |= BBPLOADING;
-                       load = true;
-               }
-               BBP_status_on(i, flag);
+               BBP_status_on(i, BBPHOT);
        }
        if (lock)
                MT_lock_unset(&GDKswapLock(i));
 
-       if (load) {
-               /* load the parent BATs */
-               assert(!logical);
-               if (tp != i) {
-                       assert(pb != NULL);
-                       /* load being set implies there is no other
-                        * thread that has access to this bat, but the
-                        * parent is a different matter */
-                       MT_lock_set(&pb->theaplock);
-                       if (b->theap != pb->theap) {
-                               HEAPincref(pb->theap);
-                               HEAPdecref(b->theap, false);
-                               b->theap = pb->theap;
-                       }
-                       MT_lock_unset(&pb->theaplock);
-               }
-               /* done loading, release descriptor */
-               BBP_status_off(i, BBPLOADING);
-       } else if (!logical) {
+       if (!logical && refs > 1) {
                /* this wasn't the first physical reference, so undo
                 * the fixes on the parent bats */
                if (pb)
@@ -3067,8 +3038,12 @@ decref(bat i, bool logical, bool release
              ? (!BATdirty(b) &&
                 !(BBP_status(i) & chkflag) &&
                 (BBP_status(i) & BBPPERSISTENT) &&
+                /* cannot unload in-memory data */
                 !GDKinmemory(farmid) &&
-                b->batSharecnt == 0)
+                /* do not unload views or parents of views */
+                b->batSharecnt == 0 &&
+                b->batCacheid == b->theap->parentid &&
+                (b->tvheap == NULL || b->batCacheid == b->tvheap->parentid))
              : (BBP_status(i) & BBPTMP)))) {
                /* bat will be unloaded now. set the UNLOADING bit
                 * while locked so no other thread thinks it's
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -647,9 +647,9 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
        b->twidth = width;
        if (cap > BATcapacity(b))
                BATsetcapacity(b, cap);
-       HEAPdecref(old, strcmp(old->filename, new->filename) != 0);
        b->theap = new;
        MT_lock_unset(&b->theaplock);
+       HEAPdecref(old, strcmp(old->filename, new->filename) != 0);
        return GDK_SUCCEED;
 }
 
diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h
--- a/gdk/gdk_private.h
+++ b/gdk/gdk_private.h
@@ -361,12 +361,13 @@ ilog2(BUN x)
 }
 
 /* some macros to help print info about BATs when using ALGODEBUG */
-#define ALGOBATFMT     "%s#" BUNFMT "@" OIDFMT "[%s]%s%s%s%s%s%s%s%s%s"
+#define ALGOBATFMT     "%s#" BUNFMT "@" OIDFMT "[%s%s]%s%s%s%s%s%s%s%s%s"
 #define ALGOBATPAR(b)                                                  \
        BATgetId(b),                                                    \
        BATcount(b),                                                    \
        b->hseqbase,                                                    \
        ATOMname(b->ttype),                                             \
+       
b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"", \
        !b->batTransient ? "P" : b->theap->parentid != b->batCacheid ? "V" : 
b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : "T", \
        BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : 
ATOMstorage(b->ttype) == TYPE_str && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "", \
        b->tsorted ? "S" : b->tnosorted ? "!s" : "",                    \
@@ -377,7 +378,7 @@ ilog2(BUN x)
        b->torderidx ? "O" : "",                                        \
        b->timprints ? "I" : b->theap->parentid && 
BBP_cache(b->theap->parentid)->timprints ? "(I)" : ""
 /* use ALGOOPTBAT* when BAT is optional (can be NULL) */
-#define ALGOOPTBATFMT  "%s%s" BUNFMT "%s" OIDFMT "%s%s%s%s%s%s%s%s%s%s%s%s"
+#define ALGOOPTBATFMT  "%s%s" BUNFMT "%s" OIDFMT "%s%s%s%s%s%s%s%s%s%s%s%s%s"
 #define ALGOOPTBATPAR(b)                                               \
        b ? BATgetId(b) : "",                                           \
        b ? "#" : "",                                                   \
@@ -386,6 +387,7 @@ ilog2(BUN x)
        b ? b->hseqbase : 0,                                            \
        b ? "[" : "",                                                   \
        b ? ATOMname(b->ttype) : "",                                    \
+       b ? 
b->ttype==TYPE_str?b->twidth==1?"1":b->twidth==2?"2":b->twidth==4?"4":"8":"" : 
"", \
        b ? "]" : "",                                                   \
        b ? !b->batTransient ? "P" : b->theap && b->theap->parentid != 
b->batCacheid ? "V" : b->tvheap && b->tvheap->parentid != b->batCacheid ? "v" : 
"T" : "", \
        b ? BATtdense(b) ? "D" : b->ttype == TYPE_void && b->tvheap ? "X" : 
ATOMstorage(b->ttype) == TYPE_str && GDK_ELIMDOUBLES(b->tvheap) ? "E" : "" : 
"", \
diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -4191,43 +4191,33 @@ BATSTRindex_int(bat *res, const bat *src
        if ((s = BATdescriptor(*src)) == NULL)
                throw(SQL, "calc.index", SQLSTATE(HY005) "Cannot access column 
descriptor");
 
-       if (*u) {
-               Heap *h = s->tvheap;
-               size_t pad, pos;
-               int v;
-
-               r = COLnew(0, TYPE_int, 1024, TRANSIENT);
-               if (r == NULL) {
+       (void) u;
+
+       Heap *h = s->tvheap;
+       size_t pad, pos;
+       int v;
+
+       r = COLnew(0, TYPE_int, 1024, TRANSIENT);
+       if (r == NULL) {
+               BBPunfix(s->batCacheid);
+               throw(SQL, "calc.index", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       }
+       pos = GDK_STRHASHSIZE;
+       while (pos < h->free) {
+               const char *p;
+
+               pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+               if (pad < sizeof(stridx_t))
+                       pad += GDK_VARALIGN;
+               pos += pad;
+               p = h->base + pos;
+               v = (int) (pos - GDK_STRHASHSIZE);
+               if (BUNappend(r, &v, false) != GDK_SUCCEED) {
+                       BBPreclaim(r);
                        BBPunfix(s->batCacheid);
                        throw(SQL, "calc.index", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
-               pos = GDK_STRHASHSIZE;
-               while (pos < h->free) {
-                       const char *p;
-
-                       pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
-                       if (pad < sizeof(stridx_t))
-                               pad += GDK_VARALIGN;
-                       pos += pad;
-                       p = h->base + pos;
-                       v = (int) (pos - GDK_STRHASHSIZE);
-                       if (BUNappend(r, &v, false) != GDK_SUCCEED) {
-                               BBPreclaim(r);
-                               BBPunfix(s->batCacheid);
-                               throw(SQL, "calc.index", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       }
-                       pos += strLen(p);
-               }
-       } else {
-               r = VIEWcreate(s->hseqbase, s);
-               if (r == NULL) {
-                       BBPunfix(s->batCacheid);
-                       throw(SQL, "calc.index", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               }
-               r->ttype = TYPE_int;
-               r->tvarsized = false;
-               HEAPdecref(r->tvheap, false);
-               r->tvheap = NULL;
+               pos += strLen(p);
        }
        BBPunfix(s->batCacheid);
        BBPkeepref((*res = r->batCacheid));
@@ -4250,42 +4240,32 @@ BATSTRindex_sht(bat *res, const bat *src
        if ((s = BATdescriptor(*src)) == NULL)
                throw(SQL, "calc.index", SQLSTATE(HY005) "Cannot access column 
descriptor");
 
-       if (*u) {
-               Heap *h = s->tvheap;
-               size_t pad, pos;
-               sht v;
-
-               r = COLnew(0, TYPE_sht, 1024, TRANSIENT);
-               if (r == NULL) {
-                       BBPunfix(s->batCacheid);
+       (void) u;
+
+       Heap *h = s->tvheap;
+       size_t pad, pos;
+       sht v;
+
+       r = COLnew(0, TYPE_sht, 1024, TRANSIENT);
+       if (r == NULL) {
+               BBPunfix(s->batCacheid);
+               throw(SQL, "calc.index", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       }
+       pos = GDK_STRHASHSIZE;
+       while (pos < h->free) {
+               const char *s;
+
+               pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
+               if (pad < sizeof(stridx_t))
+                       pad += GDK_VARALIGN;
+               pos += pad;
+               s = h->base + pos;
+               v = (sht) (pos - GDK_STRHASHSIZE);
+               if (BUNappend(r, &v, false) != GDK_SUCCEED) {
+                       BBPreclaim(r);
                        throw(SQL, "calc.index", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
                }
-               pos = GDK_STRHASHSIZE;
-               while (pos < h->free) {
-                       const char *s;
-
-                       pad = GDK_VARALIGN - (pos & (GDK_VARALIGN - 1));
-                       if (pad < sizeof(stridx_t))
-                               pad += GDK_VARALIGN;
-                       pos += pad;
-                       s = h->base + pos;
-                       v = (sht) (pos - GDK_STRHASHSIZE);
-                       if (BUNappend(r, &v, false) != GDK_SUCCEED) {
-                               BBPreclaim(r);
-                               throw(SQL, "calc.index", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-                       }
-                       pos += strLen(s);
-               }
-       } else {
-               r = VIEWcreate(s->hseqbase, s);
-               if (r == NULL) {
-                       BBPunfix(s->batCacheid);
-                       throw(SQL, "calc.index", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
-               }
-               r->ttype = TYPE_sht;
-               r->tvarsized = false;
-               HEAPdecref(r->tvheap, false);
-               r->tvheap = NULL;
+               pos += strLen(s);
        }
        BBPunfix(s->batCacheid);
        BBPkeepref((*res = r->batCacheid));
@@ -4308,43 +4288,33 @@ BATSTRindex_bte(bat *res, const bat *src
        if ((s = BATdescriptor(*src)) == NULL)
                throw(SQL, "calc.index", SQLSTATE(HY005) "Cannot access column 
descriptor");
 
-       if (*u) {
-               Heap *h = s->tvheap;
-               size_t pad, pos;
-               bte v;
-
-               r = COLnew(0, TYPE_bte, 64, TRANSIENT);
-               if (r == NULL) {
+       (void) u;
+
+       Heap *h = s->tvheap;
+       size_t pad, pos;
+       bte v;
+
+       r = COLnew(0, TYPE_bte, 64, TRANSIENT);
+       if (r == NULL) {
+               BBPunfix(s->batCacheid);
+               throw(SQL, "calc.index", SQLSTATE(HY013) MAL_MALLOC_FAIL);
+       }
+       pos = GDK_STRHASHSIZE;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to