Changeset: 0f359436c7cc for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=0f359436c7cc
Modified Files:
        gdk/gdk_search.c
        gdk/gdk_select.c
Branch: leftmart
Log Message:

select code for oid index.


diffs (171 lines):

diff --git a/gdk/gdk_search.c b/gdk/gdk_search.c
--- a/gdk/gdk_search.c
+++ b/gdk/gdk_search.c
@@ -739,22 +739,24 @@ SORTfndwhich(BAT *b, const void *v, enum
        case FIND_FIRST:
                end = lo;
                if (lo >= hi ||
-                   (use_orderidx && (atom_GE(BUNtail(bi,*(oid 
*)BUNtail(bio,lo)), v, b->ttype))) ||
+                   (use_orderidx && (atom_GE(BUNtail(bi,*(oid 
*)BUNtail(bio,lo) - b->hseqbase + BUNfirst(b)), v, b->ttype))) ||
                    (!use_orderidx && (b->tsorted ? atom_GE(BUNtail(bi, lo), v, 
b->ttype) : atom_LE(BUNtail(bi, lo), v, b->ttype)))) {
                        /* shortcut: if BAT is empty or first (and
                         * hence all) tail value is >= v (if sorted)
                         * or <= v (if revsorted), we're done */
+                       if (use_orderidx) BBPunfix(o->batCacheid);
                        return lo;
                }
                break;
        case FIND_LAST:
                end = hi;
                if (lo >= hi ||
-                   (use_orderidx && (atom_LE(BUNtail(bi,*(oid 
*)BUNtail(bio,hi-1)), v, b->ttype))) ||
+                   (use_orderidx && (atom_LE(BUNtail(bi,*(oid 
*)BUNtail(bio,hi-1) - b->hseqbase + BUNfirst(b)), v, b->ttype))) ||
                    (!use_orderidx && b->tsorted ? atom_LE(BUNtail(bi, hi - 1), 
v, b->ttype) : atom_GE(BUNtail(bi, hi - 1), v, b->ttype))) {
                        /* shortcut: if BAT is empty or first (and
                         * hence all) tail value is <= v (if sorted)
                         * or >= v (if revsorted), we're done */
+                       if (use_orderidx) BBPunfix(o->batCacheid);
                        return hi;
                }
                break;
@@ -762,6 +764,7 @@ SORTfndwhich(BAT *b, const void *v, enum
                end = 0;        /* not used in this case */
                if (lo >= hi) {
                        /* empty BAT: value not found */
+                       if (use_orderidx) BBPunfix(o->batCacheid);
                        return BUN_NONE;
                }
                break;
@@ -770,27 +773,27 @@ SORTfndwhich(BAT *b, const void *v, enum
        if (use_orderidx) {
                switch (tp) {
                case TYPE_bte:
-                       SORTfndloop(bte, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(bte, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
                case TYPE_sht:
-                       SORTfndloop(sht, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(sht, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
                case TYPE_int:
-                       SORTfndloop(int, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(int, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
                case TYPE_lng:
-                       SORTfndloop(lng, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(lng, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
 #ifdef HAVE_HGE
                case TYPE_hge:
-                       SORTfndloop(hge, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(hge, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
 #endif
                case TYPE_flt:
-                       SORTfndloop(flt, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(flt, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
                case TYPE_dbl:
-                       SORTfndloop(dbl, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur));
+                       SORTfndloop(dbl, simple_CMP, BUNtloc, *(oid 
*)BUNtail(bio,cur) - b->hseqbase + BUNfirst(b));
                        break;
                default:
                        assert(0);
@@ -868,7 +871,7 @@ SORTfndwhich(BAT *b, const void *v, enum
                        /* shift over multiple equals */
                        for (diff = cur - end; diff; diff >>= 1) {
                                while (cur >= end + diff &&
-                                      atom_EQ(BUNtail(bi, cur - diff), v, 
b->ttype))
+                                      atom_EQ(BUNtail(bi, use_orderidx ? *(oid 
*)BUNtail(bio, cur - diff) - b->hseqbase + BUNfirst(b) : cur - diff), v, 
b->ttype))
                                        cur -= diff;
                        }
                }
@@ -878,7 +881,7 @@ SORTfndwhich(BAT *b, const void *v, enum
                        /* shift over multiple equals */
                        for (diff = (end - cur) >> 1; diff; diff >>= 1) {
                                while (cur + diff < end &&
-                                      atom_EQ(BUNtail(bi, cur + diff), v, 
b->ttype))
+                                      atom_EQ(BUNtail(bi, use_orderidx ? *(oid 
*)BUNtail(bio, cur + diff) - b->hseqbase + BUNfirst(b) : cur + diff), v, 
b->ttype))
                                        cur += diff;
                        }
                }
@@ -891,6 +894,7 @@ SORTfndwhich(BAT *b, const void *v, enum
                }
                break;
        }
+       if (use_orderidx) BBPunfix(o->batCacheid);
        return cur;
 }
 
diff --git a/gdk/gdk_select.c b/gdk/gdk_select.c
--- a/gdk/gdk_select.c
+++ b/gdk/gdk_select.c
@@ -1414,9 +1414,10 @@ BATsubselect(BAT *b, BAT *s, const void 
                }
        }
 
-       if (b->tsorted || b->trevsorted) {
+       if (b->tsorted || b->trevsorted || b->torderidx.flags) {
                BUN low = 0;
                BUN high = b->batCount;
+               int use_orderidx = b->torderidx.flags && !(b->tsorted || 
b->trevsorted);
 
                if (BATtdense(b)) {
                        /* positional */
@@ -1449,7 +1450,7 @@ BATsubselect(BAT *b, BAT *s, const void 
                                low = (BUN) l;
                        if (low > high)
                                low = high;
-               } else if (b->tsorted) {
+               } else if (b->tsorted || use_orderidx) {
                        ALGODEBUG fprintf(stderr, "#BATsubselect(b=%s#" BUNFMT
                                          ",s=%s%s,anti=%d): sorted\n",
                                          BATgetId(b), BATcount(b),
@@ -1458,19 +1459,19 @@ BATsubselect(BAT *b, BAT *s, const void 
                                          anti);
                        if (lval) {
                                if (li)
-                                       low = SORTfndfirst(b, tl);
+                                       low = use_orderidx?ORDERfndfirst(b, 
tl):SORTfndfirst(b, tl);
                                else
-                                       low = SORTfndlast(b, tl);
+                                       low = use_orderidx?ORDERfndlast(b, 
tl):SORTfndlast(b, tl);
                        } else {
                                /* skip over nils at start of column */
-                               low = SORTfndlast(b, nil);
+                               low = use_orderidx?ORDERfndlast(b, 
nil):SORTfndlast(b, nil);
                        }
                        low -= BUNfirst(b);
                        if (hval) {
                                if (hi)
-                                       high = SORTfndlast(b, th);
+                                       high = use_orderidx?ORDERfndlast(b, 
th):SORTfndlast(b, th);
                                else
-                                       high = SORTfndfirst(b, th);
+                                       high = use_orderidx?ORDERfndfirst(b, 
th):SORTfndfirst(b, th);
                                high -= BUNfirst(b);
                        }
                } else {
@@ -1544,9 +1545,19 @@ BATsubselect(BAT *b, BAT *s, const void 
                                high = SORTfndfirst(s, &o) - BUNfirst(s);
                                bn = doubleslice(s, 0, 0, low, high);
                        } else {
-                               bn = doublerange(0, 0,
-                                                low + b->hseqbase,
-                                                high + b->hseqbase);
+                               if (use_orderidx) {
+                                       BAT *order;
+
+                                       if ((order = 
BBPdescriptor(b->torderidx.o)) == NULL) {
+                                               GDKerror("Runtime object (order 
index) not found");
+                                       }
+                                       bn = BATslice(order, low + 
order->hseqbase, high + order->hseqbase);
+                                       BATorder(bn);
+                               } else {
+                                       bn = doublerange(0, 0,
+                                                        low + b->hseqbase,
+                                                        high + b->hseqbase);
+                               }
                        }
                }
                bn->hseqbase = 0;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to