Changeset: 71f4537794c8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=71f4537794c8
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/backends/monet5/sql_upgrades.c
        sql/server/rel_optimizer.c
        
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
Branch: unlock
Log Message:

merged


diffs (truncated from 1396 to 300 lines):

diff --git a/cmake/monetdb-toolchain.cmake b/cmake/monetdb-toolchain.cmake
--- a/cmake/monetdb-toolchain.cmake
+++ b/cmake/monetdb-toolchain.cmake
@@ -104,7 +104,7 @@ function(monetdb_default_compiler_option
     if(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")
       add_compile_options("-fsanitize=address")
       add_compile_options("-fno-omit-frame-pointer")
-      add_compile_definitions(-DNO_ATOMIC_INSTRUCTIONS)
+      add_compile_definitions(NO_ATOMIC_INSTRUCTIONS)
     else()
       message(FATAL_ERROR "Sanitizer only supported with GCC")
     endif()
@@ -176,6 +176,6 @@ function(monetdb_default_compiler_option
   endif()
 
   if(NOT ASSERT)
-     add_compile_definitions("-DNDEBUG=1")
+     add_compile_definitions("NDEBUG=1")
   endif()
 endfunction()
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
@@ -531,6 +531,92 @@ exp_count_no_nil_arg( sql_exp *e, stmt *
        return as;
 }
 
+static stmt *
+exp_bin_or(backend *be, sql_exp *e, stmt *left, stmt *right, stmt *grp, stmt 
*ext, stmt *cnt, stmt *sel, int depth, bool reduce)
+{
+       sql_subtype *bt = sql_bind_localtype("bit");
+       list *l = e->l;
+       node *n;
+       stmt *sel1 = NULL, *sel2 = NULL, *s = NULL;
+       int anti = is_anti(e);
+
+       sel1 = sel;
+       sel2 = sel;
+       for( n = l->h; n; n = n->next ) {
+               sql_exp *c = n->data;
+               stmt *sin = (sel1 && sel1->nrcols)?sel1:NULL;
+
+               /* propagate the anti flag */
+               if (anti)
+                       set_anti(c);
+               s = exp_bin(be, c, left, right, grp, ext, cnt, sin, NULL, 
depth, reduce);
+               if (!s)
+                       return s;
+
+               if (!sin && sel1 && sel1->nrcols == 0 && s->nrcols == 0) {
+                       sql_subfunc *f = sql_bind_func(be->mvc->sa, 
be->mvc->session->schema, anti?"or":"and", bt, bt, F_FUNC);
+                       assert(f);
+                       s = stmt_binop(be, sel1, s, f);
+               } else if (sel1 && (sel1->nrcols == 0 || s->nrcols == 0)) {
+                       stmt *predicate = bin_first_column(be, left);
+
+                       predicate = stmt_const(be, predicate, stmt_bool(be, 1));
+                       if (s->nrcols == 0)
+                               s = stmt_uselect(be, predicate, s, cmp_equal, 
sel1, anti, is_semantics(c));
+                       else
+                               s = stmt_uselect(be, predicate, sel1, 
cmp_equal, s, anti, is_semantics(c));
+               }
+               sel1 = s;
+       }
+       l = e->r;
+       for( n = l->h; n; n = n->next ) {
+               sql_exp *c = n->data;
+               stmt *sin = (sel2 && sel2->nrcols)?sel2:NULL;
+
+               /* propagate the anti flag */
+               if (anti)
+                       set_anti(c);
+               s = exp_bin(be, c, left, right, grp, ext, cnt, sin, NULL, 
depth, reduce);
+               if (!s)
+                       return s;
+
+               if (!sin && sel2 && sel2->nrcols == 0 && s->nrcols == 0) {
+                       sql_subfunc *f = sql_bind_func(be->mvc->sa, 
be->mvc->session->schema, anti?"or":"and", bt, bt, F_FUNC);
+                       assert(f);
+                       s = stmt_binop(be, sel2, s, f);
+               } else if (sel2 && (sel2->nrcols == 0 || s->nrcols == 0)) {
+                       stmt *predicate = bin_first_column(be, left);
+
+                       predicate = stmt_const(be, predicate, stmt_bool(be, 1));
+                       if (s->nrcols == 0)
+                               s = stmt_uselect(be, predicate, s, cmp_equal, 
sel2, anti, 0);
+                       else
+                               s = stmt_uselect(be, predicate, sel2, 
cmp_equal, s, anti, 0);
+               }
+               sel2 = s;
+       }
+       if (sel1->nrcols == 0 && sel2->nrcols == 0) {
+               sql_subfunc *f = sql_bind_func(be->mvc->sa, 
be->mvc->session->schema, anti?"and":"or", bt, bt, F_FUNC);
+               assert(f);
+               return stmt_binop(be, sel1, sel2, f);
+       }
+       if (sel1->nrcols == 0) {
+               stmt *predicate = bin_first_column(be, left);
+
+               predicate = stmt_const(be, predicate, stmt_bool(be, 1));
+               sel1 = stmt_uselect(be, predicate, sel1, cmp_equal, NULL, 
0/*anti*/, 0);
+       }
+       if (sel2->nrcols == 0) {
+               stmt *predicate = bin_first_column(be, left);
+
+               predicate = stmt_const(be, predicate, stmt_bool(be, 1));
+               sel2 = stmt_uselect(be, predicate, sel2, cmp_equal, NULL, 
0/*anti*/, 0);
+       }
+       if (anti)
+               return stmt_project(be, stmt_tinter(be, sel1, sel2, false), 
sel1);
+       return stmt_tunion(be, sel1, sel2);
+}
+
 stmt *
 exp_bin(backend *be, sql_exp *e, stmt *left, stmt *right, stmt *grp, stmt 
*ext, stmt *cnt, stmt *sel, stmt *cond, int depth, int reduce)
 {
@@ -928,89 +1014,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                if (e->flag == cmp_in || e->flag == cmp_notin) {
                        return handle_in_exps(be, e->l, e->r, left, right, grp, 
ext, cnt, sel, (e->flag == cmp_in), 0, depth, reduce);
                }
-               if (e->flag == cmp_or && (!right || right->nrcols == 1)) {
-                       sql_subtype *bt = sql_bind_localtype("bit");
-                       list *l = e->l;
-                       node *n;
-                       stmt *sel1 = NULL, *sel2 = NULL;
-                       int anti = is_anti(e);
-
-                       sel1 = sel;
-                       sel2 = sel;
-                       for( n = l->h; n; n = n->next ) {
-                               sql_exp *c = n->data;
-                               stmt *sin = (sel1 && sel1->nrcols)?sel1:NULL;
-
-                               /* propagate the anti flag */
-                               if (anti)
-                                       set_anti(c);
-                               s = exp_bin(be, c, left, right, grp, ext, cnt, 
sin, NULL, depth, reduce);
-                               if (!s)
-                                       return s;
-
-                               if (!sin && sel1 && sel1->nrcols == 0 && 
s->nrcols == 0) {
-                                       sql_subfunc *f = sql_bind_func(sql->sa, 
sql->session->schema, anti?"or":"and", bt, bt, F_FUNC);
-                                       assert(f);
-                                       s = stmt_binop(be, sel1, s, f);
-                               } else if (sel1 && (sel1->nrcols == 0 || 
s->nrcols == 0)) {
-                                       stmt *predicate = bin_first_column(be, 
left);
-
-                                       predicate = stmt_const(be, predicate, 
stmt_bool(be, 1));
-                                       if (s->nrcols == 0)
-                                               s = stmt_uselect(be, predicate, 
s, cmp_equal, sel1, anti, is_semantics(c));
-                                       else
-                                               s = stmt_uselect(be, predicate, 
sel1, cmp_equal, s, anti, is_semantics(c));
-                               }
-                               sel1 = s;
-                       }
-                       l = e->r;
-                       for( n = l->h; n; n = n->next ) {
-                               sql_exp *c = n->data;
-                               stmt *sin = (sel2 && sel2->nrcols)?sel2:NULL;
-
-                               /* propagate the anti flag */
-                               if (anti)
-                                       set_anti(c);
-                               s = exp_bin(be, c, left, right, grp, ext, cnt, 
sin, NULL, depth, reduce);
-                               if (!s)
-                                       return s;
-
-                               if (!sin && sel2 && sel2->nrcols == 0 && 
s->nrcols == 0) {
-                                       sql_subfunc *f = sql_bind_func(sql->sa, 
sql->session->schema, anti?"or":"and", bt, bt, F_FUNC);
-                                       assert(f);
-                                       s = stmt_binop(be, sel2, s, f);
-                               } else if (sel2 && (sel2->nrcols == 0 || 
s->nrcols == 0)) {
-                                       stmt *predicate = bin_first_column(be, 
left);
-
-                                       predicate = stmt_const(be, predicate, 
stmt_bool(be, 1));
-                                       if (s->nrcols == 0)
-                                               s = stmt_uselect(be, predicate, 
s, cmp_equal, sel2, anti, 0);
-                                       else
-                                               s = stmt_uselect(be, predicate, 
sel2, cmp_equal, s, anti, 0);
-                               }
-                               sel2 = s;
-                       }
-                       if (sel1->nrcols == 0 && sel2->nrcols == 0) {
-                               sql_subfunc *f = sql_bind_func(sql->sa, 
sql->session->schema, anti?"and":"or", bt, bt, F_FUNC);
-                               assert(f);
-                               return stmt_binop(be, sel1, sel2, f);
-                       }
-                       if (sel1->nrcols == 0) {
-                               stmt *predicate = bin_first_column(be, left);
-
-                               predicate = stmt_const(be, predicate, 
stmt_bool(be, 1));
-                               sel1 = stmt_uselect(be, predicate, sel1, 
cmp_equal, NULL, 0/*anti*/, 0);
-                       }
-                       if (sel2->nrcols == 0) {
-                               stmt *predicate = bin_first_column(be, left);
-
-                               predicate = stmt_const(be, predicate, 
stmt_bool(be, 1));
-                               sel2 = stmt_uselect(be, predicate, sel2, 
cmp_equal, NULL, 0/*anti*/, 0);
-                       }
-                       if (anti)
-                               return stmt_project(be, stmt_tinter(be, sel1, 
sel2, false), sel1);
-                       return stmt_tunion(be, sel1, sel2);
-               }
+               if (e->flag == cmp_or && (!right || right->nrcols == 1))
+                       return exp_bin_or(be, e, left, right, grp, ext, cnt, 
sel, depth, reduce);
                if (e->flag == cmp_or && right) {  /* join */
                        assert(0);
                }
@@ -1323,86 +1328,12 @@ sql_Nop_(backend *be, const char *fname,
 }
 
 static stmt *
-rel_parse_value(backend *be, char *query, char emode)
+parse_value(backend *be, char *query, sql_subtype *tpe, char emode)
 {
-       mvc *m = be->mvc;
-       mvc o = *m;
-       stmt *s = NULL;
-       buffer *b;
-       char *n;
-       size_t len = _strlen(query);
-       exp_kind ek = {type_value, card_value, FALSE};
-       stream *sr;
-       bstream *bs;
-
-       m->qc = NULL;
-
-       m->emode = emode;
-       b = (buffer*)GDKmalloc(sizeof(buffer));
-       n = GDKmalloc(len + 1 + 1);
-       if (b == NULL || n == NULL) {
-               GDKfree(b);
-               GDKfree(n);
-               return sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       }
-       snprintf(n, len + 2, "%s\n", query);
-       query = n;
-       len++;
-       buffer_init(b, query, len);
-       sr = buffer_rastream(b, "sqlstatement");
-       if (sr == NULL) {
-               buffer_destroy(b);
-               return sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       }
-       bs = bstream_create(sr, b->len);
-       if(bs == NULL) {
-               buffer_destroy(b);
-               return sql_error(m, 02, SQLSTATE(HY013) MAL_MALLOC_FAIL);
-       }
-       scanner_init(&m->scanner, bs, NULL);
-       m->scanner.mode = LINE_1;
-       bstream_next(m->scanner.rs);
-
-       m->params = NULL;
-       m->sym = NULL;
-       m->errstr[0] = '\0';
-
-       (void) sqlparse(m);     /* blindly ignore errors */
-
-       /* get out the single value as we don't want an enclosing projection! */
-       if (m->sym->token == SQL_SELECT) {
-               SelectNode *sn = (SelectNode *)m->sym;
-               if (sn->selection->h->data.sym->token == SQL_COLUMN || 
sn->selection->h->data.sym->token == SQL_IDENT) {
-                       sql_rel *rel = NULL;
-                       sql_query *query = query_create(m);
-                       sql_exp *e = rel_value_exp2(query, &rel, 
sn->selection->h->data.sym->data.lval->h->data.sym, sql_sel | sql_values, ek);
-
-                       if (!rel)
-                               s = exp_bin(be, e, NULL, NULL, NULL, NULL, 
NULL, NULL, NULL, 0, 0);
-               }
-       }
-       GDKfree(query);
-       GDKfree(b);
-       bstream_destroy(m->scanner.rs);
-
-       m->sym = NULL;
-       o.frames = m->frames;   /* may have been realloc'ed */
-       o.sizeframes = m->sizeframes;
-       if (m->session->status || m->errstr[0]) {
-               int status = m->session->status;
-
-               strcpy(o.errstr, m->errstr);
-               *m = o;
-               m->session->status = status;
-       } else {
-               unsigned int label = m->label;
-
-               while (m->topframes > o.topframes)
-                       clear_frame(m, m->frames[--m->topframes]);
-               *m = o;
-               m->label = label;
-       }
-       return s;
+       sql_exp *e = rel_parse_val(be->mvc, query, tpe, emode, NULL);
+       if (e)
+               return exp_bin(be, e, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 
0, 0);
+       return sql_error(be->mvc, 02, SQLSTATE(HY001) MAL_MALLOC_FAIL);
 }
 
 static stmt *
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to