Changeset: 870192670926 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/870192670926
Branch: Jul2021
Log Message:

Merge heads


diffs (truncated from 3493 to 300 lines):

diff --git a/clients/odbc/driver/SQLSpecialColumns.c 
b/clients/odbc/driver/SQLSpecialColumns.c
--- a/clients/odbc/driver/SQLSpecialColumns.c
+++ b/clients/odbc/driver/SQLSpecialColumns.c
@@ -221,7 +221,7 @@ MNDBSpecialColumns(ODBCStmt *stmt,
                              "sys.tables t, "
                              "sys.columns c, "
                              "sys.keys k, "
-                             "sys.objects kc"
+                             "sys.objects kc "
                         "where s.id = t.schema_id and "
                               "t.id = c.table_id and "
                               "t.id = k.table_id and "
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -398,6 +398,7 @@ insert_string_bat(BAT *b, BAT *n, struct
                        r++;
                }
        }
+       assert(b->batCapacity >= b->batCount);
        b->theap->dirty = true;
        /* maintain hash */
        for (r = oldcnt, cnt = BATcount(b); b->thash && r < cnt; r++) {
@@ -1293,10 +1294,12 @@ BATreplace(BAT *b, BAT *p, BAT *n, bool 
                 * there are no nils in b afterward if there weren't
                 * any in either b or n to begin with */
                b->tnonil &= n->tnonil;
-               if (b->thash != NULL && b->thash != (Hash *) 1) {
-                       for (BUN i = updid, j = updid + BATcount(p); i < j; i++)
-                               HASHdelete(b, i, Tloc(b, i));
-               }
+               /* if there is no hash, we don't start the loop, if
+                * there is only a persisted hash, it will get destroyed
+                * in the first iteration, after which there is no hash
+                * and the loop ends */
+               for (BUN i = updid, j = updid + BATcount(p); i < j && b->thash; 
i++)
+                       HASHdelete(b, i, Tloc(b, i));
                if (n->ttype == TYPE_void) {
                        assert(b->ttype == TYPE_oid);
                        oid *o = Tloc(b, updid);
@@ -1365,7 +1368,11 @@ BATreplace(BAT *b, BAT *p, BAT *n, bool 
                        memcpy(Tloc(b, updid), Tloc(n, 0),
                               BATcount(p) * b->twidth);
                }
-               if (b->thash != NULL && b->thash != (Hash *) 1) {
+               /* either we have a hash that was updated above, or we
+                * have no hash; we cannot have the case where there is
+                * only a persisted (unloaded) hash since it would have
+                * been destroyed above */
+               if (b->thash != NULL) {
                        for (BUN i = updid, j = updid + BATcount(p); i < j; i++)
                                HASHinsert(b, i, Tloc(b, i));
                }
diff --git a/gdk/gdk_heap.c b/gdk/gdk_heap.c
--- a/gdk/gdk_heap.c
+++ b/gdk/gdk_heap.c
@@ -435,6 +435,8 @@ GDKupgradevarheap(BAT *b, var_t v, BUN c
        if (b->twidth == width) {
                if (newsize <= old->size) {
                        /* nothing to do */
+                       if (cap > b->batCapacity)
+                               BATsetcapacity(b, cap);
                        return GDK_SUCCEED;
                }
                return BATextend(b, newsize >> shift);
diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c
--- a/gdk/gdk_join.c
+++ b/gdk/gdk_join.c
@@ -3931,13 +3931,15 @@ BATjoin(BAT **r1p, BAT **r2p, BAT *l, BA
        if ((parent = VIEWtparent(l)) != 0) {
                BAT *b = BBPdescriptor(parent);
                if (l->hseqbase == b->hseqbase &&
-                   BATcount(l) == BATcount(b))
+                   BATcount(l) == BATcount(b) &&
+                   ATOMtype(l->ttype) == ATOMtype(b->ttype))
                        l = b;
        }
        if ((parent = VIEWtparent(r)) != 0) {
                BAT *b = BBPdescriptor(parent);
                if (r->hseqbase == b->hseqbase &&
-                   BATcount(r) == BATcount(b))
+                   BATcount(r) == BATcount(b) &&
+                   ATOMtype(r->ttype) == ATOMtype(b->ttype))
                        r = b;
        }
 
diff --git a/gdk/gdk_storage.c b/gdk/gdk_storage.c
--- a/gdk/gdk_storage.c
+++ b/gdk/gdk_storage.c
@@ -761,22 +761,19 @@ BATsave(BAT *bd)
 {
        gdk_return err = GDK_SUCCEED;
        const char *nme;
-       BAT bs;
-       Heap hs, vhs;
-       BAT *b = bd;
-       bool dosync = (BBP_status(b->batCacheid) & BBPPERSISTENT) != 0;
+       bool dosync = (BBP_status(bd->batCacheid) & BBPPERSISTENT) != 0;
 
-       assert(!GDKinmemory(b->theap->farmid));
-       BATcheck(b, GDK_FAIL);
+       assert(!GDKinmemory(bd->theap->farmid));
+       BATcheck(bd, GDK_FAIL);
 
-       assert(b->batCacheid > 0);
+       assert(bd->batCacheid > 0);
        /* views cannot be saved, but make an exception for
         * force-remapped views */
-       if (isVIEW(b)) {
-               GDKerror("%s is a view on %s; cannot be saved\n", BATgetId(b), 
BBPname(VIEWtparent(b)));
+       if (isVIEW(bd)) {
+               GDKerror("%s is a view on %s; cannot be saved\n", BATgetId(bd), 
BBPname(VIEWtparent(bd)));
                return GDK_FAIL;
        }
-       if (!BATdirty(b)) {
+       if (!BATdirty(bd)) {
                return GDK_SUCCEED;
        }
 
@@ -784,11 +781,13 @@ BATsave(BAT *bd)
         * messing in the BAT descriptor not affect other threads that
         * only read it. */
        MT_lock_set(&bd->theaplock);
-       bs = *b;
-       b = &bs;
-       hs = *bd->theap;
+       MT_rwlock_rdlock(&bd->thashlock);
+       BAT bs = *bd;
+       BAT *b = &bs;
+       Heap hs = *bd->theap;
        HEAPincref(&hs);
        b->theap = &hs;
+       Heap vhs;
        if (b->tvheap) {
                vhs = *bd->tvheap;
                HEAPincref(&vhs);
@@ -806,8 +805,6 @@ BATsave(BAT *bd)
            && b->tvarsized
            && err == GDK_SUCCEED)
                err = HEAPsave(b->tvheap, nme, "theap", dosync);
-       if (b->thash && b->thash != (Hash *) 1)
-               BAThashsave(b, dosync);
 
        HEAPdecref(b->theap, false);
        if (b->tvheap)
@@ -815,9 +812,10 @@ BATsave(BAT *bd)
        if (err == GDK_SUCCEED) {
                bd->batCopiedtodisk = true;
                DESCclean(bd);
-               MT_lock_unset(&bd->theaplock);
-               return GDK_SUCCEED;
+               if (b->thash && b->thash != (Hash *) 1)
+                       BAThashsave(b, dosync);
        }
+       MT_rwlock_rdunlock(&bd->thashlock);
        MT_lock_unset(&bd->theaplock);
        return err;
 }
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -1268,7 +1268,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                else if (!list_empty(exps)) {
                        unsigned nrcols = 0;
 
-                       if (strcmp(sql_func_mod(f->func), "calc") == 0 && 
strcmp(sql_func_imp(f->func), "ifthenelse") == 0)
+                       if (strcmp(sql_func_mod(f->func), "") == 0 && 
strcmp(sql_func_imp(f->func), "") == 0 && strcmp(f->func->base.name, "case") == 
0)
                                return exp2bin_case(be, e, left, right, sel, 
depth);
                        if (strcmp(sql_func_mod(f->func), "") == 0 && 
strcmp(sql_func_imp(f->func), "") == 0 && strcmp(f->func->base.name, 
"casewhen") == 0)
                                return exp2bin_casewhen(be, e, left, right, 
sel, depth);
@@ -2778,11 +2778,11 @@ rel2bin_antijoin(backend *be, sql_rel *r
                assert(list_length(mexps) == 1);
                for( en = mexps->h; en; en = en->next ) {
                        sql_exp *e = en->data;
-                       stmt *ls = exp_bin(be, e->l, left, right, NULL, NULL, 
NULL, NULL, 0, 1, 0), *rs;
+                       stmt *ls = exp_bin(be, e->l, left, right, NULL, NULL, 
NULL, NULL, 1, 0, 0), *rs;
                        if (!ls)
                                return NULL;
 
-                       if (!(rs = exp_bin(be, e->r, left, right, NULL, NULL, 
NULL, NULL, 0, 1, 0)))
+                       if (!(rs = exp_bin(be, e->r, left, right, NULL, NULL, 
NULL, NULL, 1, 0, 0)))
                                return NULL;
 
                        if (ls->nrcols == 0)
@@ -2881,14 +2881,14 @@ rel2bin_semijoin(backend *be, sql_rel *r
 
                                if (equality_only) {
                                        int oldvtop = be->mb->vtop, oldstop = 
be->mb->stop, oldvid = be->mb->vid, swap = 0;
-                                       stmt *r, *l = exp_bin(be, e->l, left, 
NULL, NULL, NULL, NULL, NULL, 0, 1, 0);
+                                       stmt *r, *l = exp_bin(be, e->l, left, 
NULL, NULL, NULL, NULL, NULL, 1, 0, 0);
 
                                        if (!l) {
                                                swap = 1;
                                                clean_mal_statements(be, 
oldstop, oldvtop, oldvid);
-                                               l = exp_bin(be, e->l, right, 
NULL, NULL, NULL, NULL, NULL, 0, 1, 0);
+                                               l = exp_bin(be, e->l, right, 
NULL, NULL, NULL, NULL, NULL, 1, 0, 0);
                                        }
-                                       r = exp_bin(be, e->r, left, right, 
NULL, NULL, NULL, NULL, 0, 1, 0);
+                                       r = exp_bin(be, e->r, left, right, 
NULL, NULL, NULL, NULL, 1, 0, 0);
 
                                        if (swap) {
                                                stmt *t = l;
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
@@ -1669,8 +1669,8 @@ mvc_append_column(sql_trans *t, sql_colu
 {
        sqlstore *store = t->store;
        int res = store->storage_api.append_col(t, c, pos, ins, TYPE_bat, 0);
-       if (res != LOG_OK)
-               throw(SQL, "sql.append", SQLSTATE(42000) "Cannot append 
values");
+       if (res != LOG_OK) /* the conflict case should never happen, but leave 
it here */
+               throw(SQL, "sql.append", SQLSTATE(42000) "Append failed%s", res 
== LOG_CONFLICT ? " due to conflict with another transaction" : "");
        return MAL_SUCCEED;
 }
 
@@ -1726,10 +1726,11 @@ mvc_append_wrap(Client cntxt, MalBlkPtr 
        const char *cname = *getArgReference_str(stk, pci, 4);
        lng pos = *(lng*)getArgReference_lng(stk, pci, 5);
        ptr ins = getArgReference(stk, pci, 6);
-       int tpe = getArgType(mb, pci, 6), err = 0;
+       int tpe = getArgType(mb, pci, 6), log_res = LOG_OK;
        sql_schema *s;
        sql_table *t;
        sql_column *c;
+       sql_idx *i;
        BAT *b = 0;
 
        *res = 0;
@@ -1762,18 +1763,14 @@ mvc_append_wrap(Client cntxt, MalBlkPtr 
                BATmsync(b);
        sqlstore *store = m->session->tr->store;
        if (cname[0] != '%' && (c = mvc_bind_column(m, t, cname)) != NULL) {
-               if (store->storage_api.append_col(m->session->tr, c, 
(size_t)pos, ins, tpe, 1) != LOG_OK)
-                       err = 1;
-       } else if (cname[0] == '%') {
-               sql_idx *i = mvc_bind_idx(m, s, cname + 1);
-               if (i && store->storage_api.append_idx(m->session->tr, i, 
(size_t)pos, ins, tpe, 1) != LOG_OK)
-                       err = 1;
+               log_res = store->storage_api.append_col(m->session->tr, c, 
(size_t)pos, ins, tpe, 1);
+       } else if (cname[0] == '%' && (i = mvc_bind_idx(m, s, cname + 1)) != 
NULL) {
+               log_res = store->storage_api.append_idx(m->session->tr, i, 
(size_t)pos, ins, tpe, 1);
        }
-       if (err)
-               throw(SQL, "sql.append", SQLSTATE(42S02) "append failed");
-       if (b) {
+       if (b)
                BBPunfix(b->batCacheid);
-       }
+       if (log_res != LOG_OK) /* the conflict case should never happen, but 
leave it here */
+               throw(SQL, "sql.append", SQLSTATE(42000) "Append failed%s", 
log_res == LOG_CONFLICT ? " due to conflict with another transaction" : "");
        return MAL_SUCCEED;
 }
 
@@ -1790,10 +1787,11 @@ mvc_update_wrap(Client cntxt, MalBlkPtr 
        bat Tids = *getArgReference_bat(stk, pci, 5);
        bat Upd = *getArgReference_bat(stk, pci, 6);
        BAT *tids, *upd;
-       int tpe = getArgType(mb, pci, 6), err = 0;
+       int tpe = getArgType(mb, pci, 6), log_res = LOG_OK;
        sql_schema *s;
        sql_table *t;
        sql_column *c;
+       sql_idx *i;
 
        *res = 0;
        if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
@@ -1833,17 +1831,14 @@ mvc_update_wrap(Client cntxt, MalBlkPtr 
                BATmsync(tids);
        sqlstore *store = m->session->tr->store;
        if (cname[0] != '%' && (c = mvc_bind_column(m, t, cname)) != NULL) {
-               if (store->storage_api.update_col(m->session->tr, c, tids, upd, 
TYPE_bat) != LOG_OK)
-                       err = 1;
-       } else if (cname[0] == '%') {
-               sql_idx *i = mvc_bind_idx(m, s, cname + 1);
-               if (i && store->storage_api.update_idx(m->session->tr, i, tids, 
upd, TYPE_bat) != LOG_OK)
-                       err = 1;
+               log_res = store->storage_api.update_col(m->session->tr, c, 
tids, upd, TYPE_bat);
+       } else if (cname[0] == '%' && (i = mvc_bind_idx(m, s, cname + 1)) != 
NULL) {
+               log_res = store->storage_api.update_idx(m->session->tr, i, 
tids, upd, TYPE_bat);
        }
        BBPunfix(tids->batCacheid);
        BBPunfix(upd->batCacheid);
-       if (err)
-               throw(SQL, "sql.update", SQLSTATE(42S02) "update failed");
+       if (log_res != LOG_OK)
+               throw(SQL, "sql.update", SQLSTATE(42000) "Update failed%s", 
log_res == LOG_CONFLICT ? " due to conflict with another transaction" : "");
        return MAL_SUCCEED;
 }
 
@@ -1855,6 +1850,7 @@ mvc_clear_table_wrap(Client cntxt, MalBl
        sql_table *t;
        mvc *m = NULL;
        str msg;
+       BUN clear_res;
        lng *res = getArgReference_lng(stk, pci, 0);
        const char *sname = *getArgReference_str(stk, pci, 1);
        const char *tname = *getArgReference_str(stk, pci, 2);
@@ -1869,9 +1865,10 @@ mvc_clear_table_wrap(Client cntxt, MalBl
        t = mvc_bind_table(m, s, tname);
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to