Changeset: ad93a4a35c6e for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ad93a4a35c6e
Modified Files:
monetdb5/modules/kernel/algebra.mx
sql/backends/monet5/sql_gencode.c
sql/test/Skyserver/runv6.all
sql/test/Tests/rank.stable.out
sql/test/Tests/setoptimizer.stable.out
Branch: default
Log Message:
join, antijoin, thetajoin and crossproduct now have versions which return
two columns.
diffs (truncated from 683 to 300 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
@@ -529,9 +529,40 @@ comment "Returns the union of two BATs;
command tunion ( left:bat[:any_1,:any_2], right:bat[:any_1,:any_2])
:bat[:any_1,:any_2]
address ALGtunion;
+
+
# @+ Join operations
# The core of every relational engine.
# The join collection provided by the GDK kernel.
+command antijoin( left:bat[:oid,:any_1], right:bat[:oid,:any_1])
+ (l:bat[:oid,:oid],r:bat[:oid,:oid])
+address ALGantijoin2
+comment "Returns 2 columns with all BUNs, consisting of the head-oids
+ from 'left' and 'right' for which there are BUNs in 'left'
+ and 'right' with equal tails";
+
+command join( left:bat[:oid,:any_1], right:bat[:oid,:any_1])
+ (l:bat[:oid,:oid],r:bat[:oid,:oid])
+address ALGjoin2
+comment "Returns 2 columns with all BUNs, consisting of the head-oids
+ from 'left' and 'right' for which there are BUNs in 'left'
+ and 'right' with equal tails";
+
+# @- Theta Join
+command thetajoin( left:bat[:oid,:any_1], right:bat[:oid,:any_1], opname:int)
+ (l:bat[:oid,:oid],r:bat[:oid,:oid])
+address ALGthetajoin2
+comment "Returns 2 columns with all BUNs, consisting of the head-oids
+ from 'left' and 'right' for which there are BUNs in 'left'
+ and 'right' with equal tails";
+
+command crossproduct( left:bat[:oid,:any_1], right:bat[:oid,:any_2])
+ (l:bat[:oid,:oid],r:bat[:oid,:oid])
+address ALGcrossproduct2
+comment "Returns 2 columns with all BUNs, consisting of the head-oids
+ from 'left' and 'right' for which there are BUNs in 'left'
+ and 'right' with equal tails";
+
# 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]
@@ -1070,6 +1101,12 @@ algebra_export str ALGselectInclusiveHea
algebra_export str ALGuselectInclusive(int *result, int *bid, ptr low, ptr
high, bit *lin, bit *rin);
algebra_export str ALGantiuselectInclusive(int *result, int *bid, ptr low, ptr
high, bit *lin, bit *rin);
algebra_export str ALGfragment(int *result, int *bid, ptr hlow, ptr hhigh, ptr
tlow, ptr thigh);
+
+algebra_export str ALGantijoin2(int *l, int *r, int *lid, int *rid);
+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 ALGthetajoinEstimate(int *result, int *lid, int *rid, int
*opc, lng *estimate);
algebra_export str ALGthetajoin(int *result, int *lid, int *rid, int *opc);
algebra_export str ALGbandjoin_default(int *result, int *lid, int *rid, ptr
*minus, ptr *plus);
@@ -2706,6 +2743,126 @@ ALGantijoin(bat *result, bat *lid, bat *
}
str
+ALGantijoin2( bat *l, bat *r, bat *left, bat *right)
+{
+ BAT *L, *R, *j;
+
+ if ((L = BATdescriptor(*left)) == NULL) {
+ throw(MAL, "algebra.antijoin", RUNTIME_OBJECT_MISSING);
+ }
+ if ((R = BATdescriptor(*right)) == NULL) {
+ BBPunfix(L->batCacheid);
+ throw(MAL, "algebra.antijoin", RUNTIME_OBJECT_MISSING);
+ }
+
+ /* j = antijoin(left,reverse(right))
+ l = reverse(mark(j))
+ r = reverse(mark(reverse(j)))
+ */
+ j = BATantijoin(L, BATmirror(R));
+ if (!j)
+ throw(MAL, "algebra.antijoin", 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
+ALGjoin2( bat *l, bat *r, bat *left, bat *right)
+{
+ BAT *L, *R, *j;
+
+ if ((L = BATdescriptor(*left)) == NULL) {
+ throw(MAL, "algebra.join", RUNTIME_OBJECT_MISSING);
+ }
+ if ((R = BATdescriptor(*right)) == NULL) {
+ BBPunfix(L->batCacheid);
+ throw(MAL, "algebra.join", RUNTIME_OBJECT_MISSING);
+ }
+
+ /* j = join(left,reverse(right))
+ l = reverse(mark(j))
+ r = reverse(mark(reverse(j)))
+ */
+ j = BATjoin(L, BATmirror(R), BUN_NONE);
+ if (!j)
+ throw(MAL, "algebra.join", 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
+ALGthetajoin2( bat *l, bat *r, bat *left, bat *right, int *opc)
+{
+ BAT *L, *R, *j;
+
+ if ((L = BATdescriptor(*left)) == NULL) {
+ throw(MAL, "algebra.thetajoin", RUNTIME_OBJECT_MISSING);
+ }
+ if ((R = BATdescriptor(*right)) == NULL) {
+ BBPunfix(L->batCacheid);
+ throw(MAL, "algebra.thetajoin", RUNTIME_OBJECT_MISSING);
+ }
+
+ /* j = thetajoin(left,reverse(right), opc)
+ l = reverse(mark(j))
+ r = reverse(mark(reverse(j)))
+ */
+ j = BATthetajoin(L, BATmirror(R), *opc, lng_nil);
+ if (!j)
+ throw(MAL, "algebra.thetajoin", 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
+ALGcrossproduct2( bat *l, bat *r, bat *left, bat *right)
+{
+ BAT *L, *R, *j;
+
+ if ((L = BATdescriptor(*left)) == NULL) {
+ throw(MAL, "algebra.crossproduct", RUNTIME_OBJECT_MISSING);
+ }
+ if ((R = BATdescriptor(*right)) == NULL) {
+ BBPunfix(L->batCacheid);
+ throw(MAL, "algebra.crossproduct", RUNTIME_OBJECT_MISSING);
+ }
+
+ /* j = crossproduct(left,reverse(right))
+ l = reverse(mark(j))
+ r = reverse(mark(reverse(j)))
+ */
+ j = BATcross(L, BATmirror(R));
+ if (!j)
+ throw(MAL, "algebra.crossproduct", 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
ALGjoinestimate(bat *result, bat *lid, bat *rid, lng *estimate)
{
return ALGbinaryestimate(result, lid, rid, estimate, BATjoin,
"algebra.join");
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
@@ -1211,9 +1211,9 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
sub = _dumpstmt(sql, mb, s->op4.stval);
if ((s->op2->nrcols > 0 || s->op3->nrcols) && (s->type
== st_uselect2)) {
+ int k;
char *mod = calcRef;
char *op1 = "<", *op2 = "<";
- int k;
r1 = _dumpstmt(sql, mb, s->op2);
r2 = _dumpstmt(sql, mb, s->op3);
@@ -1258,18 +1258,6 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
cmd = bandjoinRef;
}
-/* TODO REMOVE
- if (s->op2->type == st_atom &&
- s->op3->type == st_atom &&
- atom_null(s->op2->op4.aval) &&
- atom_null(s->op3->op4.aval)
- ) {
- q = newStmt2(mb, algebraRef, selectNotNilRef);
- q = pushArgument(mb, q, l);
- s->nr = getDestVar(q);
- break;
- }
-*/
if (!rs) {
r1 = _dumpstmt(sql, mb, s->op2);
r2 = _dumpstmt(sql, mb, s->op3);
@@ -1357,8 +1345,8 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
}
break;
case st_join:{
- int l = _dumpstmt(sql, mb, s->op1), j;
- int r = _dumpstmt(sql, mb, s->op2), mhj, mtj;
+ int l = _dumpstmt(sql, mb, s->op1);
+ int r = _dumpstmt(sql, mb, s->op2);
char *jt = "join", *nme;
assert(l >= 0 && r >= 0);
@@ -1376,54 +1364,51 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
return s->nr;
}
- q = newStmt2(mb, batRef, reverseRef);
- q = pushArgument(mb, q, r);
- r = getDestVar(q);
switch (s->flag) {
case cmp_equal:
q = newStmt1(mb, algebraRef, jt);
-
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
break;
case cmp_notequal:
q = newStmt1(mb, algebraRef, "antijoin");
-
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
break;
case cmp_lt:
q = newStmt1(mb, algebraRef, "thetajoin");
-
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
q = pushInt(mb, q, -1);
break;
case cmp_lte:
q = newStmt1(mb, algebraRef, "thetajoin");
-
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
q = pushInt(mb, q, -2);
break;
case cmp_gt:
q = newStmt1(mb, algebraRef, "thetajoin");
-
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
q = pushInt(mb, q, 1);
break;
case cmp_gte:
q = newStmt1(mb, algebraRef, "thetajoin");
-
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
q = pushInt(mb, q, 2);
break;
case cmp_all: /* aka cross table */
- //q = dump_crossproduct(mb, l, r);
q = newStmt2(mb, algebraRef, crossRef);
+ q = pushReturn(mb, q, newTmpVariable(mb,
TYPE_any));
q = pushArgument(mb, q, l);
q = pushArgument(mb, q, r);
break;
@@ -1434,29 +1419,12 @@ _dumpstmt(backend *sql, MalBlkPtr mb, st
default:
showException(GDKout, SQL,"sql","SQL2MAL: error
impossible\n");
}
- j = getDestVar(q);
-
- q = newStmt2(mb, algebraRef, markTRef);
- q = pushArgument(mb, q, j);
- q = pushOid(mb, q, 0);
- mtj = getDestVar(q);
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list