Changeset: 7e5a158b9a4d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7e5a158b9a4d
Modified Files:
        gdk/gdk_rangejoin.c
Branch: headless
Log Message:

Deal with nil values in the inputs of band and range join.
In rangejoin, if l is nil, it doesn't match, and if rl or rh is nil,
they stand for minus/plus infinity.
In bandjoin, nils don't match.


diffs (120 lines):

diff --git a/gdk/gdk_rangejoin.c b/gdk/gdk_rangejoin.c
--- a/gdk/gdk_rangejoin.c
+++ b/gdk/gdk_rangejoin.c
@@ -22,8 +22,8 @@
  * @a N. J. Nes
  *
  * @* Range Join Operators
- * The sql statement b.x <= a.z <= b.y, could be implemented using too 
thetajoins.
- * But that results in very large intermediates.
+ * The sql statement b.x <= a.z <= b.y, could be implemented using two
+ * thetajoins.  But that results in very large intermediates.
  *
  */
 
@@ -43,6 +43,7 @@
        oid v, w;
        int (*cmp)(void*,void*);
        ptr x1;
+       ptr nil;
 
        ERRORcheck(l == NULL, "COLrangejoin: invalid left operand\n");
        ERRORcheck(rl == NULL, "COLrangejoin: invalid right low operand\n");
@@ -67,37 +68,48 @@
        rli = col_iterator(rl);
        rhi = col_iterator(rh);
        cmp = COLatoms[l->type].atomCmp;
+       nil = ATOMnilptr(l->type);
 
        COLloop(l, p, q) {
                x1 = BUNhead(lit, p);
+               if (cmp(x1, nil) == 0)
+                       continue;
                if (li && hi) {
                        COLloop(rl, v, w) {
-                               if (cmp(x1, BUNhead(rli, v)) >= 0  &&
-                                   cmp(x1, BUNhead(rhi, v)) <= 0) {
+                               if ((cmp(BUNhead(rli, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rli, v)) >= 0) &&
+                                   (cmp(BUNhead(rhi, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rhi, v)) <= 0)) {
                                        bunfastins_oid(bn1, p - l->first);
                                        bunfastins_oid(bn2, v - rl->first);
                                }
                        }
                } else if (li && !hi) {
                        COLloop(rl, v, w) {
-                               if (cmp(x1, BUNhead(rli, v)) >= 0  &&
-                                   cmp(x1, BUNhead(rhi, v)) < 0) {
+                               if ((cmp(BUNhead(rli, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rli, v)) >= 0) &&
+                                   (cmp(BUNhead(rhi, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rhi, v)) < 0)) {
                                        bunfastins_oid(bn1, p - l->first);
                                        bunfastins_oid(bn2, v - rl->first);
                                }
                        }
                } else if (!li && hi) {
                        COLloop(rl, v, w) {
-                               if (cmp(x1, BUNhead(rli, v)) > 0  &&
-                                   cmp(x1, BUNhead(rhi, v)) <= 0) {
+                               if ((cmp(BUNhead(rli, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rli, v)) > 0) &&
+                                   (cmp(BUNhead(rhi, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rhi, v)) <= 0)) {
                                        bunfastins_oid(bn1, p - l->first);
                                        bunfastins_oid(bn2, v - rl->first);
                                }
                        }
                } else {
                        COLloop(rl, v, w) {
-                               if (cmp(x1, BUNhead(rli, v)) > 0  &&
-                                   cmp(x1, BUNhead(rhi, v)) < 0) {
+                               if ((cmp(BUNhead(rli, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rli, v)) > 0) &&
+                                   (cmp(BUNhead(rhi, v), nil) == 0 ||
+                                    cmp(x1, BUNhead(rhi, v)) < 0)) {
                                        bunfastins_oid(bn1, p - l->first);
                                        bunfastins_oid(bn2, v - rl->first);
                                }
@@ -155,9 +167,13 @@
                                                                        \
                for (p = 0; p < l->count; p++) {                        \
                        x1 = COLget_TYPE(l, p, TYPE);                   \
+                       if (x1 == TYPE##_nil)                           \
+                               continue;                               \
                        if (li && hi) {                                 \
                                for (v = 0; v < r->count; v++) {        \
                                        x2 = COLget_TYPE(r, v, TYPE);   \
+                                       if (x2 == TYPE##_nil)           \
+                                               continue;               \
                                        if (x1 >= x2 - cc1 &&           \
                                            x1 <= x2 + cc2) {           \
                                                bunfastins_oid(bn1, p); \
@@ -167,6 +183,8 @@
                        } else if (li && !hi) {                         \
                                for (v = 0; v < r->count; v++) {        \
                                        x2 = COLget_TYPE(r, v, TYPE);   \
+                                       if (x2 == TYPE##_nil)           \
+                                               continue;               \
                                        if (x1 >= x2 - cc1 &&           \
                                            x1 < x2 + cc2) {            \
                                                bunfastins_oid(bn1, p); \
@@ -176,6 +194,8 @@
                        } else if (!li && hi) {                         \
                                for (v = 0; v < r->count; v++) {        \
                                        x2 = COLget_TYPE(r, v, TYPE);   \
+                                       if (x2 == TYPE##_nil)           \
+                                               continue;               \
                                        if (x1 > x2 - cc1 &&            \
                                            x1 <= x2 + cc2) {           \
                                                bunfastins_oid(bn1, p); \
@@ -185,6 +205,8 @@
                        } else {                                        \
                                for (v = 0; v < r->count; v++) {        \
                                        x2 = COLget_TYPE(r, v, TYPE);   \
+                                       if (x2 == TYPE##_nil)           \
+                                               continue;               \
                                        if (x1 > x2 - cc1 &&            \
                                            x1 < x2 + cc2) {            \
                                                bunfastins_oid(bn1, p); \
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to