Changeset: 557cb9d44457 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/557cb9d44457
Modified Files:
clients/Tests/MAL-signatures-hge.test
clients/Tests/MAL-signatures.test
monetdb5/modules/kernel/algebra.c
sql/backends/monet5/rel_pphash.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
sql/test/subquery/Tests/subquery3.test
Branch: default
Log Message:
fixed multi-column NOT IN with NULLs in a SELECT-clause => it's an outer-m-anti,
so we need to return all LHS rows.
- renamed algebra.selectNotFalse/ALGselectNotFalse into
algebra.markselect/ALGmarkselect2, since it no longer select only the not-false
rows, and has become a special case of markselect
- extended subquery3.test with some example queries
diffs (232 lines):
diff --git a/clients/Tests/MAL-signatures-hge.test
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -712,6 +712,7 @@ algebra likeselect command algebra.likes
algebra markjoin command algebra.markjoin(X_0:bat[:any_1],
X_1:bat[:any_1], X_2:bat[:oid], X_3:bat[:oid], X_4:bit, X_5:lng)
(X_6:bat[:oid], X_7:bat[:bit]) ALGmark2join Mark join with candidate
lists
algebra markjoin command algebra.markjoin(X_0:bat[:any_1],
X_1:bat[:any_1], X_2:bat[:oid], X_3:bat[:oid], X_4:bit, X_5:lng)
(X_6:bat[:oid], X_7:bat[:oid], X_8:bat[:bit]) ALGmark3join Mark join
with candidate lists
algebra markselect command algebra.markselect(X_0:bat[:oid],
X_1:bat[:bit], X_2:bat[:bit], X_3:bit) (X_4:bat[:oid], X_5:bat[:bit])
ALGmarkselect Group on group-ids, return aggregated anyequal or allnotequal
+algebra markselect command algebra.markselect(X_0:bat[:oid],
X_1:bat[:bit], X_2:bat[:bit], X_3:bit, X_4:bit) (X_5:bat[:oid], X_6:bat[:bit])
ALGmarkselect2 Return (gid, mark&&pred). If 'aggr', group on gid, return
aggregated (gid, mark&&pred). If 'outer', return a row for each (grouped) gid;
otherwise, return only the rows where mark&&pred != FALSE.
algebra not_like command algebra.not_like(X_0:str, X_1:str,
X_2:str, X_3:bit):bit PCREnotlike (empty)
algebra orderidx command algebra.orderidx(X_0:bat[:any_1],
X_1:bit):bat[:any_1] OIDXorderidx Create an order index
algebra outercrossproduct command
algebra.outercrossproduct(X_0:bat[:any_1], X_1:bat[:any_2], X_2:bat[:oid],
X_3:bat[:oid], X_4:bit) (X_5:bat[:oid], X_6:bat[:oid])
ALGoutercrossproduct3 Compute the outer cross product of both input bats
@@ -729,7 +730,6 @@ algebra select command algebra.select(X_
algebra select command algebra.select(X_0:bat[:any_1], X_1:any_1,
X_2:any_1, X_3:bit, X_4:bit, X_5:bit, X_6:bit):bat[:oid] ALGselect1nil
With unknown set, each nil != nil
algebra select command algebra.select(X_0:bat[:any_1], X_1:bat[:oid],
X_2:any_1, X_3:any_1, X_4:bit, X_5:bit, X_6:bit):bat[:oid] ALGselect2
Select all head values of the first input BAT for which the tail value is in
range and for which the head value occurs in the tail of the second input BAT.
The first input is a dense-headed BAT, the second input is a dense-headed BAT
with sorted tail, output is a dense-headed BAT with in the tail the head value
of the input BAT for which the tail value is between the values low and high
(inclusive if li respectively hi is set). The output BAT is sorted on the tail
value. If low or high is nil, the boundary is not considered (effectively -
and + infinity). If anti is set, the result is the complement. Nil values in
the tail are never matched, unless low=nil, high=nil, li=1, hi=1, anti=0. All
non-nil values are returned if low=nil, high=nil, and li, hi are not both 1, or
anti=1. Note that the output is suitable as second input for this functi
on.
algebra select command algebra.select(X_0:bat[:any_1], X_1:bat[:oid],
X_2:any_1, X_3:any_1, X_4:bit, X_5:bit, X_6:bit, X_7:bit):bat[:oid]
ALGselect2nil With unknown set, each nil != nil
-algebra selectNotFalse command algebra.selectNotFalse(X_0:bat[:oid],
X_1:bat[:bit], X_2:bat[:bit], X_3:bit) (X_4:bat[:oid], X_5:bat[:bit])
ALGselectNotFalse Return (gid, mark&&pred), if mark&&pred != FALSE. If
'aggr', group on gid, return aggregated (gid, mark&&pred)
algebra selectNotNil command
algebra.selectNotNil(X_0:bat[:any_1]):bat[:any_1] ALGselectNotNil Select
all not-nil values
algebra semijoin command algebra.semijoin(X_0:bat[:any_1],
X_1:bat[:any_1], X_2:bat[:oid], X_3:bat[:oid], X_4:bit, X_5:bit, X_6:lng)
(X_7:bat[:oid], X_8:bat[:oid]) ALGsemijoin Semi join with candidate
lists
algebra single command algebra.single(X_0:bat[:oid],
X_1:bat[:oid]):bat[:oid] ALGsingle Check for single result ids.
diff --git a/clients/Tests/MAL-signatures.test
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -599,6 +599,7 @@ algebra likeselect command algebra.likes
algebra markjoin command algebra.markjoin(X_0:bat[:any_1],
X_1:bat[:any_1], X_2:bat[:oid], X_3:bat[:oid], X_4:bit, X_5:lng)
(X_6:bat[:oid], X_7:bat[:bit]) ALGmark2join Mark join with candidate
lists
algebra markjoin command algebra.markjoin(X_0:bat[:any_1],
X_1:bat[:any_1], X_2:bat[:oid], X_3:bat[:oid], X_4:bit, X_5:lng)
(X_6:bat[:oid], X_7:bat[:oid], X_8:bat[:bit]) ALGmark3join Mark join
with candidate lists
algebra markselect command algebra.markselect(X_0:bat[:oid],
X_1:bat[:bit], X_2:bat[:bit], X_3:bit) (X_4:bat[:oid], X_5:bat[:bit])
ALGmarkselect Group on group-ids, return aggregated anyequal or allnotequal
+algebra markselect command algebra.markselect(X_0:bat[:oid],
X_1:bat[:bit], X_2:bat[:bit], X_3:bit, X_4:bit) (X_5:bat[:oid], X_6:bat[:bit])
ALGmarkselect2 Return (gid, mark&&pred). If 'aggr', group on gid, return
aggregated (gid, mark&&pred). If 'outer', return a row for each (grouped) gid;
otherwise, return only the rows where mark&&pred != FALSE.
algebra not_like command algebra.not_like(X_0:str, X_1:str,
X_2:str, X_3:bit):bit PCREnotlike (empty)
algebra orderidx command algebra.orderidx(X_0:bat[:any_1],
X_1:bit):bat[:any_1] OIDXorderidx Create an order index
algebra outercrossproduct command
algebra.outercrossproduct(X_0:bat[:any_1], X_1:bat[:any_2], X_2:bat[:oid],
X_3:bat[:oid], X_4:bit) (X_5:bat[:oid], X_6:bat[:oid])
ALGoutercrossproduct3 Compute the outer cross product of both input bats
@@ -616,7 +617,6 @@ algebra select command algebra.select(X_
algebra select command algebra.select(X_0:bat[:any_1], X_1:any_1,
X_2:any_1, X_3:bit, X_4:bit, X_5:bit, X_6:bit):bat[:oid] ALGselect1nil
With unknown set, each nil != nil
algebra select command algebra.select(X_0:bat[:any_1], X_1:bat[:oid],
X_2:any_1, X_3:any_1, X_4:bit, X_5:bit, X_6:bit):bat[:oid] ALGselect2
Select all head values of the first input BAT for which the tail value is in
range and for which the head value occurs in the tail of the second input BAT.
The first input is a dense-headed BAT, the second input is a dense-headed BAT
with sorted tail, output is a dense-headed BAT with in the tail the head value
of the input BAT for which the tail value is between the values low and high
(inclusive if li respectively hi is set). The output BAT is sorted on the tail
value. If low or high is nil, the boundary is not considered (effectively -
and + infinity). If anti is set, the result is the complement. Nil values in
the tail are never matched, unless low=nil, high=nil, li=1, hi=1, anti=0. All
non-nil values are returned if low=nil, high=nil, and li, hi are not both 1, or
anti=1. Note that the output is suitable as second input for this functi
on.
algebra select command algebra.select(X_0:bat[:any_1], X_1:bat[:oid],
X_2:any_1, X_3:any_1, X_4:bit, X_5:bit, X_6:bit, X_7:bit):bat[:oid]
ALGselect2nil With unknown set, each nil != nil
-algebra selectNotFalse command algebra.selectNotFalse(X_0:bat[:oid],
X_1:bat[:bit], X_2:bat[:bit], X_3:bit) (X_4:bat[:oid], X_5:bat[:bit])
ALGselectNotFalse Return (gid, mark&&pred), if mark&&pred != FALSE. If
'aggr', group on gid, return aggregated (gid, mark&&pred)
algebra selectNotNil command
algebra.selectNotNil(X_0:bat[:any_1]):bat[:any_1] ALGselectNotNil Select
all not-nil values
algebra semijoin command algebra.semijoin(X_0:bat[:any_1],
X_1:bat[:any_1], X_2:bat[:oid], X_3:bat[:oid], X_4:bit, X_5:bit, X_6:lng)
(X_7:bat[:oid], X_8:bat[:oid]) ALGsemijoin Semi join with candidate
lists
algebra single command algebra.single(X_0:bat[:oid],
X_1:bat[:oid]):bat[:oid] ALGsingle Check for single result ids.
diff --git a/monetdb5/modules/kernel/algebra.c
b/monetdb5/modules/kernel/algebra.c
--- a/monetdb5/modules/kernel/algebra.c
+++ b/monetdb5/modules/kernel/algebra.c
@@ -478,7 +478,7 @@ ALGmarkselect(Client ctx, bat *r1, bat *
}
static str
-ALGselectNotFalse(Client ctx, bat *r1, bat *r2, const bat *gid, const bat
*mark, const bat *pred, const bit *Aggr)
+ALGmarkselect2(Client ctx, bat *r1, bat *r2, const bat *gid, const bat *mark,
const bat *pred, const bit *Aggr, const bit *Outer)
{
(void) ctx;
BAT *g = BATdescriptor(*gid); /* oid */
@@ -486,6 +486,7 @@ ALGselectNotFalse(Client ctx, bat *r1, b
BAT *p = BATdescriptor(*pred); /* bit */
BAT *res1 = NULL, *res2 = NULL;
bit aggr = *Aggr;
+ bit outer = *Outer;
if (!g || !m || !p)
goto error;
@@ -506,7 +507,7 @@ ALGselectNotFalse(Client ctx, bat *r1, b
for (BUN n = 0; n < nr; n++, c++) {
ri1[q] = c;
ri2[q] = (mi[n] == FALSE || pi[n] ==
FALSE)?FALSE:(mi[n] == bit_nil || pi[n] == bit_nil)?bit_nil:TRUE;
- q += (ri2[q] != FALSE); /* filter out the rows
that are surely FALSE */
+ q += ((ri2[q] != FALSE) /* filter out the rows
that are surely FALSE for !outer */ || outer);
}
} else { /* the aggregated variant */
oid *gi = Tloc(g, 0);
@@ -514,7 +515,7 @@ ALGselectNotFalse(Client ctx, bat *r1, b
bit m = (mi[0] == FALSE || pi[0] == FALSE)?FALSE:(mi[0]
== bit_nil || pi[0] == bit_nil)?bit_nil:TRUE;
bool all_unequal = (m == FALSE)?TRUE:FALSE;
for (BUN n = 1; n < nr; n++, c++) {
- if (cur != gi[n] && !all_unequal) {
+ if (cur != gi[n] && (!all_unequal || outer)) {
ri1[q] = c;
ri2[q] = m;
q++;
@@ -525,7 +526,7 @@ ALGselectNotFalse(Client ctx, bat *r1, b
m = (m == FALSE && (mi[n] == FALSE || pi[n] ==
FALSE))?FALSE:(m == bit_nil || mi[n] == bit_nil || pi[n] ==
bit_nil)?bit_nil:TRUE;
all_unequal = all_unequal & (m == FALSE);
}
- if (!all_unequal) {
+ if (!all_unequal || outer) {
ri1[q] = c;
ri2[q] = m;
q++;
@@ -2090,9 +2091,9 @@ static mel_func algebra_init_funcs[] = {
command("algebra", "select", ALGselect2nil, false, "With unknown set, each
nil != nil", args(1,9,
batarg("",oid),batargany("b",1),batarg("s",oid),argany("low",1),argany("high",1),arg("li",bit),arg("hi",bit),arg("anti",bit),arg("unknown",bit))),
command("algebra", "thetaselect", ALGthetaselect2, false, "Select all head
values of the first input BAT for which the tail value obeys the relation value
OP VAL and for which the head value occurs in the tail of the second input BAT.
Input is a dense-headed BAT, output is a dense-headed BAT with in the tail the
head value of the input BAT for which the relationship holds. The output BAT
is sorted on the tail value.", args(1,5,
batarg("",oid),batargany("b",1),batarg("s",oid),argany("val",1),arg("op",str))),
command("algebra", "markselect", ALGmarkselect, false, "Group on group-ids,
return aggregated anyequal or allnotequal", args(2,6, batarg("",oid),
batarg("", bit), batarg("gid",oid), batarg("m", bit), batarg("p", bit),
arg("any", bit))),
+ command("algebra", "markselect", ALGmarkselect2, false, "Return (gid,
mark&&pred). If 'aggr', group on gid, return aggregated (gid, mark&&pred). If
'outer', return a row for each (grouped) gid; otherwise, return only the rows
where mark&&pred != FALSE.", args(2,7, batarg("",oid), batarg("", bit),
batarg("gid", oid), batarg("mark", bit), batarg("pred", bit), arg('aggr',bit),
arg('outer',bit))),
command("algebra", "single", ALGsingle, false, "Check for single result
ids.", args(1,3, batarg("r",oid), batarg("cands", oid), batarg("i", oid))),
command("algebra", "outerselect", ALGouterselect, false, "Per input lid
return at least one row, if none of the predicates (p) hold, return a nil, else
'all' true cases.", args(2,7, batarg("",oid), batarg("", bit), batarg("lid",
oid), batarg("rid", bit), batarg("predicate", bit), arg("any", bit),
arg("single", bit))),
- command("algebra", "selectNotFalse", ALGselectNotFalse, false, "Return (gid,
mark&&pred), if mark&&pred != FALSE. If 'aggr', group on gid, return aggregated
(gid, mark&&pred)", args(2,6, batarg("",oid), batarg("", bit), batarg("gid",
oid), batarg("mark", bit), batarg("pred", bit), arg('aggr',bit))),
command("algebra", "selectNotNil", ALGselectNotNil, false, "Select all
not-nil values", args(1,2, batargany("",1),batargany("b",1))),
command("algebra", "sort", ALGsort11, false, "Returns a copy of the BAT
sorted on tail values. The order is descending if the reverse bit is set. This
is a stable sort if the stable bit is set.", args(1,5,
batargany("",1),batargany("b",1),arg("reverse",bit),arg("nilslast",bit),arg("stable",bit))),
command("algebra", "sort", ALGsort12, false, "Returns a copy of the BAT
sorted on tail values and a BAT that specifies how the input was reordered. The
order is descending if the reverse bit is set. This is a stable sort if the
stable bit is set.", args(2,6,
batargany("",1),batarg("",oid),batargany("b",1),arg("reverse",bit),arg("nilslast",bit),arg("stable",bit))),
diff --git a/sql/backends/monet5/rel_pphash.c b/sql/backends/monet5/rel_pphash.c
--- a/sql/backends/monet5/rel_pphash.c
+++ b/sql/backends/monet5/rel_pphash.c
@@ -651,8 +651,10 @@ rel2bin_oahash_select(backend *be, stmt
static stmt *
rel2bin_oahash_outerselect(backend *be, stmt *sub, list *sexps, sql_rel *rel,
stmt *probed_ids, stmt *hash_ids, stmt **prb_mrk, bool cart, bool mark, bool
manti)
{
- assert (is_outerjoin(rel->op) || !list_empty(rel->attr));
stmt *sel = NULL, *m = prb_mrk?*prb_mrk:NULL;
+ bool is_outerj = is_outerjoin(rel->op);
+
+ assert (is_outerj || !list_empty(rel->attr));
if (hash_ids && cart) {
/* 0 == empty (no matches possible), nil - no match (but has
nil), 1 match */
@@ -673,9 +675,9 @@ rel2bin_oahash_outerselect(backend *be,
if (sel)
lgids = stmt_project(be, sel, lgids);
stmt *outer = NULL;
- if (manti) {
+ if (manti) {// && !is_outerj) {
assert(m); assert(p);
- outer = stmt_selectNotFalse(be, lgids, m, p, !en->next);
+ outer = stmt_markselect2(be, lgids, m, p, !en->next,
is_outerj);
}
else if (en->next || !mark)
outer = stmt_outerselect(be, lgids, m, p, is_any(e),
!en->next && is_single(rel));
@@ -693,14 +695,28 @@ rel2bin_oahash_outerselect(backend *be,
if (prb_mrk)
*prb_mrk = m;
}
- if (manti) { /* do the reverse selection for the anti-joins */
- stmt *u = stmt_unique(be, probed_ids);
- if (!u) return NULL;
- stmt *asel = stmt_tdiff4(be, probed_ids, probed_ids, u, sel);
- if (!asel) return NULL;
- sel = asel;
- stmt *amrk = stmt_const(be, asel, stmt_bool(be, 1));
- *prb_mrk = amrk;
+ if (manti) {
+ if (is_outerj) { /* reverse prb_mrk for outer joins, retain all
probed_ids */
+ assert(prb_mrk && *prb_mrk);
+ InstrPtr q = newStmtArgs(be->mb, batcalcRef, notRef, 1);
+ if (!q) return NULL;
+ q = pushArgument(be->mb, q, (*prb_mrk)->nr);
+ pushInstruction(be->mb, q);
+ stmt *rmrk = stmt_none(be);
+ rmrk->op4.typeval = *sql_fetch_localtype(TYPE_bit);
+ rmrk->nrcols = 2;
+ rmrk->nr = q->argv[0];
+ rmrk->q = q;
+ *prb_mrk = rmrk;
+ } else { /* do the reverse selection for the anti-joins */
+ stmt *u = stmt_unique(be, probed_ids);
+ if (!u) return NULL;
+ stmt *asel = stmt_tdiff4(be, probed_ids, probed_ids, u,
sel);
+ if (!asel) return NULL;
+ sel = asel;
+ stmt *amrk = stmt_const(be, asel, stmt_bool(be, 1));
+ *prb_mrk = amrk;
+ }
}
return sel;
}
diff --git a/sql/backends/monet5/sql_statement.c
b/sql/backends/monet5/sql_statement.c
--- a/sql/backends/monet5/sql_statement.c
+++ b/sql/backends/monet5/sql_statement.c
@@ -2308,17 +2308,18 @@ stmt_markselect(backend *be, stmt *g, st
}
stmt *
-stmt_selectNotFalse(backend *be, stmt *g, stmt *m, stmt *p, bool aggr)
+stmt_markselect2(backend *be, stmt *g, stmt *m, stmt *p, bool aggr, bool outer)
{
MalBlkPtr mb = be->mb;
InstrPtr q;
- q = newStmtArgs(mb, algebraRef, putName("selectNotFalse"), 6);
+ q = newStmtArgs(mb, algebraRef, putName("markselect"), 7);
q = pushReturn(mb, q, newTmpVariable(mb, newBatType(TYPE_bit)));
q = pushArgument(mb, q, g->nr); /* group ids */
q = pushArgument(mb, q, m->nr); /* mark flag */
q = pushArgument(mb, q, p->nr); /* predicate */
q = pushBit(mb, q, (aggr)?TRUE:FALSE);
+ q = pushBit(mb, q, (outer)?TRUE:FALSE);
pushInstruction(mb, q);
if (!q)
diff --git a/sql/backends/monet5/sql_statement.h
b/sql/backends/monet5/sql_statement.h
--- a/sql/backends/monet5/sql_statement.h
+++ b/sql/backends/monet5/sql_statement.h
@@ -207,8 +207,8 @@ extern stmt *stmt_single(backend *be, st
extern stmt *stmt_outerselect(backend *be, stmt *g, stmt *m, stmt *p, bool
any, bool single);
extern stmt *stmt_thetaselect(backend *be, stmt *op1, stmt *op2, stmt *val,
const char *cmp, sql_subtype *tpe);
extern stmt *stmt_markselect(backend *be, stmt *g, stmt *m, stmt *p, bool any);
+extern stmt *stmt_markselect2(backend *be, stmt *g, stmt *m, stmt *p, bool
aggr, bool outer);
extern stmt *stmt_markjoin(backend *be, stmt *l, stmt *r, bool nil_matches,
bool final);
-extern stmt *stmt_selectNotFalse(backend *be, stmt *g, stmt *m, stmt *p, bool
aggr);
extern stmt *stmt_tunion(backend *be, stmt *op1, stmt *op2);
extern stmt *stmt_tdiff(backend *be, stmt *op1, stmt *op2, stmt *lcand);
diff --git a/sql/test/subquery/Tests/subquery3.test
b/sql/test/subquery/Tests/subquery3.test
--- a/sql/test/subquery/Tests/subquery3.test
+++ b/sql/test/subquery/Tests/subquery3.test
@@ -636,6 +636,31 @@ SELECT (col1, col2) NOT IN (SELECT 1,3)
1
1
+
+query I nosort
+SELECT (col1, col2) NOT IN (VALUES (NULL,2)) FROM another_T ORDER BY col1
+----
+0
+1
+1
+1
+
+query I nosort
+SELECT (col1, col2) NOT IN (SELECT 1,NULL) FROM another_T ORDER BY col1
+----
+0
+1
+1
+1
+
+query I nosort
+SELECT (col1, col2) NOT IN (SELECT NULL,3) FROM another_T
+----
+1
+1
+1
+1
+
query I rowsort
SELECT col1 FROM another_T WHERE (col2, col3) IN (SELECT col4, col5)
----
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]