Changeset: 40c0ec33880e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/40c0ec33880e
Modified Files:
sql/backends/monet5/sql.c
sql/test/emptydb/Tests/check.stable.out
sql/test/emptydb/Tests/check.stable.out.32bit
sql/test/emptydb/Tests/check.stable.out.int128
Branch: default
Log Message:
Merge with Jul2021
diffs (truncated from 3550 to 300 lines):
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_logger.c b/gdk/gdk_logger.c
--- a/gdk/gdk_logger.c
+++ b/gdk/gdk_logger.c
@@ -2329,7 +2329,7 @@ internal_log_bat(logger *lg, BAT *b, log
* should simply introduce a versioning scheme.
*/
gdk_return
-log_bat_persists(logger *lg, BAT *b, int id)
+log_bat_persists(logger *lg, BAT *b, log_id id)
{
logger_lock(lg);
bte ta = find_type(lg, b->ttype);
@@ -2359,7 +2359,7 @@ log_bat_persists(logger *lg, BAT *b, int
}
gdk_return
-log_bat_transient(logger *lg, int id)
+log_bat_transient(logger *lg, log_id id)
{
logger_lock(lg);
log_bid bid = internal_find_bat(lg, id);
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);
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
@@ -1226,6 +1226,9 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
return msg;
if ((msg = checkSQLContext(cntxt)) != NULL)
return msg;
+ sql_schema *s = mvc_bind_schema(m, sname);
+ sql_table *t = mvc_bind_table(m, s, tname);
+ sql_column *c = mvc_bind_column(m, t, cname);
b = mvc_bind(m, sname, tname, cname, access);
if (b && b->ttype != coltype) {
BBPunfix(b->batCacheid);
@@ -1233,7 +1236,9 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
}
if (b) {
if (pci->argc == (8 + upd) && getArgType(mb, pci, 6 + upd) ==
TYPE_int) {
+ sqlstore *store = m->session->tr->store;
BUN cnt = BATcount(b), psz;
+ cnt = store->storage_api.count_col(m->session->tr, c,
0);
/* partitioned access */
int part_nr = *getArgReference_int(stk, pci, 6 + upd);
int nr_parts = *getArgReference_int(stk, pci, 7 + upd);
@@ -1669,8 +1674,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 +1731,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 +1768,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 +1792,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 +1836,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 +1855,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 +1870,10 @@ mvc_clear_table_wrap(Client cntxt, MalBl
t = mvc_bind_table(m, s, tname);
if (t == NULL)
throw(SQL, "sql.clear_table", SQLSTATE(42S02) "Table missing
%s.%s", sname,tname);
- *res = mvc_clear_table(m, t);
- if (*res == BUN_NONE)
- throw(SQL, "sql.clear_table", SQLSTATE(42S02) "clear failed");
+ clear_res = mvc_clear_table(m, t);
+ if (clear_res >= BUN_NONE - 1)
+ throw(SQL, "sql.clear_table", SQLSTATE(42000) "Table clear
failed%s", clear_res == (BUN_NONE - 1) ? " due to conflict with another
transaction" : "");
+ *res = (lng) clear_res;
return MAL_SUCCEED;
}
@@ -1885,9 +1887,8 @@ mvc_delete_wrap(Client cntxt, MalBlkPtr
const char *sname = *getArgReference_str(stk, pci, 2);
const char *tname = *getArgReference_str(stk, pci, 3);
ptr ins = getArgReference(stk, pci, 4);
- int tpe = getArgType(mb, pci, 4);
+ int tpe = getArgType(mb, pci, 4), log_res;
BAT *b = NULL;
-
sql_schema *s;
sql_table *t;
@@ -1920,10 +1921,11 @@ mvc_delete_wrap(Client cntxt, MalBlkPtr
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list