Changeset: 23cf870c73b2 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=23cf870c73b2
Modified Files:
        monetdb5/modules/kernel/algebra.mx
        sql/backends/monet5/sql_gencode.c
        sql/server/sql_rel2bin.c
        
sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out
Branch: default
Log Message:

cleanup range/band join interface.
fixed bug in leftjoin vs leftfetchjoin


diffs (203 lines):

diff --git a/monetdb5/modules/kernel/algebra.mx 
b/monetdb5/modules/kernel/algebra.mx
--- a/monetdb5/modules/kernel/algebra.mx
+++ b/monetdb5/modules/kernel/algebra.mx
@@ -563,6 +563,19 @@ comment "Returns 2 columns with all BUNs
          from 'left' and 'right' for which there are BUNs in 'left' 
          and 'right' with equal tails";
 
+command bandjoin( outer:bat[:oid,:any_2], inner:bat[:oid,:any_3], minus:any_2 
, plus:any_2, li:bit, hi:bit ) 
+               (l:bat[:oid,:oid],r:bat[:oid,:oid])
+address ALGbandjoin2
+comment "This is a join() for which the predicate is that two BUNs match 
+               if the left-tail value is within the range [right-head - minus, 
+               right-head + plus], depending on (l_in/h_in), the bounds 
+               are included. Works only for the builtin numerical types, 
+               and their derivates.";
+
+command join(left:bat[:oid,:any_2], rl:bat[:oid,:any_2], rh:bat[:oid,:any_2], 
li:bit, hi:bit) 
+               (l:bat[:oid,:oid],r:bat[:oid,:oid])
+address ALGrangejoin2;
+
 # Note that joins over void columns are handled as if they are oids.
 command crossproduct(left:bat[:any_1,:any_2], right:bat[:any_3,:any_4])
        :bat[:any_1,:any_4]
@@ -1106,6 +1119,8 @@ algebra_export str ALGantijoin2(int *l, 
 algebra_export str ALGjoin2(int *l, int *r, int *lid, int *rid);
 algebra_export str ALGthetajoin2(int *l, int *r, int *lid, int *rid, int *opc);
 algebra_export str ALGcrossproduct2(int *l, int *r, int *lid, int *rid);
+algebra_export str ALGbandjoin2(int *l, int *r, int *lid, int *rid, ptr 
*minus, ptr *plus, bit *li, bit *hi);
+algebra_export str ALGrangejoin2(int *l, int *r, int *lid, int *rlid, int 
*rhid, bit *li, bit *hi);
 
 algebra_export str ALGthetajoinEstimate(int *result, int *lid, int *rid, int 
*opc, lng *estimate);
 algebra_export str ALGthetajoin(int *result, int *lid, int *rid, int *opc);
@@ -2861,6 +2876,71 @@ ALGcrossproduct2( bat *l, bat *r, bat *l
        BBPkeepref(*r = R->batCacheid);
        return MAL_SUCCEED;
 }
+str
+ALGbandjoin2(bat *l, bat *r, bat *left, bat *right, ptr *minus, ptr *plus, bit 
*li, bit *hi)
+{
+       BAT *L, *R, *j;
+
+       if ((L = BATdescriptor(*left)) == NULL) {
+               throw(MAL, "algebra.bandjoin", RUNTIME_OBJECT_MISSING);
+       }
+       if ((R = BATdescriptor(*right)) == NULL) {
+               BBPunfix(L->batCacheid);
+               throw(MAL, "algebra.bandjoin", RUNTIME_OBJECT_MISSING);
+       }
+
+       /* j = bandjoin(left,reverse(right), minus, plus, li, hi)
+          l = reverse(mark(j))
+          r = reverse(mark(reverse(j)))
+       */
+       j = BATbandjoin(L, BATmirror(R), minus, plus, *li, *hi);
+       if (!j)
+               throw(MAL, "algebra.bandjoin", GDK_EXCEPTION);
+       BBPunfix(L->batCacheid);
+       BBPunfix(R->batCacheid);
+       L = BATmirror(BATmark(j,0));
+       R = BATmirror(BATmark(BATmirror(j),0));
+       BBPunfix(j->batCacheid);
+       BBPkeepref(*l = L->batCacheid);
+       BBPkeepref(*r = R->batCacheid);
+       return MAL_SUCCEED;
+}
+
+str 
+ALGrangejoin2(int *l, int *r, int *left, int *rightl, int *righth, bit *li, 
bit *hi)
+{
+       BAT *L, *R, *RL, *RH, *j;
+
+       if ((L = BATdescriptor(*left)) == NULL) {
+               throw(MAL, "algebra.join", RUNTIME_OBJECT_MISSING);
+       }
+       if ((RL = BATdescriptor(*rightl)) == NULL) {
+               BBPunfix(L->batCacheid);
+               throw(MAL, "algebra.join", RUNTIME_OBJECT_MISSING);
+       }
+       if ((RH = BATdescriptor(*righth)) == NULL) {
+               BBPunfix(L->batCacheid);
+               BBPunfix(RL->batCacheid);
+               throw(MAL, "algebra.join", RUNTIME_OBJECT_MISSING);
+       }
+
+       /* j = join(left,rightl,righth, li, hi)
+          l = reverse(mark(j))
+          r = reverse(mark(reverse(j)))
+       */
+       j = BATrangejoin(L, RL, RH, *li, *hi);
+       if (!j)
+               throw(MAL, "algebra.join", GDK_EXCEPTION);
+       BBPunfix(L->batCacheid);
+       BBPunfix(RL->batCacheid);
+       BBPunfix(RH->batCacheid);
+       L = BATmirror(BATmark(j,0));
+       R = BATmirror(BATmark(BATmirror(j),0));
+       BBPunfix(j->batCacheid);
+       BBPkeepref(*l = L->batCacheid);
+       BBPkeepref(*r = R->batCacheid);
+       return MAL_SUCCEED;
+}
 
 str
 ALGjoinestimate(bat *result, bat *lid, bat *rid, lng *estimate)
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
@@ -1199,12 +1199,9 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
                        InstrPtr r,p;
                        int l = _dumpstmt(sql, mb, s->op1);
                        stmt *base, *low = NULL, *high = NULL;
-                       int r1 = -1, r2 = -1, rs = 0, j, mtj, mhj;
+                       int r1 = -1, r2 = -1, rs = 0;
                        bit anti = (s->flag&ANTI)?TRUE:FALSE;
-                       char *cmd = 
-                               (s->type == st_uselect2) ?
-                               "subselect":
-                               "join", *nme;
+                       char *cmd = (s->type == st_uselect2) ?  "subselect": 
"join", *nme;
                        int sub = -1;
 
                        if (s->op4.stval)
@@ -1244,9 +1241,6 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
                            range_join_convertable(s, &base, &low, &high)) {
                                int tt = tail_type(base)->type->localtype;
                                rs = _dumpstmt(sql, mb, base);
-                               q = newStmt2(mb, batRef, reverseRef);
-                               q = pushArgument(mb, q, rs);
-                               rs = getDestVar(q);
                                if (low)
                                        r1 = _dumpstmt(sql, mb, low);
                                else
@@ -1263,6 +1257,8 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
                                r2 = _dumpstmt(sql, mb, s->op3);
                        }
                        q = newStmt1(mb, algebraRef, cmd);
+                       if (s->type == st_join2)
+                               q = pushReturn(mb, q, newTmpVariable(mb, 
TYPE_any));
                        q = pushArgument(mb, q, l);
                        if (sub > 0)
                                q = pushArgument(mb, q, sub);
@@ -1294,33 +1290,14 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
                                s->nr = getDestVar(q);
                                break;
                        }
-
-                       j = getDestVar(q);
-
-                       q = newStmt2(mb, algebraRef, markTRef);
-                       q = pushArgument(mb, q, j);
-                       q = pushOid(mb, q, 0);
-                       mtj = getDestVar(q);
-
-                       q = newStmt2(mb, batRef, reverseRef );
-                       q = pushArgument(mb, q, mtj);
-                       mtj = getDestVar(q);
-                       if (q)
-                               s->nr = getDestVar(q);
-
-                       q = newStmt2(mb, algebraRef, markHRef);
-                       q = pushArgument(mb, q, j);
-                       q = pushOid(mb, q, 0);
-                       mhj = getDestVar(q);
+                       s->nr = getDestVar(q);
 
                        /* rename second result */
                        nme = GDKmalloc(SMALLBUFSIZ);
                        snprintf(nme, SMALLBUFSIZ, "r1_%d", s->nr);
-                       renameVariable(mb, mhj, nme);
-
+                       renameVariable(mb, getArg(q,1), nme);
                        break;
                }
-                       break;
                case st_joinN:
                        s->nr = dump_joinN(sql, mb, s);
                        break;
diff --git a/sql/server/sql_rel2bin.c b/sql/server/sql_rel2bin.c
--- a/sql/server/sql_rel2bin.c
+++ b/sql/server/sql_rel2bin.c
@@ -79,8 +79,8 @@ releqjoin( mvc *sql, int flag, list *l1,
        for (; n1 && n2; n1 = n1->next, n2 = n2->next) {
                stmt *ld = n1->data;
                stmt *rd = n2->data;
-               stmt *le = stmt_project(sql->sa, l, ld );
-               stmt *re = stmt_project(sql->sa, r, rd );
+               stmt *le = stmt_reorder_project(sql->sa, l, ld );
+               stmt *re = stmt_reorder_project(sql->sa, r, rd );
                /* intentional both tail_type's of le (as re sometimes is a
                   find for bulk loading */
                sql_subfunc *f=sql_bind_func(sql->sa, sql->session->schema, 
"=", tail_type(le), tail_type(le), F_FUNC);
diff --git 
a/sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out 
b/sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out
--- 
a/sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out
+++ 
b/sql/test/BugTracker-2009/Tests/use_order_column_first.SF-2686008.stable.out
@@ -53,7 +53,7 @@ Ready.
 project (
 | group by (
 | | table(sys.sorted) [ sorted.a, sorted.b, sorted.%TID% NOT NULL ] COUNT 
-| ) [ sorted.a, sorted.b ] [ sorted.a, sorted.b ]
+| ) [ sorted.b, sorted.a ] [ sorted.a, sorted.b ]
 ) [ sorted.a, sorted.b ]
 % .plan # table_name
 % rel # name
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to