Changeset: ca1e9eb63393 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ca1e9eb63393
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_statement.c
        sql/backends/monet5/sql_statement.h
        sql/server/rel_exp.c
        sql/server/rel_exp.h
        sql/server/rel_optimizer.c
        sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.stable.out
        sql/test/BugTracker-2016/Tests/null_in_null.Bug-3900.stable.out
        
sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out
        
sql/test/BugTracker-2019/Tests/duplicates-not-eliminated-long-CASE-stmt.Bug-6697.stable.out.single
        sql/test/SQLancer/Tests/sqlancer02.stable.out
        sql/test/miscellaneous/Tests/simple_plans.stable.out
        sql/test/miscellaneous/Tests/simple_plans.stable.out.single
Branch: default
Log Message:

use cmp (between) instead of hared coded mal instruction
(cleans up the handling later, in rel_bin etc)


diffs (truncated from 806 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
@@ -36,7 +36,7 @@ stmt_selectnil( backend *be, stmt *col)
 {
        sql_subtype *t = tail_type(col);
        stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL));
-       stmt *nn = stmt_uselect2(be, col, n, n, 3, NULL, 0);
+       stmt *nn = stmt_uselect2(be, col, n, n, 3, NULL, 0, 1);
        return nn;
 }
 
@@ -312,7 +312,7 @@ stmt_selectnonil( backend *be, stmt *col
 {
        sql_subtype *t = tail_type(col);
        stmt *n = stmt_atom(be, atom_general(be->mvc->sa, t, NULL));
-       stmt *nn = stmt_uselect2(be, col, n, n, 3, s, 1);
+       stmt *nn = stmt_uselect2(be, col, n, n, 3, s, 1, 1);
        return nn;
 }
 
@@ -1065,44 +1065,11 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                                s = stmt_join(be, l, r, is_anti(e), 
(comp_type)e->flag, is_semantics(e), false);
                        }
                } else {
-                       if (r2) {
-                               if (!reduce || (l->nrcols == 0 && r->nrcols == 
0 && r2->nrcols == 0)) {
-                                       sql_subtype *bt = 
sql_bind_localtype("bit");
-                                       sql_subfunc *lf = 
sql_bind_func(sql->sa, sql->session->schema,
-                                                       
compare_func(range2lcompare(e->flag), 0),
-                                                       tail_type(l), 
tail_type(r), F_FUNC);
-                                       sql_subfunc *rf = 
sql_bind_func(sql->sa, sql->session->schema,
-                                                       
compare_func(range2rcompare(e->flag), 0),
-                                                       tail_type(l), 
tail_type(r), F_FUNC);
-                                       sql_subfunc *a = sql_bind_func(sql->sa, 
sql->session->schema,
-                                                       "and", bt, bt, F_FUNC);
-
-                                       if (is_atom(re->type) && re->l && 
atom_null((atom*)re->l) &&
-                                           is_atom(re2->type) && re2->l && 
atom_null((atom*)re2->l)) {
-                                               assert(0); // old hack is gone 
...
-                                       } else {
-                                               assert(lf && rf && a);
-                                               s = stmt_binop(be,
-                                                       stmt_binop(be, l, r, 
lf),
-                                                       stmt_binop(be, l, r2, 
rf), a);
-                                               if (l->cand)
-                                                       s->cand = l->cand;
-                                               if (r->cand)
-                                                       s->cand = r->cand;
-                                               if (r2->cand)
-                                                       s->cand = r2->cand;
-                                       }
-                                       if (is_anti(e)) {
-                                               stmt *cand = s->cand;
-                                               sql_subfunc *a = 
sql_bind_func(sql->sa, sql->session->schema, "not", bt, NULL, F_FUNC);
-                                               s = stmt_unop(be, s, a);
-                                               s->cand = cand;
-                                       }
-                               } else {
-                                       if (l->nrcols == 0)
-                                               l = stmt_const(be, 
bin_first_column(be, left), l);
-                                       s = stmt_uselect2(be, l, r, r2, 
(comp_type)e->flag, sel, is_anti(e));
-                               }
+                       if (r2) { /* handle all cases in stmt_uselect,
+                                                reducing, non reducing, scalar 
etc */
+                               if (l->nrcols == 0)
+                                       l = stmt_const(be, bin_first_column(be, 
left), l);
+                               s = stmt_uselect2(be, l, r, r2, 
(comp_type)e->flag, sel, is_anti(e), reduce);
                        } else {
                                /* value compare or select */
                                if ((!reduce || (l->nrcols == 0 && r->nrcols == 
0)) && (e->flag == mark_in || e->flag == mark_notin)) {
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
@@ -1612,7 +1612,8 @@ argumentZero(MalBlkPtr mb, int tpe)
 
 
 static InstrPtr
-select2_join2(backend *be, stmt *op1, stmt *op2, stmt *op3, int cmp, stmt 
*sub, int anti, int swapped, int type)
+select2_join2(backend *be, stmt *op1, stmt *op2, stmt *op3, int cmp, stmt 
*sub, int anti, int swapped, int type, int
+               reduce)
 {
        MalBlkPtr mb = be->mb;
        InstrPtr p, q;
@@ -1622,18 +1623,23 @@ select2_join2(backend *be, stmt *op1, st
        if (op1->nr < 0 && (sub && sub->nr < 0))
                return NULL;
        l = op1->nr;
-       if (((cmp & CMP_BETWEEN && cmp & CMP_SYMMETRIC) || (cmp & CMP_BETWEEN 
&& anti) || op2->nrcols > 0 || op3->nrcols > 0) && (type == st_uselect2)) {
+       if (((cmp & CMP_BETWEEN && cmp & CMP_SYMMETRIC) || (cmp & CMP_BETWEEN 
&& anti) || op2->nrcols > 0 || op3->nrcols > 0 || !reduce) && (type == 
st_uselect2)) {
                int k;
+               int nrcols = (op1->nrcols || op2->nrcols || op3->nrcols);
 
                if (op2->nr < 0 || op3->nr < 0)
                        return NULL;
-               p = newStmt(mb, batcalcRef, betweenRef);
+
+               if (nrcols)
+                       p = newStmt(mb, batcalcRef, betweenRef);
+               else
+                       p = newStmt(mb, calcRef, betweenRef);
                p = pushArgument(mb, p, l);
                p = pushArgument(mb, p, op2->nr);
                p = pushArgument(mb, p, op3->nr);
 
                /* cands */
-               if (op1->cand || op2->cand || op3->cand) { /* some already 
handled the previous selection */
+               if ((sub && !reduce) || op1->cand || op2->cand || op3->cand) { 
/* some already handled the previous selection */
                        if (op1->cand && op1->nrcols)
                                p = pushNil(mb, p, TYPE_bat);
                        else if (op1->nrcols)
@@ -1658,6 +1664,8 @@ select2_join2(backend *be, stmt *op1, st
                p = pushBit(mb, p, (cmp & 2) != 0);         /* hi inclusive */
                p = pushBit(mb, p, FALSE);                  /* nils_false */
                p = pushBit(mb, p, (anti)?TRUE:FALSE);      /* anti */
+               if (!reduce)
+                       return p;
                k = getDestVar(p);
 
                q = newStmt(mb, algebraRef, selectRef);
@@ -1767,9 +1775,9 @@ select2_join2(backend *be, stmt *op1, st
 }
 
 stmt *
-stmt_uselect2(backend *be, stmt *op1, stmt *op2, stmt *op3, int cmp, stmt 
*sub, int anti)
+stmt_uselect2(backend *be, stmt *op1, stmt *op2, stmt *op3, int cmp, stmt 
*sub, int anti, int reduce)
 {
-       InstrPtr q = select2_join2(be, op1, op2, op3, cmp, sub, anti, 0, 
st_uselect2);
+       InstrPtr q = select2_join2(be, op1, op2, op3, cmp, sub, anti, 0, 
st_uselect2, reduce);
 
        if (q) {
                stmt *s = stmt_create(be->mvc->sa, st_uselect2);
@@ -2204,7 +2212,7 @@ stmt_left_project(backend *be, stmt *op1
 stmt *
 stmt_join2(backend *be, stmt *l, stmt *ra, stmt *rb, int cmp, int anti, int 
swapped)
 {
-       InstrPtr q = select2_join2(be, l, ra, rb, cmp, NULL, anti, swapped, 
st_join2);
+       InstrPtr q = select2_join2(be, l, ra, rb, cmp, NULL, anti, swapped, 
st_join2, 1/*reduce semantics*/);
        if (q) {
                stmt *s = stmt_create(be->mvc->sa, st_join2);
 
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
@@ -176,7 +176,7 @@ extern stmt *stmt_uselect(backend *be, s
        2 ==   l <= x <  h
        3 ==   l <= x <= h
        */
-extern stmt *stmt_uselect2(backend *be, stmt *op1, stmt *op2, stmt *op3, int 
cmp, stmt *sub, int anti);
+extern stmt *stmt_uselect2(backend *be, stmt *op1, stmt *op2, stmt *op3, int 
cmp, stmt *sub, int anti, int reduce);
 extern stmt *stmt_genselect(backend *be, stmt *lops, stmt *rops, sql_subfunc 
*f, stmt *sub, int anti);
 
 extern stmt *stmt_tunion(backend *be, stmt *op1, stmt *op2);
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
@@ -135,6 +135,22 @@ compare2range( int l, int r )
        return -1;
 }
 
+int
+compare_funcs2range(const char *l_op, const char *r_op)
+{
+       assert(l_op[0] == '>' && r_op[0] == '<');
+       if (!l_op[1] && !r_op[1])
+               return 0;
+       if (!l_op[1] && r_op[1] == '=')
+               return 2;
+       if (l_op[1] == '=' && !r_op[1])
+               return 1;
+       if (l_op[1] == '=' && r_op[1] == '=')
+               return 3;
+       assert(0);
+       return 0;
+}
+
 static sql_exp *
 exp_create(sql_allocator *sa, int type)
 {
@@ -2267,7 +2283,7 @@ exps_bind_column2( list *exps, const cha
                                for (; he; he = he->chain) {
                                        sql_exp *e = he->value;
 
-                                       if (e && is_column(e->type) && 
e->alias.name && e->alias.rname && strcmp(e->alias.name, cname) == 0 && 
strcmp(e->alias.rname, rname) == 0) {
+                                       if (e && e->alias.name && 
e->alias.rname && strcmp(e->alias.name, cname) == 0 && strcmp(e->alias.rname, 
rname) == 0) {
                                                MT_lock_unset(&exps->ht_lock);
                                                return e;
                                        }
@@ -2280,7 +2296,7 @@ exps_bind_column2( list *exps, const cha
                for (en = exps->h; en; en = en->next ) {
                        sql_exp *e = en->data;
 
-                       if (e && is_column(e->type) && e->alias.name && 
e->alias.rname && strcmp(e->alias.name, cname) == 0 && strcmp(e->alias.rname, 
rname) == 0)
+                       if (e && e->alias.name && e->alias.rname && 
strcmp(e->alias.name, cname) == 0 && strcmp(e->alias.rname, rname) == 0)
                                return e;
                }
        }
diff --git a/sql/server/rel_exp.h b/sql/server/rel_exp.h
--- a/sql/server/rel_exp.h
+++ b/sql/server/rel_exp.h
@@ -30,6 +30,7 @@ extern comp_type negate_compare( comp_ty
 extern comp_type range2lcompare( int r );
 extern comp_type range2rcompare( int r );
 extern int compare2range( int l, int r );
+extern int compare_funcs2range(const char *l, const char *r);
 
 extern sql_exp *exp_compare(sql_allocator *sa, sql_exp *l, sql_exp *r, int 
cmptype);
 extern sql_exp *exp_compare2(sql_allocator *sa, sql_exp *l, sql_exp *r, 
sql_exp *f, int cmptype);
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
@@ -3894,25 +3894,12 @@ exp_merge_project_rse(visitor *v, sql_re
                                if (((strcmp(lf->func->base.name, ">=") == 0 || 
strcmp(lf->func->base.name, ">") == 0) && list_length(lfexps) == 2) &&
                                    ((strcmp(rf->func->base.name, "<=") == 0 || 
strcmp(rf->func->base.name, "<") == 0) && list_length(rfexps) == 2)
                                    && exp_equal(list_fetch(lfexps,0), 
list_fetch(rfexps,0)) == 0) {
-                                       sql_exp *ce = list_fetch(lfexps, 0);
-                                       list *types, *ops = sa_list(sql->sa);
-                                       sql_subfunc *between;
-
-                                       append(ops, ce);
-                                       append(ops, list_fetch(lfexps, 1));
-                                       append(ops, list_fetch(rfexps, 1));
-                                       append(ops, exp_atom_bool(sql->sa, 0)); 
/* non symetrical */
-                                       append(ops, exp_atom_bool(sql->sa, 
lf->func->base.name[1] == '=')); /* left inclusive */
-                                       append(ops, exp_atom_bool(sql->sa, 
rf->func->base.name[1] == '=')); /* right exclusive */
-                                       append(ops, exp_atom_bool(sql->sa, 0)); 
/* nils_false */
-                                       append(ops, exp_atom_bool(sql->sa, 0)); 
/* anti */
-
-                                       types = exp_types(sql->sa, ops);
-                                       /* convert into between */
-                                       between = sql_bind_func_(sql->sa, 
mvc_bind_schema(sql, "sys"), "between", types, F_FUNC);
-                                       if (between) {
-                                               sql_exp *ne = exp_op(sql->sa, 
ops, between);
-
+                                       sql_exp *ne = exp_compare2(sql->sa,
+                                                       list_fetch(lfexps, 0),
+                                                       list_fetch(lfexps, 1),
+                                                       list_fetch(rfexps, 1),
+                                                       
compare_funcs2range(lf->func->base.name, rf->func->base.name));
+                                       if (ne) {
                                                exp_setname(sql->sa, ne, 
exp_relname(e), exp_name(e));
                                                e = ne;
                                        }
diff --git a/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.stable.out 
b/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.stable.out
--- a/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.stable.out
+++ b/sql/test/BugTracker-2012/Tests/currenttime.Bug-2781.stable.out
@@ -5,48 +5,11 @@ stdout of test 'currenttime.Bug-2781` in
 # 14:00:10 >  "/usr/bin/python" "currenttime.Bug-2781.py" 
"currenttime.Bug-2781"
 # 14:00:10 >  
 
-# MonetDB 5 server v11.19.10 (hg id: 68ab398acb08)
-# This is an unreleased version
-# Serving database 'mTests_test_BugTracker-2012', using 8 threads
-# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically 
linked
-# Found 15.629 GiB available main-memory.
-# Copyright (c) 1993-July 2008 CWI.
-# Copyright (c) August 2008-2015 MonetDB B.V., all rights reserved
-# Visit http://www.monetdb.org/ for further information
-# Listening for connection requests on mapi:monetdb://london.ins.cwi.nl:32575/
-# MonetDB/GIS module loaded
-# MonetDB/JAQL module loaded
-# MonetDB/SQL module loaded
-# MonetDB/R   module loaded
-
-# SQL catalog created, loading sql scripts once
-# loading sql script: 09_like.sql
-# loading sql script: 10_math.sql
-# loading sql script: 11_times.sql
-# loading sql script: 12_url.sql
-# loading sql script: 13_date.sql
-# loading sql script: 14_inet.sql
-# loading sql script: 15_history.sql
-# loading sql script: 16_tracelog.sql
-# loading sql script: 17_compress.sql
-# loading sql script: 18_dictionary.sql
-# loading sql script: 19_cluster.sql
-# loading sql script: 20_vacuum.sql
-# loading sql script: 21_dependency_functions.sql
-# loading sql script: 22_clients.sql
-# loading sql script: 23_skyserver.sql
-# loading sql script: 24_zorder.sql
-# loading sql script: 25_debug.sql
-# loading sql script: 39_analytics.sql
-# loading sql script: 40_geom.sql
-# loading sql script: 80_udf.sql
-# loading sql script: 99_system.sql
-
-#select localtimestamp() between (timestamp '2020-05-06 10:22:12' - interval 
'20' second) and (timestamp '2020-05-06 10:22:12' + interval '20' second);
-% . # table_name
-% %1 # name
-% boolean # type
-% 5 # length
+#select localtimestamp() between (timestamp '2020-07-07 14:25:20' - interval 
'20' second) and (timestamp '2020-07-07 14:25:20' + interval '20' second);
+% .%2 # table_name
+% %2 # name
+% oid # type
+% 22 # length
 [ true ]
 
 # 09:58:28 >  
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to