Changeset: e2303cab844d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=e2303cab844d
Branch: Oct2020
Log Message:

merged


diffs (100 lines):

diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -1800,9 +1800,33 @@ exp_is_zero(sql_exp *e)
 int
 exp_is_not_null(sql_exp *e)
 {
-       if (e->type == e_atom && e->l)
-               return !(atom_null(e->l));
-       return 0;
+       switch (e->type) {
+       case e_atom:
+               if (e->f) /* values list */
+                       return false;
+               if (e->l)
+                       return !(atom_null(e->l));
+               return false;
+       case e_convert:
+               return exp_is_not_null(e->l);
+       case e_func:
+               if (!e->semantics && e->l) {
+                       list *l = e->l;
+                       for (node *n = l->h; n; n=n->next) {
+                               sql_exp *p = n->data;
+                               if (!exp_is_not_null(p))
+                                       return false;
+                       }
+                       return true;
+               }
+               return false;
+       case e_aggr:
+       case e_column:
+       case e_cmp:
+       case e_psm:
+               return false;
+       }
+       return false;
 }
 
 int
diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c
--- a/sql/server/rel_optimizer.c
+++ b/sql/server/rel_optimizer.c
@@ -7528,6 +7528,22 @@ rel_simplify_predicates(visitor *v, sql_
 {
        (void)depth;
        if (is_select(rel->op) || is_join(rel->op) || is_semi(rel->op)) {
+               if (is_compare(e->type) && is_semantics(e) && (e->flag == 
cmp_equal || e->flag == cmp_notequal) && exp_is_null(e->r)) {
+                       /* simplify 'is null' predicates on constants */
+                       if (exp_is_null(e->l)) {
+                               int nval = e->flag == cmp_equal;
+                               if (is_anti(e)) nval = !nval;
+                               e = exp_atom_bool(v->sql->sa, nval);
+                               v->changes++;
+                               return e;
+                       } else if (exp_is_not_null(e->l)) {
+                               int nval = e->flag == cmp_notequal;
+                               if (is_anti(e)) nval = !nval;
+                               e = exp_atom_bool(v->sql->sa, nval);
+                               v->changes++;
+                               return e;
+                       }
+               }
                if (is_atom(e->type) && ((!e->l && !e->r && !e->f) || e->r)) /* 
prepared statement parameter or argument */
                        return e;
                if (is_atom(e->type) && e->l) { /* direct literal */
@@ -7642,6 +7658,7 @@ rel_simplify_predicates(visitor *v, sql_
                                        }
                                }
                        } else if (is_atom(l->type) && is_atom(r->type) && 
!is_semantics(e)) {
+                               /* compute comparisons on atoms */
                                if (exp_is_null(l) || exp_is_null(r)) {
                                        e = exp_null(v->sql->sa, 
sql_bind_localtype("bit"));
                                        v->changes++;
diff --git a/sql/test/miscellaneous/Tests/groupby_error.stable.out 
b/sql/test/miscellaneous/Tests/groupby_error.stable.out
--- a/sql/test/miscellaneous/Tests/groupby_error.stable.out
+++ b/sql/test/miscellaneous/Tests/groupby_error.stable.out
@@ -510,6 +510,22 @@ project (
 #CREATE TABLE tab2 ("col0" INTEGER,"col1" INTEGER,"col2" INTEGER);
 #INSERT INTO tab2 VALUES(64,77,40), (75,67,58), (46,51,23);
 [ 3    ]
+#SELECT col2 FROM tab2 WHERE col2 >= - col1 * 2 AND 1 IS NOT NULL;
+% sys.tab2 # table_name
+% col2 # name
+% int # type
+% 2 # length
+[ 40   ]
+[ 58   ]
+[ 23   ]
+#SELECT col2 FROM tab2 WHERE ( + col2 ) >= - col1 * + + 19 * + col2 AND NOT 79 
/ + 50 IS NULL;
+% sys.tab2 # table_name
+% col2 # name
+% int # type
+% 2 # length
+[ 40   ]
+[ 58   ]
+[ 23   ]
 #ROLLBACK;
 #START TRANSACTION;
 #CREATE TABLE t(x DECIMAL(4,1));
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to