Changeset: 29cf41414a05 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=29cf41414a05 Modified Files: gdk/gdk_cand.h gdk/gdk_join.c gdk/gdk_private.h gdk/gdk_select.c sql/test/SQLite_regress/sqllogictest/Tests/select3.test.stable.out sql/test/SQLite_regress/sqllogictest/Tests/select3.test.stable.out.int128 Branch: candidate-exceptions Log Message:
Converted BATselect to candidate iterators. diffs (truncated from 78388 to 300 lines): diff --git a/gdk/gdk_cand.h b/gdk/gdk_cand.h --- a/gdk/gdk_cand.h +++ b/gdk/gdk_cand.h @@ -98,6 +98,20 @@ canditer_next(struct canditer *ci) } return o; } +#define canditer_next_dense(ci) ((ci)->next == (ci)->ncand ? oid_nil : (ci)->seq + (ci)->next++) +#define canditer_next_mater(ci) ((ci)->next == (ci)->ncand ? oid_nil : (ci)->oids[(ci)->next++]) +static inline oid +canditer_next_except(struct canditer *ci) +{ + if (ci->next == ci->ncand) + return oid_nil; + oid o = ci->seq + ci->add + ci->next++; + while (ci->add < ci->noids && o == ci->oids[ci->add]) { + ci->add++; + o++; + } + return o; +} gdk_export BUN canditer_init(struct canditer *ci, BAT *b, BAT *s); gdk_export oid canditer_peek(struct canditer *ci); diff --git a/gdk/gdk_join.c b/gdk/gdk_join.c --- a/gdk/gdk_join.c +++ b/gdk/gdk_join.c @@ -431,10 +431,8 @@ mergejoin_void(BAT **r1p, BAT **r2p, BAT * has a match in r */ assert(ATOMtype(l->ttype) == ATOMtype(r->ttype)); assert(r->tsorted || r->trevsorted); - assert(sl == NULL || sl->tsorted); - assert(sr == NULL || sr->tsorted); assert(BATcount(l) > 0); - assert(BATtdense(r)); + assert(rci->tpe == cand_dense); assert(BATcount(r) > 0); /* figure out range [lo..hi) of values in r that we need to match */ diff --git a/gdk/gdk_private.h b/gdk/gdk_private.h --- a/gdk/gdk_private.h +++ b/gdk/gdk_private.h @@ -120,10 +120,6 @@ void BBPdump(void) /* never called: for __attribute__((__visibility__("hidden"))); __hidden Heap *createOIDXheap(BAT *b, bool stable) __attribute__((__visibility__("hidden"))); -__hidden BAT *doublerange(oid l1, oid h1, oid l2, oid h2) - __attribute__((__visibility__("hidden"))); -__hidden BAT *doubleslice(BAT *b, BUN l1, BUN h1, BUN l2, BUN h2) - __attribute__((__visibility__("hidden"))); __hidden void gdk_bbp_reset(void) __attribute__((__visibility__("hidden"))); __hidden gdk_return GDKextend(const char *fn, size_t size) diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c --- a/gdk/gdk_select.c +++ b/gdk/gdk_select.c @@ -52,7 +52,14 @@ virtualize(BAT *bn) bn->tseqbase = 0; else bn->tseqbase = * (const oid *) Tloc(bn, 0); - HEAPfree(&bn->theap, true); + if (VIEWtparent(bn)) { + BBPunshare(VIEWtparent(bn)); + BBPunfix(VIEWtparent(bn)); + bn->theap.parentid = 0; + bn->theap.base = NULL; + } else { + HEAPfree(&bn->theap, true); + } bn->theap.storage = bn->theap.newstorage = STORE_MEM; bn->theap.size = 0; bn->ttype = TYPE_void; @@ -64,69 +71,6 @@ virtualize(BAT *bn) return bn; } -BAT * -doublerange(oid l1, oid h1, oid l2, oid h2) -{ - BAT *bn; - oid *restrict p; - - assert(l1 <= h1); - assert(l2 <= h2); - assert(h1 <= l2); - if (l1 == h1 || l2 == h2) { - return BATdense(0, l1 == h1 ? l2 : l1, h1 - l1 + h2 - l2); - } - bn = COLnew(0, TYPE_oid, h1 - l1 + h2 - l2, TRANSIENT); - if (bn == NULL) - return NULL; - BATsetcount(bn, h1 - l1 + h2 - l2); - p = (oid *) Tloc(bn, 0); - while (l1 < h1) - *p++ = l1++; - while (l2 < h2) - *p++ = l2++; - bn->tkey = true; - bn->tsorted = true; - bn->trevsorted = BATcount(bn) <= 1; - bn->tnil = false; - bn->tnonil = true; - return bn; -} - -BAT * -doubleslice(BAT *b, BUN l1, BUN h1, BUN l2, BUN h2) -{ - BAT *bn; - oid *restrict p; - const oid *restrict o; - - assert(l1 <= h1); - assert(l2 <= h2); - assert(h1 <= l2); - assert(b->tsorted); - assert(b->tkey); - if (b->ttype == TYPE_void) - return doublerange(l1 + b->tseqbase, h1 + b->tseqbase, - l2 + b->tseqbase, h2 + b->tseqbase); - bn = COLnew(0, TYPE_oid, h1 - l1 + h2 - l2, TRANSIENT); - if (bn == NULL) - return NULL; - BATsetcount(bn, h1 - l1 + h2 - l2); - p = (oid *) Tloc(bn, 0); - o = (const oid *) Tloc(b, l1); - while (l1++ < h1) - *p++ = *o++; - o = (const oid *) Tloc(b, l2); - while (l2++ < h2) - *p++ = *o++; - bn->tkey = true; - bn->tsorted = true; - bn->trevsorted = BATcount(bn) <= 1; - bn->tnil = false; - bn->tnonil = true; - return virtualize(bn); -} - #define HASHloop_bound(bi, h, hb, v, lo, hi) \ for (hb = HASHget(h, HASHprobe((h), v)); \ hb != HASHnil(h); \ @@ -136,19 +80,20 @@ doubleslice(BAT *b, BUN l1, BUN h1, BUN (*cmp)(v, BUNtail(bi, hb)) == 0)) static BAT * -hashselect(BAT *b, BAT *s, BAT *bn, const void *tl, BUN maximum, bool phash) +hashselect(BAT *b, struct canditer *restrict ci, BAT *bn, + const void *tl, BUN maximum, bool phash) { BATiter bi; BUN i, cnt; oid o, *restrict dst; - BUN l, h; + BUN l, h, d = 0; oid seq; int (*cmp)(const void *, const void *); assert(bn->ttype == TYPE_oid); seq = b->hseqbase; - l = 0; - h = BUNlast(b); + l = ci->seq - seq; + h = canditer_last(ci) + 1 - seq; if (phash) { BAT *b2 = BBPdescriptor(VIEWtparent(b)); @@ -158,22 +103,12 @@ hashselect(BAT *b, BAT *s, BAT *bn, cons "for hash\n", ALGOBATPAR(b), ALGOBATPAR(b2)); - l = (BUN) ((b->theap.base - b2->theap.base) >> b->tshift); - h = l + BATcount(b); + d = (BUN) ((b->theap.base - b2->theap.base) >> b->tshift); + l += d; + h += d; b = b2; } - if (s && BATtdense(s)) { - /* no need for binary search in s, we just adjust the - * boundaries */ - if (s->tseqbase + BATcount(s) < seq + (h - l)) - h -= seq + (h - l) - (s->tseqbase + BATcount(s)); - if (s->tseqbase > seq) { - l += s->tseqbase - seq; - seq += s->tseqbase - seq; - } - s = NULL; - } if (BAThash(b) != GDK_SUCCEED) { BBPreclaim(bn); return NULL; @@ -190,11 +125,10 @@ hashselect(BAT *b, BAT *s, BAT *bn, cons bi = bat_iterator(b); dst = (oid *) Tloc(bn, 0); cnt = 0; - if (s) { - assert(s->tsorted); + if (ci->tpe != cand_dense) { HASHloop_bound(bi, b->thash, i, tl, l, h) { - o = (oid) (i - l + seq); - if (BATcandcontains(s, o)) { + o = (oid) (i + seq - d); + if (canditer_search(ci, o, false) != BUN_NONE) { buninsfix(bn, dst, cnt, o, maximum - BATcapacity(bn), maximum, NULL); @@ -203,7 +137,7 @@ hashselect(BAT *b, BAT *s, BAT *bn, cons } } else { HASHloop_bound(bi, b->thash, i, tl, l, h) { - o = (oid) (i - l + seq); + o = (oid) (i + seq - d); buninsfix(bn, dst, cnt, o, maximum - BATcapacity(bn), maximum, NULL); @@ -230,36 +164,33 @@ hashselect(BAT *b, BAT *s, BAT *bn, cons /* Imprints select code */ /* inner check */ -#define impscheck(CAND,TEST,ADD) \ - do { \ - e = (BUN) (i+limit-pr_off+off); \ - if (im[icnt] & mask) { \ - if ((im[icnt] & ~innermask) == 0) { \ - while (p < q && o < e) { \ - v = src[o-off]; \ - ADD; \ - cnt++; \ - p++; \ - if (p < q) \ - CAND; \ - } \ - } else { \ - while (p < q && o < e) { \ - v = src[o-off]; \ - ADD; \ - cnt += (TEST) != 0; \ - p++; \ - if (p < q) \ - CAND; \ - } \ - } \ - } else { \ - while (p < q && o < e) { \ - p++; \ - if (p < q) \ - CAND; \ - } \ - } \ +#define impscheck(canditer_next,TEST,ADD) \ + do { \ + const oid e = (oid) (i+limit-pr_off+hseq); \ + if (im[icnt] & mask) { \ + if ((im[icnt] & ~innermask) == 0) { \ + while (p < ci->ncand && o < e) { \ + v = src[o-hseq]; \ + ADD; \ + cnt++; \ + p++; \ + o = canditer_next(ci); \ + } \ + } else { \ + while (p < ci->ncand && o < e) { \ + v = src[o-hseq]; \ + ADD; \ + cnt += (TEST) != 0; \ + p++; \ + o = canditer_next(ci); \ + } \ + } \ + } else { \ + while (p < ci->ncand && o < e) { \ + p++; \ + o = canditer_next(ci); \ + } \ + } \ } while (false) /* main loop for imprints */ @@ -268,38 +199,38 @@ hashselect(BAT *b, BAT *s, BAT *bn, cons * dcnt is the iterator for dictionary entries * i is the iterator for the values in imprints */ -#define impsloop(CAND,TEST,ADD) \ +#define impsloop(canditer_next,TEST,ADD) \ do { \ - BUN dcnt, icnt, limit, i, l, e; \ - cchdc_t *restrict d = (cchdc_t *) imprints->dict; \ - uint8_t rpp = ATOMelmshift(IMPS_PAGE >> b->tshift); \ - CAND; \ - for (i = 0, dcnt = 0, icnt = 0; \ - dcnt < imprints->dictcnt && i + off < w + pr_off && p < q; \ + BUN dcnt, icnt, limit, i; \ + const cchdc_t *restrict d = (cchdc_t *) imprints->dict; \ + const uint8_t rpp = ATOMelmshift(IMPS_PAGE >> b->tshift); \ + o = canditer_next(ci); \ + for (i = 0, dcnt = 0, icnt = 0, p = 0; \ + dcnt < imprints->dictcnt && i <= w - hseq + pr_off && p < ci->ncand; \ _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list