Changeset: 9e6388c2ca8c for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9e6388c2ca8c Modified Files: clients/Tests/exports.stable.out gdk/gdk_cand.c gdk/gdk_cand.h sql/backends/monet5/sql.c sql/storage/bat/bat_table.c Branch: unlock Log Message:
Changed interface of BATnegcands and BATmaskedcands to return new BAT. diffs (289 lines): diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out --- a/clients/Tests/exports.stable.out +++ b/clients/Tests/exports.stable.out @@ -161,7 +161,7 @@ gdk_return BATjoin(BAT **r1p, BAT **r2p, gdk_return BATkey(BAT *b, bool onoff); bool BATkeyed(BAT *b); gdk_return BATleftjoin(BAT **r1p, BAT **r2p, BAT *l, BAT *r, BAT *sl, BAT *sr, bool nil_matches, BUN estimate) __attribute__((__warn_unused_result__)); -gdk_return BATmaskedcands(BAT *dense_cands, BAT *masked, bool selected); +BAT *BATmaskedcands(oid hseq, BAT *masked, bool selected); void *BATmax(BAT *b, void *aggr); void *BATmax_skipnil(BAT *b, void *aggr, bit skipnil); BAT *BATmergecand(BAT *a, BAT *b); @@ -169,7 +169,7 @@ void *BATmin(BAT *b, void *aggr); void *BATmin_skipnil(BAT *b, void *aggr, bit skipnil); gdk_return BATmode(BAT *b, bool transient); void BATmsync(BAT *b); -gdk_return BATnegcands(BAT *dense_cands, BAT *odels); +BAT *BATnegcands(BUN nr, BAT *odels); BAT *BATnil_grp(BAT *l, BAT *g, BAT *e, BAT *s); bool BATordered(BAT *b); bool BATordered_rev(BAT *b); diff --git a/gdk/gdk_cand.c b/gdk/gdk_cand.c --- a/gdk/gdk_cand.c +++ b/gdk/gdk_cand.c @@ -1240,45 +1240,47 @@ canditer_slice2val(struct canditer *ci, lo2, hi2, ci->ncand); } -gdk_return -BATnegcands(BAT *dense_cands, BAT *odels) +BAT * +BATnegcands(BUN nr, BAT *odels) { const char *nme; Heap *dels; BUN lo, hi; ccand_t *c; + BAT *bn; - assert(BATtdense(dense_cands)); - assert(dense_cands->ttype == TYPE_void); - assert(dense_cands->batRole == TRANSIENT); - + bn = BATdense(0, 0, nr); + if (bn == NULL) + return NULL; if (BATcount(odels) == 0) - return GDK_SUCCEED; + return bn; - lo = SORTfndfirst(odels, &dense_cands->tseqbase); - hi = SORTfndfirst(odels, &(oid) {dense_cands->tseqbase + BATcount(dense_cands)}); + lo = SORTfndfirst(odels, &bn->tseqbase); + hi = SORTfndfirst(odels, &(oid) {bn->tseqbase + BATcount(bn)}); if (lo == hi) - return GDK_SUCCEED; + return bn; - nme = BBP_physical(dense_cands->batCacheid); + nme = BBP_physical(bn->batCacheid); if ((dels = (Heap*)GDKzalloc(sizeof(Heap))) == NULL || - (dels->farmid = BBPselectfarm(dense_cands->batRole, dense_cands->ttype, varheap)) < 0){ + (dels->farmid = BBPselectfarm(bn->batRole, bn->ttype, varheap)) < 0){ GDKfree(dels); - return GDK_FAIL; + BBPreclaim(bn); + return NULL; } strconcat_len(dels->filename, sizeof(dels->filename), nme, ".theap", NULL); if (HEAPalloc(dels, hi - lo + (sizeof(ccand_t)/sizeof(oid)), sizeof(oid), 0) != GDK_SUCCEED) { GDKfree(dels); - return GDK_FAIL; + BBPreclaim(bn); + return NULL; } ATOMIC_INIT(&dels->refs, 1); c = (ccand_t *) dels->base; *c = (ccand_t) { .type = CAND_NEGOID, }; - dels->parentid = dense_cands->batCacheid; + dels->parentid = bn->batCacheid; dels->free = sizeof(ccand_t) + sizeof(oid) * (hi - lo); if (odels->ttype == TYPE_void) { oid *r = (oid *) (dels->base + sizeof(ccand_t)); @@ -1288,37 +1290,45 @@ BATnegcands(BAT *dense_cands, BAT *odels oid *r = (oid *) (dels->base + sizeof(ccand_t)); memcpy(r, Tloc(odels, lo), sizeof(oid) * (hi - lo)); } - dense_cands->batDirtydesc = true; - dense_cands->tvheap = dels; - BATsetcount(dense_cands, dense_cands->batCount - (hi - lo)); + bn->batDirtydesc = true; + bn->tvheap = dels; + BATsetcount(bn, bn->batCount - (hi - lo)); TRC_DEBUG(ALGO, "BATnegcands(cands=" ALGOBATFMT "," "dels=" ALGOBATFMT ")\n", - ALGOBATPAR(dense_cands), + ALGOBATPAR(bn), ALGOBATPAR(odels)); - return GDK_SUCCEED; + TRC_DEBUG(ALGO, "nr=" BUNFMT ", odels=" ALGOBATFMT + " -> " ALGOBATFMT "\n", + nr, ALGOBATPAR(odels), + ALGOBATPAR(bn)); + return bn; } -gdk_return -BATmaskedcands(BAT *dense_cands, BAT *masked, bool selected) +BAT * +BATmaskedcands(oid hseq, BAT *masked, bool selected) { const char *nme; Heap *msks; ccand_t *c; BUN nmask; + BAT *bn; - assert(BATtdense(dense_cands)); - assert(dense_cands->ttype == TYPE_void); - assert(dense_cands->batRole == TRANSIENT); assert(masked->ttype == TYPE_msk); + bn = COLnew(hseq, TYPE_void, 0, TRANSIENT); + if (bn == NULL) + return NULL; + BATtseqbase(bn, hseq); + if (BATcount(masked) == 0) - return GDK_SUCCEED; + return bn; - nme = BBP_physical(dense_cands->batCacheid); + nme = BBP_physical(bn->batCacheid); if ((msks = (Heap*)GDKzalloc(sizeof(Heap))) == NULL || - (msks->farmid = BBPselectfarm(dense_cands->batRole, dense_cands->ttype, varheap)) < 0){ + (msks->farmid = BBPselectfarm(bn->batRole, bn->ttype, varheap)) < 0){ GDKfree(msks); - return GDK_FAIL; + BBPreclaim(bn); + return NULL; } strconcat_len(msks->filename, sizeof(msks->filename), nme, ".theap", NULL); @@ -1326,14 +1336,15 @@ BATmaskedcands(BAT *dense_cands, BAT *ma nmask = (BATcount(masked) + 31) / 32; if (HEAPalloc(msks, nmask + (sizeof(ccand_t)/sizeof(uint32_t)), sizeof(uint32_t), 0) != GDK_SUCCEED) { GDKfree(msks); - return GDK_FAIL; + BBPreclaim(bn); + return NULL; } c = (ccand_t *) msks->base; *c = (ccand_t) { .type = CAND_MSK, .mask = selected, }; - msks->parentid = dense_cands->batCacheid; + msks->parentid = bn->batCacheid; msks->free = sizeof(ccand_t) + nmask * sizeof(uint32_t); uint32_t *r = (uint32_t*)(msks->base + sizeof(ccand_t)); memcpy(r, Tloc(masked, 0), nmask * sizeof(uint32_t)); @@ -1349,20 +1360,21 @@ BATmaskedcands(BAT *dense_cands, BAT *ma } if (cnt > 0) { ATOMIC_INIT(&msks->refs, 1); - dense_cands->tvheap = msks; - dense_cands->hseqbase += c->firstbit; + bn->tvheap = msks; + bn->hseqbase += c->firstbit; } else { /* no point having a mask if it's empty */ HEAPfree(msks, true); GDKfree(msks); } - dense_cands->batDirtydesc = true; - BATsetcount(dense_cands, cnt); - TRC_DEBUG(ALGO, "BATmaskedcands(cands=" ALGOBATFMT "," - "masked=" ALGOBATFMT ")\n", - ALGOBATPAR(dense_cands), - ALGOBATPAR(masked)); - return GDK_SUCCEED; + bn->batDirtydesc = true; + BATsetcount(bn, cnt); + TRC_DEBUG(ALGO, "hseq=" OIDFMT ", masked=" ALGOBATFMT ", selected=%s" + " -> " ALGOBATFMT "\n", + hseq, ALGOBATPAR(masked), + selected ? "true" : "false", + ALGOBATPAR(bn)); + return bn; } BAT * diff --git a/gdk/gdk_cand.h b/gdk/gdk_cand.h --- a/gdk/gdk_cand.h +++ b/gdk/gdk_cand.h @@ -193,8 +193,8 @@ gdk_export BAT *canditer_slice(struct ca gdk_export BAT *canditer_sliceval(struct canditer *ci, oid lo, oid hi); gdk_export BAT *canditer_slice2(struct canditer *ci, BUN lo1, BUN hi1, BUN lo2, BUN hi2); gdk_export BAT *canditer_slice2val(struct canditer *ci, oid lo1, oid hi1, oid lo2, oid hi2); -gdk_export gdk_return BATnegcands( BAT *dense_cands, BAT *odels); -gdk_export gdk_return BATmaskedcands( BAT *dense_cands, BAT *masked, bool selected); +gdk_export BAT *BATnegcands(BUN nr, BAT *odels); +gdk_export BAT *BATmaskedcands(oid hseq, BAT *masked, bool selected); gdk_export BAT *BATunmask(BAT *b); gdk_export BAT *BATmergecand(BAT *a, BAT *b); 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 @@ -2303,21 +2303,20 @@ SQLtid(Client cntxt, MalBlkPtr mb, MalSt BBPunfix(nui->batCacheid); BBPunfix(nuv->batCacheid); } - d = NULL; /* true == deleted, need not deleted */ if (bn) { - tids = BATdense(sb, sb, (BUN) nr); - if (bn && BATcount(bn)) + if (BATcount(bn)) { d = BATcalcnot(bn, NULL); - if (bn) BBPunfix(bn->batCacheid); - if (d && BATmaskedcands(tids, d, true) != GDK_SUCCEED) { - if (d) BBPunfix(d->batCacheid); - if (tids) BBPunfix(tids->batCacheid); + if (d == NULL) + throw(SQL, "sql.tid", SQLSTATE(HY013) MAL_MALLOC_FAIL); + } else + d = bn; + tids = BATmaskedcands(sb, d, true); + BBPunfix(d->batCacheid); + if (tids == NULL) { throw(MAL, "sql.tids", SQLSTATE(45003) "TIDdeletes failed"); } - if (d) - BBPunfix(d->batCacheid); d = tids; } if(d == NULL) diff --git a/sql/storage/bat/bat_table.c b/sql/storage/bat/bat_table.c --- a/sql/storage/bat/bat_table.c +++ b/sql/storage/bat/bat_table.c @@ -17,10 +17,7 @@ static BAT * sql_column *c = t->columns.set->h->data; /* create void,void bat with length and oid's set */ size_t nr = store_funcs.count_col(tr, c, 0), dcnt = 0; - BAT *tids = BATdense(0, 0, (BUN) nr); - - if (!tids) - return NULL; + BAT *tids = NULL; if ((dcnt=store_funcs.count_del(tr, t, 0)) > 0 || store_funcs.count_del(tr, t, 2) > 0) { BAT *d; @@ -45,24 +42,21 @@ static BAT * d = nd; } BAT *del_ids = BATunmask(d); - if (!del_ids) { - bat_destroy(d); - bat_destroy(tids); + bat_destroy(d); + if (del_ids == NULL) { return NULL; } - bat_destroy(d); - gdk_return ret = BATnegcands(tids, del_ids); + tids = BATnegcands((BUN) nr, del_ids); BBPunfix(del_ids->batCacheid); - if (ret != GDK_SUCCEED) { - BBPreclaim(del_ids); - bat_destroy(tids); + if (tids == NULL) { return NULL; } } else { - bat_destroy(tids); return NULL; } } + if (tids == NULL) + tids = BATdense(0, 0, (BUN) nr); return tids; } _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list