Changeset: 0c519cdceb53 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/0c519cdceb53
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_result.c
        sql/storage/bat/bat_logger.c
        testing/sqllogictest.py
        testing/sqltest.py
        tools/monetdbe/monetdbe.c
Branch: nested
Log Message:

Merge with default branch.


diffs (truncated from 1664 to 300 lines):

diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
 # ChangeLog file for devel
 # This file is updated with Maddlog
 
+* Thu Feb 19 2026 Sjoerd Mullender <[email protected]>
+- Changed the BATloop macro so that it now has a BATiter pointer as
+  first argument.
+
diff --git a/clients/Tests/exports.py b/clients/Tests/exports.py
--- a/clients/Tests/exports.py
+++ b/clients/Tests/exports.py
@@ -4,5 +4,6 @@ import MonetDBtesting.listexports
 with open('exports.stable.out') as fil:
     stable = fil.readlines()
 output = MonetDBtesting.listexports.listexports()
-for line in difflib.unified_diff(stable, output):
+for line in difflib.unified_diff(stable, output,
+                                 fromfile='expected', tofile='received'):
     sys.stderr.write(line)
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -247,8 +247,6 @@ typedef size_t BUN;
 #endif
 #define BUN_MAX (BUN_NONE - 1) /* maximum allowed size of a BAT */
 
-#define ATOMextern(t)  (ATOMstorage(t) >= TYPE_str)
-
 typedef enum {
        PERSISTENT = 0,
        TRANSIENT,
@@ -1221,15 +1219,18 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
        assert(b->theap->parentid == b->batCacheid);
        MT_lock_set(&b->theaplock);
        rc = ATOMputVAR(b, &d, v);
-       MT_lock_unset(&b->theaplock);
-       if (rc != GDK_SUCCEED)
+       if (rc != GDK_SUCCEED) {
+               MT_lock_unset(&b->theaplock);
                return rc;
+       }
        if (b->twidth < SIZEOF_VAR_T &&
            (b->twidth <= 2 ? d - GDK_VAROFFSET : d) >= ((size_t) 1 << (8 << 
b->tshift))) {
                /* doesn't fit in current heap, upgrade it */
                rc = GDKupgradevarheap(b, d, 0, MAX(p, b->batCount));
-               if (rc != GDK_SUCCEED)
+               if (rc != GDK_SUCCEED) {
+                       MT_lock_unset(&b->theaplock);
                        return rc;
+               }
        }
        switch (b->twidth) {
        case 1:
@@ -1249,6 +1250,7 @@ tfastins_nocheckVAR(BAT *b, BUN p, const
        default:
                MT_UNREACHABLE();
        }
+       MT_lock_unset(&b->theaplock);
        return GDK_SUCCEED;
 }
 
@@ -1500,8 +1502,8 @@ gdk_export void VIEWbounds(BAT *b, BAT *
                }                                                       \
        } while (false)
 
-#define BATloop(r, p, q)                               \
-       for (q = BATcount(r), p = 0; p < q; p++)
+#define BATloop(bi, p, q)                              \
+       for (q = (bi)->count, p = 0; p < q; p++)
 
 enum prop_t {
        GDK_MIN_BOUND, /* MINimum allowed value for range partitions [min, max> 
*/
diff --git a/gdk/gdk_atoms.c b/gdk/gdk_atoms.c
--- a/gdk/gdk_atoms.c
+++ b/gdk/gdk_atoms.c
@@ -299,14 +299,14 @@ ATOMname(int t)
 bool
 ATOMisdescendant(int tpe, int parent)
 {
-       int cur = -1;
+       int cur;
 
-       while (cur != tpe) {
+       do {
+               if (tpe == parent)
+                       return true;
                cur = tpe;
-               if (cur == parent)
-                       return true;
                tpe = ATOMstorage(tpe);
-       }
+       } while (cur != tpe);
        return false;
 }
 
diff --git a/gdk/gdk_atoms.h b/gdk/gdk_atoms.h
--- a/gdk/gdk_atoms.h
+++ b/gdk/gdk_atoms.h
@@ -278,6 +278,7 @@ gdk_export const inet6 inet6_nil;
 #define ATOMvarsized(t)                (BATatoms[t].atomPut != NULL)
 #define ATOMlinear(t)          BATatoms[t].linear
 #define ATOMtype(t)            ((t) == TYPE_void ? TYPE_oid : (t))
+#define ATOMextern(t)          (ATOMstorage(t) >= TYPE_str)
 
 /* The base type is the storage type if the comparison function, the
  * hash function, and the nil value are the same as those of the
diff --git a/gdk/gdk_bat.c b/gdk/gdk_bat.c
--- a/gdk/gdk_bat.c
+++ b/gdk/gdk_bat.c
@@ -1628,15 +1628,16 @@ BUNinplacemulti(BAT *b, const oid *posit
                                MT_rwlock_wrunlock(&b->thashlock);
                                goto bailout;
                        }
-                       MT_lock_unset(&b->theaplock);
                        if (b->twidth < SIZEOF_VAR_T &&
                            (b->twidth <= 2 ? _d - GDK_VAROFFSET : _d) >= 
((size_t) 1 << (8 << b->tshift))) {
                                /* doesn't fit in current heap, upgrade it */
                                if (GDKupgradevarheap(b, _d, 0, bi.count) != 
GDK_SUCCEED) {
+                                       MT_lock_unset(&b->theaplock);
                                        MT_rwlock_wrunlock(&b->thashlock);
                                        goto bailout;
                                }
                        }
+                       MT_lock_unset(&b->theaplock);
                        /* reinitialize iterator after possible heap upgrade */
                        {
                                /* save and restore minpos/maxpos */
@@ -1837,7 +1838,7 @@ slowfnd(BAT *b, const void *v)
        BUN p, q;
        bool (*atomeq)(const void *, const void *) = ATOMequal(bi.type);
 
-       BATloop(b, p, q) {
+       BATloop(&bi, p, q) {
                if ((*atomeq)(v, BUNtail(&bi, p))) {
                        bat_iterator_end(&bi);
                        return p;
@@ -2857,7 +2858,7 @@ BATassertProps(BAT *b)
                        /* only call compare function if we have to */
                        bool cmpprv = b->tsorted | b->trevsorted | b->tkey;
 
-                       BATloop(b, p, q) {
+                       BATloop(&bi, p, q) {
                                valp = BUNtail(&bi, p);
                                bool isnil = eqf(valp, nilp);
                                assert(!isnil || !notnull);
@@ -2938,7 +2939,7 @@ BATassertProps(BAT *b)
                                TRC_WARNING(BAT, "Cannot allocate hash 
table\n");
                                goto abort_check;
                        }
-                       BATloop(b, p, q) {
+                       BATloop(&bi, p, q) {
                                BUN hb;
                                BUN prb;
                                valp = BUNtail(&bi, p);
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -232,9 +232,12 @@ insert_string_bat(BAT *b, BATiter *ni, s
 
        /* make sure there is (vertical) space in the offset heap, we
         * may also widen thanks to v, set above */
+       MT_lock_set(&b->theaplock);
        if (GDKupgradevarheap(b, v, oldcnt + cnt < b->batCapacity ? 
b->batCapacity : oldcnt + cnt, b->batCount) != GDK_SUCCEED) {
+               MT_lock_unset(&b->theaplock);
                return GDK_FAIL;
        }
+       MT_lock_unset(&b->theaplock);
 
        if (toff == 0 && ni->width == b->twidth && ci->tpe == cand_dense) {
                /* we don't need to do any translation of offset
@@ -1511,14 +1514,15 @@ BATappend_or_update(BAT *b, BAT *p, cons
                                prevnew = new;
                                prevoff = d;
                        }
-                       MT_lock_unset(&b->theaplock);
                        if (rc != GDK_SUCCEED) {
+                               MT_lock_unset(&b->theaplock);
                                goto bailout;
                        }
                        if (b->twidth < SIZEOF_VAR_T &&
                            (b->twidth <= 2 ? d - GDK_VAROFFSET : d) >= 
((size_t) 1 << (8 << b->tshift))) {
                                /* doesn't fit in current heap, upgrade it */
                                if (GDKupgradevarheap(b, d, 0, MAX(updid, 
b->batCount)) != GDK_SUCCEED) {
+                                       MT_lock_unset(&b->theaplock);
                                        goto bailout;
                                }
                        }
@@ -1533,6 +1537,7 @@ BATappend_or_update(BAT *b, BAT *p, cons
                                bi.minpos = minpos;
                                bi.maxpos = maxpos;
                        }
+                       MT_lock_unset(&b->theaplock);
                        switch (b->twidth) {
                        case 1:
                                ((uint8_t *) b->theap->base)[updid] = (uint8_t) 
(d - GDK_VAROFFSET);
@@ -3231,6 +3236,16 @@ BATcount_no_nil(BAT *b, BAT *s)
                bat_iterator_end(&bi);
                return ci.ncand;
        }
+       if (BATcheckhash(b)) {
+               BUN p = 0;
+               const void *nil = ATOMnilptr(b->ttype);
+               cnt = ci.ncand;
+               HASHloop(&bi, b->thash, p, nil)
+                       if (canditer_contains(&ci, p + b->hseqbase))
+                               cnt--;
+               bat_iterator_end(&bi);
+               return cnt;
+       }
        p = bi.base;
        t = ATOMbasetype(bi.type);
        switch (t) {
@@ -3283,6 +3298,38 @@ BATcount_no_nil(BAT *b, BAT *s)
                        cnt += !is_inet6_nil(((const inet6 *) 
p)[canditer_next(&ci) - hseq]);
                break;
        case TYPE_str:
+               if (GDK_ELIMDOUBLES(bi.vh)) {
+                       var_t off = strLocate(bi.vh, str_nil);
+                       if (off == (var_t) -2) {
+                               cnt = ci.ncand;
+                               break;
+                       }
+                       switch (bi.width) {
+                       case 1:
+                               off -= GDK_VAROFFSET;
+                               CAND_LOOP(&ci)
+                                       cnt += (var_t) ((const uint8_t *) 
p)[canditer_next(&ci) - hseq] != off;
+                               break;
+                       case 2:
+                               off -= GDK_VAROFFSET;
+                               CAND_LOOP(&ci)
+                                       cnt += (var_t) ((const uint16_t *) 
p)[canditer_next(&ci) - hseq] != off;
+                               break;
+                       case 4:
+                               CAND_LOOP(&ci)
+                                       cnt += (var_t) ((const uint32_t *) 
p)[canditer_next(&ci) - hseq] != off;
+                               break;
+#if SIZEOF_VAR_T == 8
+                       case 8:
+                               CAND_LOOP(&ci)
+                                       cnt += (var_t) ((const uint64_t *) 
p)[canditer_next(&ci) - hseq] != off;
+                               break;
+#endif
+                       default:
+                               MT_UNREACHABLE();
+                       }
+                       break;
+               }
                base = bi.vh->base;
                switch (bi.width) {
                case 1:
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -437,7 +437,9 @@ HEAPextend(Heap *h, size_t size, bool ma
 
 /* grow the string offset heap so that the value v fits (i.e. wide
  * enough to fit the value), and it has space for at least cap elements;
- * copy ncopy BUNs, or up to the heap size, whichever is smaller */
+ * copy ncopy BUNs, or up to the heap size, whichever is smaller
+ *
+ * this function should be called with theaplock held */
 gdk_return
 GDKupgradevarheap(BAT *b, var_t v, BUN cap, BUN ncopy)
 {
@@ -478,7 +480,11 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
                                BATsetcapacity(b, cap);
                        return GDK_SUCCEED;
                }
-               return BATextend(b, newsize >> shift);
+               if (HEAPgrow(&b->theap, newsize,
+                            b->batRestricted == BAT_READ) != GDK_SUCCEED)
+                       return GDK_FAIL;
+               b->batCapacity = newsize >> shift;
+               return GDK_SUCCEED;
        }
 
        n = MIN(ncopy, old->size >> b->tshift);
@@ -573,7 +579,6 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
        default:
                MT_UNREACHABLE();
        }
-       MT_lock_set(&b->theaplock);
        b->tshift = shift;
        b->twidth = width;
        if (cap > BATcapacity(b))
@@ -590,7 +595,6 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
                ValPtr p = BATgetprop_nolock(b, (enum prop_t) 20);
                HEAPdecref(old, p == NULL || strcmp(((Heap*) 
p->val.pval)->filename, old->filename) != 0);
        }
-       MT_lock_unset(&b->theaplock);
        return GDK_SUCCEED;
 }
 
diff --git a/gdk/gdk_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to