Changeset: 244e990db72e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/244e990db72e
Added Files:
sql/test/BugTracker-2026/Tests/8095-double-negated-in.test
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/rel_physical.c
sql/backends/monet5/rel_pphash.c
sql/backends/monet5/rel_util.c
sql/backends/monet5/rel_util.h
sql/backends/monet5/sql_statement.c
sql/include/sql_catalog.h
sql/server/rel_dump.c
sql/server/rel_exp.c
sql/server/rel_exp.h
sql/server/rel_optimize_exps.c
sql/server/rel_optimize_join.c
sql/server/rel_optimize_others.c
sql/server/rel_optimize_proj.c
sql/server/rel_optimize_sel.c
sql/server/rel_optimizer.c
sql/server/rel_propagate.c
sql/server/rel_rel.c
sql/server/rel_rewriter.c
sql/server/rel_select.c
sql/server/rel_statistics.c
sql/server/rel_unnest.c
sql/server/rel_updates.c
sql/server/sql_partition.c
sql/test/BugTracker-2025/Tests/7737-join-order.test
sql/test/BugTracker-2026/Tests/All
Branch: default
Log Message:
removed notin and notequal, only use anti flag now (was redundant)
Also fixes the issue # 8095.
diffs (truncated from 2312 to 300 lines):
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -574,8 +574,6 @@ handle_in_exps(backend *be, sql_exp *ce,
stmt_const(be, bin_find_smallest_column(be,
left), s),
stmt_bool(be, 1), cmp_equal, sel, 0, 0);
} else if (list_length(nl) < 16) {
- comp_type cmp = (in)?cmp_equal:cmp_notequal;
-
if (!in)
s = sel;
for (n = nl->h; n; n = n->next) {
@@ -585,13 +583,13 @@ handle_in_exps(backend *be, sql_exp *ce,
return NULL;
if (in) {
- i = stmt_uselect(be, c, i, cmp, sel, 0, 0);
+ i = stmt_uselect(be, c, i, cmp_equal, sel, 0,
0);
if (s)
s = stmt_tunion(be, s, i);
else
s = i;
} else {
- s = stmt_uselect(be, c, i, cmp, s, 0, 0);
+ s = stmt_uselect(be, c, i, cmp_equal, s, 1, 0);
}
}
} else {
@@ -2103,7 +2101,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
s = stmt_genselect(be, l, r, e->f, sel, is_anti(e));
return s;
}
- if (e->flag == cmp_in || e->flag == cmp_notin)
+ if (e->flag == cmp_in)
return handle_in_exps(be, e->l, e->r, left, right, grp,
ext, cnt, sel, (e->flag == cmp_in)^is_anti(e), depth, reduce, push);
if (e->flag == cmp_con)
return exp_bin_conjunctive(be, e, left, right, grp,
ext, cnt, sel, depth, reduce, push);
@@ -2180,7 +2178,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
tail_type(l), tail_type(l), F_FUNC, true, true);
assert(f);
if (is_semantics(e)) {
- if (exp_is_null(e->l) &&
exp_is_null(e->r) && (e->flag == cmp_equal || e->flag == cmp_notequal)) {
+ if (exp_is_null(e->l) &&
exp_is_null(e->r) && (e->flag == cmp_equal)) {
s = stmt_bool(be,
e->flag == cmp_equal ? !is_anti(e): is_anti(e));
} else {
list *args =
sa_list(sql->sa);
@@ -2542,7 +2540,7 @@ exp2bin_args(backend *be, sql_exp *e, li
if (e->flag == cmp_filter) {
args = exps2bin_args(be, e->l, args);
args = exps2bin_args(be, e->r, args);
- } else if (e->flag == cmp_in || e->flag == cmp_notin) {
+ } else if (e->flag == cmp_in) {
args = exp2bin_args(be, e->l, args);
args = exps2bin_args(be, e->r, args);
} else {
@@ -2965,7 +2963,7 @@ rel2bin_hash_lookup(backend *be, sql_rel
sql_exp *e = en->data;
stmt *s = NULL;
- if (e->type == e_cmp && e->flag == cmp_equal) {
+ if (e->type == e_cmp && is_equi_exp_(e)) {
sql_exp *ee = (swap_exp)?e->l:e->r;
if (swap_rel)
s = exp_bin(be, ee, left, NULL, NULL, NULL,
NULL, NULL, 0, 0, 0);
@@ -3342,7 +3340,7 @@ get_equi_joins_first(mvc *sql, list *exp
for (node *n = exps->h; n; n = n->next) {
sql_exp *e = n->data;
- assert(e->type == e_cmp && e->flag != cmp_in && e->flag !=
cmp_notin);
+ assert(e->type == e_cmp && e->flag != cmp_in);
if (is_equi_exp_(e))
list_append(new_exps, e);
else
@@ -3432,7 +3430,7 @@ rel2bin_join(backend *be, sql_rel *rel,
prop *p;
/* stop search for equi joins on first non equi
*/
- if (list_length(lje) && (idx || e->type !=
e_cmp || e->flag != cmp_equal))
+ if (list_length(lje) && (idx || e->type !=
e_cmp || !is_equi_exp_(e)))
break;
/* handle possible index lookups, expressions
are in index order! */
@@ -3462,7 +3460,7 @@ rel2bin_join(backend *be, sql_rel *rel,
assert(s->type == st_join || s->type ==
st_join2 || s->type == st_joinN);
if (!join)
join = s;
- if (e->flag != cmp_equal) { /* only collect
equi joins */
+ if (!is_equi_exp_(e)) { /* only collect equi
joins */
en = en->next;
break;
}
@@ -3675,8 +3673,7 @@ rel2bin_antijoin(backend *be, sql_rel *r
bool composite = true;
for (node *m = jexps->h; m; m = m->next) {
sql_exp *ce = m->data;
- if (ce->type != e_cmp || ce->flag != cmp_equal
||
- is_anti(ce) || !is_semantics(ce) ||
exp_has_func(ce)) {
+ if (ce->type != e_cmp || !is_equi_exp_(ce) ||
is_anti(ce) || !is_semantics(ce) || exp_has_func(ce)) {
composite = false;
break;
}
@@ -3708,7 +3705,7 @@ rel2bin_antijoin(backend *be, sql_rel *r
if (!join) {
sql_exp *e = en->data;
- if (e->type == e_cmp && (e->flag == cmp_equal
|| e->flag == cmp_notequal)) {
+ if (e->type == e_cmp && (e->flag == cmp_equal))
{
stmt *ls = exp_bin(be, e->l, left, NULL, NULL,
NULL, NULL, NULL, 1, 0, 0), *rs;
bool constval = false;
if (!ls) {
@@ -3736,7 +3733,7 @@ rel2bin_antijoin(backend *be, sql_rel *r
if (!li)
li = ls;
- if (!en->next && !is_anti(e) && e->flag !=
cmp_notequal &&
+ if (!en->next && !is_anti(e) && e->flag ==
cmp_equal &&
(constval || stmt_has_null(ls) ||
stmt_has_null(rs))) {
join = stmt_tdiff2(be, ls, rs, NULL,
is_semantics(e), is_any(e));
jexps = NULL;
@@ -3955,7 +3952,7 @@ rel2bin_semijoin(backend *be, sql_rel *r
}
break;
}
- if (list_length(lje) && (idx || e->type !=
e_cmp || (e->flag != cmp_equal && e->flag != cmp_filter) ||
+ if (list_length(lje) && (idx || e->type !=
e_cmp || (!is_equi_exp_(e) && e->flag != cmp_filter) ||
(join && e->flag == cmp_filter)))
break;
@@ -8343,11 +8340,11 @@ exp_remap(sql_exp *le, sql_exp *re, list
case e_cmp:
if (le->flag != re->flag)
return -1;
- if (le->flag <= cmp_notequal) {
+ if (le->flag <= cmp_equal) {
return (exp_remap(le->l, re->l, remapped) == 0 &&
exp_remap(le->r, re->r, remapped) == 0 &&
((!le->f && !re->f) || exp_remap(le->f, re->f,
remapped) == 0))?0:-1;
- } else if (le->flag == cmp_in || le->flag == cmp_notin) {
+ } else if (le->flag == cmp_in) {
return (exp_remap(le->l, re->l, remapped) == 0 &&
exps_remap(le->r, re->r, remapped) ==
0)?0:-1;
}
diff --git a/sql/backends/monet5/rel_physical.c
b/sql/backends/monet5/rel_physical.c
--- a/sql/backends/monet5/rel_physical.c
+++ b/sql/backends/monet5/rel_physical.c
@@ -498,7 +498,7 @@ find_cmp_exps(list **exps_hsh, list **ex
/* search first for the not-atom exp, otherwise rel_find_exp()
* incorrectly returns TRUE for an atom-typed exp */
- if (exp_is_atom(e->l) || e->flag != cmp_equal ||
exp_is_atom(e->r)) {
+ if (exp_is_atom(e->l) || !is_equi_exp_(e) || exp_is_atom(e->r))
{
assert(0);
} else {
sql_exp *ne = NULL;
@@ -671,7 +671,7 @@ exp_hash(sql_exp *e)
h *= (e->flag+1);
if (e->flag == cmp_con || e->flag == cmp_dis)
return h * exps_hash(e->l);
- else if (e->flag == cmp_in || e->flag == cmp_notin)
+ else if (e->flag == cmp_in)
return h * exp_hash(e->l) * exps_hash(e->r);
else if (e->flag == cmp_filter)
return h * exps_hash(e->l) * exps_hash(e->r);
@@ -770,7 +770,7 @@ right_is_unique(sql_rel *r, list *exps)
if (list_length(exps) >= 1) {
sql_exp *e = exps->h->data;
- if (e->type == e_cmp && e->flag == cmp_equal) {
+ if (e->type == e_cmp && is_equi_exp_(e)) {
if (rel_find_exp(r, e->l)) {
sql_exp *el = e->l;
return is_unique(el);
@@ -1336,7 +1336,7 @@ rel_count_gt_zero(visitor *v, sql_rel *r
e = exp_ref(sql, e);
}
rel->used |= rewrite_gt_zero_used;
- e = exp_compare(sql->sa, e, exp_atom_lng(sql->sa, 0),
cmp_notequal);
+ e = exp_ne(sql->sa, e, exp_atom_lng(sql->sa, 0));
if (rel_is_ref(rel)) {
sql_rel *i = rel_create(v->sql->sa);
*i = *rel;
@@ -1592,7 +1592,7 @@ append_func_argument(visitor *v, sql_exp
} else if (ie->type == e_cmp) {
if (ie->flag == cmp_con || ie->flag == cmp_dis) {
resultexps = append_func_arguments(v, ie->l,
resultexps);
- } else if (ie->flag == cmp_in || ie->flag == cmp_notin) {
+ } else if (ie->flag == cmp_in) {
resultexps = append_func_argument(v, ie->l, resultexps);
resultexps = append_func_arguments(v, ie->r,
resultexps);
} else if (ie->flag == cmp_filter) {
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
@@ -215,7 +215,7 @@ hash_probe(backend *be, sql_rel *rel, li
assert(key); /* must find */
key = column(be, key);
bool single = ((rel->single == 1 && rel->op != op_semi) &&
(n->next == NULL) && !has_outerselect);
- bool eq = (e2->flag == cmp_equal) && !anti;
+ bool eq = is_equi_exp_(e2) && !anti;
bool grpjoin = groupjoin && is_any(e2);
if (first && match_cnt && is_any(e2)) {
@@ -781,7 +781,7 @@ rel2bin_oahash_cart(backend *be, sql_rel
cross = true;
} else if (e->flag == cmp_con || e->flag == cmp_dis) {
cross = true;
- } else if (e->flag == cmp_in || e->flag == cmp_notin) {
+ } else if (e->flag == cmp_in) {
cross = true;
} else {
if (!rel_has_exp(l, e->l, subexp)) {
diff --git a/sql/backends/monet5/rel_util.c b/sql/backends/monet5/rel_util.c
--- a/sql/backends/monet5/rel_util.c
+++ b/sql/backends/monet5/rel_util.c
@@ -12,6 +12,23 @@
#include "rel_exp.h"
bool
+is_equi_exp_(sql_exp *e)
+{
+ if (!e || e->type != e_cmp || e->flag != cmp_equal)
+ return false;
+ if (!is_anti(e))
+ return true;
+ /* <> is canonical cmp_equal plus the anti flag and is not an equijoin.
+ * IS NOT NULL uses the same encoding but keeps the semantics bit and
+ * compares against NULL; like before the cleanup it can be hashed.
+ * IS DISTINCT FROM keeps the semantics bit too, but compares two
+ * arbitrary expressions and must stay a theta join. */
+ if (is_semantics(e))
+ return exp_is_null(e->l) || exp_is_null(e->r);
+ return false;
+}
+
+bool
can_join_exp(sql_rel *rel, sql_exp *e, bool anti)
{
bool can_join = 0;
diff --git a/sql/backends/monet5/rel_util.h b/sql/backends/monet5/rel_util.h
--- a/sql/backends/monet5/rel_util.h
+++ b/sql/backends/monet5/rel_util.h
@@ -14,7 +14,7 @@
#include "sql_mvc.h"
#include "sql_relation.h"
-#define is_equi_exp_(e) ((e)->flag == cmp_equal)
+extern bool is_equi_exp_(sql_exp *e);
extern bool can_join_exp(sql_rel *rel, sql_exp *e, bool anti);
extern void split_join_exps(sql_rel *rel, list *joinable, list *not_joinable,
bool anti, bool eqonly, bool firstonly);
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
@@ -1830,6 +1830,10 @@ stmt_uselect(backend *be, stmt *op1, stm
r = n;
cmptype = swap_compare(cmptype);
}
+ /* Canonical <>/NOT IN use cmp_equal/cmp_in plus the anti flag. Fold
+ * non-semantic equality into the operator itself; semantic equality
+ * (IS [NOT] NULL) keeps the select's anti bit. */
+ bool eq_ne = cmptype == cmp_equal && anti && !is_semantics;
if (op2->nrcols >= 1) {
bit need_not = FALSE;
const char *mod = calcRef;
@@ -1838,10 +1842,7 @@ stmt_uselect(backend *be, stmt *op1, stm
switch (cmptype) {
case cmp_equal:
- op = "=";
- break;
- case cmp_notequal:
- op = "!=";
+ op = eq_ne ? "!=" : "=";
break;
case cmp_lt:
op = "<";
@@ -1887,7 +1888,7 @@ stmt_uselect(backend *be, stmt *op1, stm
q = pushBit(mb, q, !need_not);
q = pushBit(mb, q, TRUE);
q = pushBit(mb, q, TRUE);
- q = pushBit(mb, q, anti);
+ q = pushBit(mb, q, eq_ne ? FALSE : anti);
k = getDestVar(q);
} else {
assert (cmptype != cmp_filter);
@@ -1908,13 +1909,7 @@ stmt_uselect(backend *be, stmt *op1, stm
if (is_semantics)
q = pushStr(mb, q, anti?"ne":"eq");
else
- q = pushStr(mb, q, anti?"!=":"==");
- break;
- case cmp_notequal:
- if (is_semantics)
- q = pushStr(mb, q, anti?"eq":"ne");
- else
- q = pushStr(mb, q, anti?"==":"!=");
+ q = pushStr(mb, q, eq_ne?"!=":"==");
break;
case cmp_lt:
q = pushStr(mb, q, anti?">=":"<");
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]