Changeset: c720b5a862df for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/c720b5a862df Modified Files: sql/server/rel_select.c sql/test/2024/Tests/distinct_from.test Branch: default Log Message:
fixes #7527 diffs (95 lines): diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -2804,15 +2804,42 @@ rel_logical_exp(sql_query *query, sql_re char *compare_op = n->next->data.sval; int quantifier = 0; int is_semantics = 0; + bool is_distinct_from = false; if (n->next->next->next) quantifier = n->next->next->next->data.i_val + 1; assert(quantifier == 0 || quantifier == 1 || quantifier == 2 || quantifier == 3 || quantifier == 4); if (quantifier >= 3) { + if (quantifier == 4) + is_distinct_from = true; quantifier = 0; is_semantics = 1; } + if (is_distinct_from) { + sql_exp* ls = rel_value_exp(query, &rel, lo, f|sql_farg, ek); + if (!ls) + return NULL; + sql_exp* rs = rel_value_exp(query, &rel, ro, f|sql_farg, ek); + if (!rs) + return NULL; + + bool ls_is_non_null_atom = exp_is_atom(ls) && exp_is_not_null(ls); + bool rs_is_non_null_atom = exp_is_atom(rs) && exp_is_not_null(rs); + + if (ls_is_non_null_atom || rs_is_non_null_atom) { + sql_rel* l = rel_compare(query, rel, sc, lo, ro, compare_op, f | sql_or, ek, quantifier, 0); + sql_subtype *t; + if (!(t = exp_subtype(rs_is_non_null_atom?ls:rs))) + return sql_error(sql, 01, SQLSTATE(42000) "Cannot have a parameter for IS NULL operator"); + sql_exp* e = exp_compare(sql->sa, rs_is_non_null_atom?ls:rs, exp_atom(sql->sa, atom_general(sql->sa, t, NULL, 0)), cmp_equal); + set_has_no_nil(e); + set_semantics(e); + sql_rel* r = rel_select_push_compare_exp_down(sql, rel, e, e->l, e->r, NULL, f | sql_or); + + return rel_or(sql, rel_dup(rel), l, r, NULL, NULL, NULL); + } + } /* [NOT] DISTINCT FROM */ return rel_compare(query, rel, sc, lo, ro, compare_op, f, ek, quantifier, is_semantics); diff --git a/sql/test/2024/Tests/distinct_from.test b/sql/test/2024/Tests/distinct_from.test --- a/sql/test/2024/Tests/distinct_from.test +++ b/sql/test/2024/Tests/distinct_from.test @@ -107,6 +107,28 @@ 1 1 0 +query I nosort +select s FROM foo WHERE s IS DISTINCT FROM 20; +---- +10 +NULL + +query I nosort +select s FROM foo WHERE s IS NOT DISTINCT FROM 20; +---- +20 + +query I nosort +select s FROM foo WHERE s + 10 IS DISTINCT FROM s; +---- +10 +20 + +query I nosort +select s FROM foo WHERE s + 10 IS NOT DISTINCT FROM s; +---- +NULL + statement ok create table bar(s) as values (20), (30), (NULL) @@ -176,3 +198,16 @@ 20 20 NULL NULL + +statement ok +create table baz(s int) + +query II rowsort +SELECT * FROM baz RIGHT JOIN foo ON true WHERE (1 IS DISTINCT FROM baz.s); +---- +NULL +10 +NULL +20 +NULL +NULL _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org