Re: MonetDB: Oct2014 - split update bat within the catalog interface...
This causes an assertion failed during upgrade from a Jan2014 database. On 2014-09-09 08:24, Niels Nes wrote:
Changeset: 1c3d356ffdc2 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c3d356ffdc2 Modified Files: sql/backends/monet5/rel_bin.c sql/backends/monet5/sql.c sql/backends/monet5/sql_gencode.c sql/backends/monet5/sql_optimizer.c sql/backends/monet5/sql_statistics.c sql/include/sql_catalog.h sql/storage/bat/bat_storage.c Branch: Oct2014 Log Message:
split update bat within the catalog interface to remove dependency on BATselect.
diffs (truncated from 395 to 300 lines):
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 @@ -733,7 +733,7 @@ stmt_col( mvc *sql, sql_column *c, stmt (c->base.flag != TR_NEW || c->t->base.flag != TR_NEW /* alter */) && (c->t->persistence == SQL_PERSIST || c->t->persistence == SQL_DECLARED_TABLE) && !c->t->commit_action) { stmt *i = stmt_bat(sql->sa, c, RD_INS); - stmt *u = stmt_bat(sql->sa, c, RD_UPD); + stmt *u = stmt_bat(sql->sa, c, RD_UPD_ID); sc = stmt_project_delta(sql->sa, sc, u, i); sc = stmt_project(sql->sa, del, sc); } else if (del) { /* always handle the deletes */ @@ -751,7 +751,7 @@ stmt_idx( mvc *sql, sql_idx *i, stmt *de (i->base.flag != TR_NEW || i->t->base.flag != TR_NEW /* alter */) && (i->t->persistence == SQL_PERSIST || i->t->persistence == SQL_DECLARED_TABLE) && !i->t->commit_action) { stmt *ic = stmt_idxbat(sql->sa, i, RD_INS); - stmt *u = stmt_idxbat(sql->sa, i, RD_UPD); + stmt *u = stmt_idxbat(sql->sa, i, RD_UPD_ID); sc = stmt_project_delta(sql->sa, sc, u, ic); sc = stmt_project(sql->sa, del, sc); } else if (del) { /* always handle the deletes */ 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 @@ -489,7 +489,7 @@ table_has_updates(sql_trans *tr, sql_tab
for ( n = t->columns.set->h; !cnt && n; n = n->next) { sql_column *c = n->data; - BAT *b = store_funcs.bind_col(tr, c, RD_UPD); + BAT *b = store_funcs.bind_col(tr, c, RD_UPD_ID); cnt |= BATcount(b) > 0; BBPunfix(b->batCacheid); } @@ -1644,6 +1644,7 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb bn = BATslice(b, part_nr * psz, (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz)); BATseqbase(bn, part_nr * psz); } else { + /* BAT b holds the UPD_ID bat */ oid l, h; BAT *c = mvc_bind(m, *sname, *tname, *cname, 0); cnt = BATcount(c); @@ -1651,23 +1652,39 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb l = part_nr * psz; h = (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz); h--; - bn = BATmirror(BATselect(BATmirror(b), &l, &h)); + bn = BATsubselect(b, NULL, &l, &h, 1, 0, 0); BBPreleaseref(c->batCacheid); } BBPreleaseref(b->batCacheid); b = bn; + } else if (upd) { + BAT *uv = mvc_bind(m, *sname, *tname, *cname, RD_UPD_VAL); + int *uvl = (int *) getArgReference(stk, pci, 1); + + BBPkeepref(*bid = b->batCacheid); + BBPkeepref(*uvl = uv->batCacheid); + return MAL_SUCCEED; } if (upd) { int *uvl = (int *) getArgReference(stk, pci, 1);
if (BATcount(b)) { - BAT *id = BATmirror(BATmark(b, 0)); - BAT *vl = BATmirror(BATmark(BATmirror(b), 0)); + BAT *uv = mvc_bind(m, *sname, *tname, *cname, RD_UPD_VAL); + BAT *ui = mvc_bind(m, *sname, *tname, *cname, RD_UPD_ID); + BAT *id = BATproject(b, ui); + BAT *vl = BATproject(b, uv); + bat_destroy(b); + bat_destroy(ui); + bat_destroy(uv); BBPkeepref(*bid = id->batCacheid); BBPkeepref(*uvl = vl->batCacheid); } else { + 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); + *bid = e_bat(TYPE_oid); - *uvl = e_bat(b->T->type); + *uvl = e_bat(c->type.type->localtype); } BBPreleaseref(b->batCacheid); } else { @@ -1711,6 +1728,7 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl bn = BATslice(b, part_nr * psz, (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz)); BATseqbase(bn, part_nr * psz); } else { + /* BAT b holds the UPD_ID bat */ oid l, h; BAT *c = mvc_bind_idxbat(m, *sname, *tname, *iname, 0); cnt = BATcount(c); @@ -1718,23 +1736,37 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl l = part_nr * psz; h = (part_nr + 1 == nr_parts) ? cnt : ((part_nr + 1) * psz); h--; - bn = BATmirror(BATselect(BATmirror(b), &l, &h)); + bn = BATsubselect(b, NULL, &l, &h, 1, 0, 0); BBPreleaseref(c->batCacheid); } BBPreleaseref(b->batCacheid); b = bn; + } else if (upd) { + BAT *uv = mvc_bind_idxbat(m, *sname, *tname, *iname, RD_UPD_VAL); + int *uvl = (int *) getArgReference(stk, pci, 1); + BBPkeepref(*bid = b->batCacheid); + BBPkeepref(*uvl = uv->batCacheid); + return MAL_SUCCEED; } if (upd) { int *uvl = (int *) getArgReference(stk, pci, 1);
if (BATcount(b)) { - BAT *id = BATmirror(BATmark(b, 0)); - BAT *vl = BATmirror(BATmark(BATmirror(b), 0)); + BAT *uv = mvc_bind_idxbat(m, *sname, *tname, *iname, RD_UPD_VAL); + BAT *ui = mvc_bind_idxbat(m, *sname, *tname, *iname, RD_UPD_ID); + BAT *id = BATproject(b, ui); + BAT *vl = BATproject(b, uv); + bat_destroy(b); + bat_destroy(ui); + bat_destroy(uv); BBPkeepref(*bid = id->batCacheid); BBPkeepref(*uvl = vl->batCacheid); } else { + sql_schema *s = mvc_bind_schema(m, *sname); + sql_idx *i = mvc_bind_idx(m, s, *iname); + *bid = e_bat(TYPE_oid); - *uvl = e_bat(b->T->type); + *uvl = e_bat((i->type==join_idx)?TYPE_oid:TYPE_wrd); } BBPreleaseref(b->batCacheid); } else { @@ -3959,7 +3991,7 @@ SQLcluster1(Client cntxt, MalBlkPtr mb, c = o->data; if (first) { first = 0; - b = store_funcs.bind_col(tr, c, 0); + b = store_funcs.bind_col(tr, c, RDONLY); msg = CLUSTER_key(&hid, &b->batCacheid); BBPreleaseref(b->batCacheid); if (msg) @@ -3973,7 +4005,7 @@ SQLcluster1(Client cntxt, MalBlkPtr mb, throw(SQL, "sql.cluster", "Can not access descriptor"); }
- b = store_funcs.bind_col(tr, c, 0); + b = store_funcs.bind_col(tr, c, RDONLY); if (b == NULL) throw(SQL, "sql.cluster", "Can not access descriptor"); msg = CLUSTER_apply(&bid, b, map); @@ -4039,7 +4071,7 @@ SQLcluster2(Client cntxt, MalBlkPtr mb, bat psum; unsigned int bits = 10, off = 0; first = 0; - b = store_funcs.bind_col(tr, c, 0); + b = store_funcs.bind_col(tr, c, RDONLY); msg = MKEYbathash(&hid, &b->batCacheid); BBPreleaseref(b->batCacheid); if (msg) @@ -4051,7 +4083,7 @@ SQLcluster2(Client cntxt, MalBlkPtr mb, return msg; }
- b = store_funcs.bind_col(tr, c, 0); + b = store_funcs.bind_col(tr, c, RDONLY); if (b == NULL) throw(SQL, "sql.cluster", "Can not access descriptor"); msg = CLS_map(&bid, &mid, &b->batCacheid); @@ -4132,7 +4164,7 @@ vacuum(Client cntxt, MalBlkPtr mb, MalSt bids[i] = 0; for (o = t->columns.set->h; o; o = o->next, i++) { c = o->data; - b = store_funcs.bind_col(tr, c, 0); + b = store_funcs.bind_col(tr, c, RDONLY); if (b == NULL || (msg = (*func) (&bid, &(b->batCacheid), &(del->batCacheid))) != NULL) { for (i--; i >= 0; i--) BBPdecref(bids[i], TRUE); @@ -4226,7 +4258,7 @@ SQLvacuum(Client cntxt, MalBlkPtr mb, Ma
for (o = t->columns.set->h; o && ordered == 0; o = o->next) { c = o->data; - b = store_funcs.bind_col(tr, c, 0); + b = store_funcs.bind_col(tr, c, RDONLY); if (b == NULL) throw(SQL, "sql.vacuum", "Can not access descriptor"); ordered |= BATtordered(b); @@ -4409,7 +4441,7 @@ sql_storage(Client cntxt, MalBlkPtr mb, for (ncol = (t)->columns.set->h; ncol; ncol = ncol->next) { sql_base *bc = ncol->data; sql_column *c = (sql_column *) ncol->data; - BAT *bn = store_funcs.bind_col(tr, c, 0); + BAT *bn = store_funcs.bind_col(tr, c, RDONLY); lng sz;
/*printf("schema %s.%s.%s" , b->name, bt->name, bc->name); */ @@ -4474,7 +4506,7 @@ sql_storage(Client cntxt, MalBlkPtr mb, sql_base *bc = ncol->data; sql_idx *c = (sql_idx *) ncol->data; if (c->type != no_idx) { - BAT *bn = store_funcs.bind_idx(tr, c, 0); + BAT *bn = store_funcs.bind_idx(tr, c, RDONLY); lng sz;
/*printf("schema %s.%s.%s" , b->name, bt->name, bc->name); */ diff --git a/sql/backends/monet5/sql_gencode.c b/sql/backends/monet5/sql_gencode.c --- a/sql/backends/monet5/sql_gencode.c +++ b/sql/backends/monet5/sql_gencode.c @@ -897,7 +897,7 @@ static int q = newStmt2(mb, sqlRef, bindRef); if (q == NULL) return -1; - if (s->flag == RD_UPD) { + if (s->flag == RD_UPD_ID) { q = pushReturn(mb, q, newTmpVariable(mb, newBatType(ht, tt))); } else setVarType(mb, getArg(q, 0), newBatType(ht, tt)); @@ -910,7 +910,7 @@ static int return -1; s->nr = getDestVar(q);
- if (s->flag == RD_UPD) { + if (s->flag == RD_UPD_ID) { /* rename second result */ renameVariable(mb, getArg(q, 1), "r1_%d", s->nr); } @@ -924,7 +924,7 @@ static int q = newStmt2(mb, sqlRef, bindidxRef); if (q == NULL) return -1; - if (s->flag == RD_UPD) { + if (s->flag == RD_UPD_ID) { q = pushReturn(mb, q, newTmpVariable(mb, newBatType(ht, tt))); } else setVarType(mb, getArg(q, 0), newBatType(ht, tt)); @@ -937,7 +937,7 @@ static int return -1; s->nr = getDestVar(q);
- if (s->flag == RD_UPD) { + if (s->flag == RD_UPD_ID) { /* rename second result */ renameVariable(mb, getArg(q, 1), "r1_%d", s->nr); } diff --git a/sql/backends/monet5/sql_optimizer.c b/sql/backends/monet5/sql_optimizer.c --- a/sql/backends/monet5/sql_optimizer.c +++ b/sql/backends/monet5/sql_optimizer.c @@ -138,7 +138,7 @@ SQLgetStatistics(Client cntxt, mvc *m, M if (i && (!isRemote(i->t) && !isMergeTable(i->t))) { cnt = store_funcs.count_idx(tr, i, 1); assert(cnt <= (size_t) GDK_oid_max); - b = store_funcs.bind_idx(m->session->tr, i, 0); + b = store_funcs.bind_idx(m->session->tr, i, RDONLY); if (b) { str loc; if (b->batPersistence == PERSISTENT && BATlocation(&loc, &b->batCacheid) && loc) @@ -158,7 +158,7 @@ SQLgetStatistics(Client cntxt, mvc *m, M
cnt = store_funcs.count_col(tr, c, 1); assert(cnt <= (size_t) GDK_oid_max); - b = store_funcs.bind_col(m->session->tr, c, 0); + b = store_funcs.bind_col(m->session->tr, c, RDONLY); if (b) { str loc; if (b->batPersistence == PERSISTENT && BATlocation(&loc, &b->batCacheid) && loc) diff --git a/sql/backends/monet5/sql_statistics.c b/sql/backends/monet5/sql_statistics.c --- a/sql/backends/monet5/sql_statistics.c +++ b/sql/backends/monet5/sql_statistics.c @@ -98,7 +98,7 @@ sql_analyze(Client cntxt, MalBlkPtr mb, for (ncol = (t)->columns.set->h; ncol; ncol = ncol->next) { sql_base *bc = ncol->data; sql_column *c = (sql_column *) ncol->data; - BAT *bn = store_funcs.bind_col(tr, c, 0), *br; + BAT *bn = store_funcs.bind_col(tr, c, RDONLY), *br; BAT *bsample; lng sz = BATcount(bn);
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h --- a/sql/include/sql_catalog.h +++ b/sql/include/sql_catalog.h @@ -92,8 +92,9 @@
#define RDONLY 0 #define RD_INS 1 -#define RD_UPD 2 -#define QUICK 3 +#define RD_UPD_ID 2 +#define RD_UPD_VAL 3 +#define QUICK 4
#define FRAME_ROWS 0 #define FRAME_RANGE 1 diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c --- a/sql/storage/bat/bat_storage.c +++ b/sql/storage/bat/bat_storage.c @@ -52,7 +52,7 @@ delta_bind_del(sql_dbat *bat, int access (void) access; /* satisfy compiler */ #endif _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list
-- Sjoerd Mullender
participants (1)
-
Sjoerd Mullender