Changeset: 386d9494c808 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=386d9494c808 Modified Files: sql/backends/monet5/rel_bin.c sql/server/rel_optimizer.c sql/server/rel_propagate.c sql/server/rel_psm.c sql/server/rel_rewriter.c sql/server/rel_schema.c sql/server/rel_select.c sql/server/rel_unnest.c sql/server/rel_updates.c sql/test/BugDay_2005-10-06_2.9.3/Tests/bool_boolean.SF-935601.stable.out sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out sql/test/miscellaneous/Tests/groupby_error.sql sql/test/miscellaneous/Tests/groupby_error.stable.out sql/test/miscellaneous/Tests/simple_plans.stable.out sql/test/subquery/Tests/subquery3.stable.err sql/test/subquery/Tests/subquery3.stable.out sql/test/subquery/Tests/subquery5.sql sql/test/subquery/Tests/subquery5.stable.err sql/test/subquery/Tests/subquery5.stable.out Branch: default Log Message:
Merge with Jun2020 diffs (truncated from 1508 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 @@ -24,7 +24,7 @@ #define OUTER_ZERO 64 -static stmt * exp_bin(backend *be, sql_exp *e, stmt *left, stmt *right, stmt *grp, stmt *ext, stmt *cnt, stmt *sel); +static stmt * exp_bin(backend *be, sql_exp *e, stmt *left, stmt *right, stmt *grp, stmt *ext, stmt *cnt, stmt *sel, int depth, int reduce); static stmt * rel_bin(backend *be, sql_rel *rel); static stmt * subrel_bin(backend *be, sql_rel *rel, list *refs); @@ -288,7 +288,7 @@ distinct_value_list(backend *be, list *v s = stmt_temp(be, exp_subtype(vals->h->data)); for( n = vals->h; n; n = n->next) { sql_exp *e = n->data; - stmt *i = exp_bin(be, e, NULL, NULL, NULL, NULL, NULL, NULL); + stmt *i = exp_bin(be, e, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0); if (exp_is_null(be->mvc, e)) *last_null_value = i; @@ -362,16 +362,16 @@ subrel_project( backend *be, stmt *s, li } static stmt * -handle_in_exps(backend *be, sql_exp *ce, list *nl, stmt *left, stmt *right, stmt *grp, stmt *ext, stmt *cnt, stmt *sel, int in, int use_r) +handle_in_exps(backend *be, sql_exp *ce, list *nl, stmt *left, stmt *right, stmt *grp, stmt *ext, stmt *cnt, stmt *sel, int in, int use_r, int depth, int reduce) { mvc *sql = be->mvc; node *n; - stmt *s = NULL, *c = exp_bin(be, ce, left, right, grp, ext, cnt, NULL); + stmt *s = NULL, *c = exp_bin(be, ce, left, right, grp, ext, cnt, NULL, 0, 0); if(!c) return NULL; - if (c->nrcols == 0) { + if (c->nrcols == 0 || (depth && !reduce)) { sql_subtype *bt = sql_bind_localtype("bit"); sql_subfunc *cmp = (in) ?sql_bind_func(sql->sa, sql->session->schema, "=", tail_type(c), tail_type(c), F_FUNC) @@ -381,7 +381,7 @@ handle_in_exps(backend *be, sql_exp *ce, for( n = nl->h; n; n = n->next) { sql_exp *e = n->data; - stmt *i = exp_bin(be, use_r?e->r:e, left, right, grp, ext, cnt, NULL); + stmt *i = exp_bin(be, use_r?e->r:e, left, right, grp, ext, cnt, NULL, 0, 0); if(!i) return NULL; @@ -392,7 +392,7 @@ handle_in_exps(backend *be, sql_exp *ce, s = i; } - if (sel) + if (sel && !(depth && !reduce)) s = stmt_uselect(be, stmt_const(be, bin_first_column(be, left), s), stmt_bool(be, 1), cmp_equal, sel, 0, 0); @@ -403,7 +403,7 @@ handle_in_exps(backend *be, sql_exp *ce, s = sel; for( n = nl->h; n; n = n->next) { sql_exp *e = n->data; - stmt *i = exp_bin(be, use_r?e->r:e, left, right, grp, ext, cnt, NULL); + stmt *i = exp_bin(be, use_r?e->r:e, left, right, grp, ext, cnt, NULL, 0, 0); if(!i) return NULL; @@ -482,7 +482,7 @@ value_list(backend *be, list *vals, stmt s = stmt_temp(be, type); for( n = vals->h; n; n = n->next) { sql_exp *e = n->data; - stmt *i = exp_bin(be, e, left, NULL, NULL, NULL, NULL, sel); + stmt *i = exp_bin(be, e, left, NULL, NULL, NULL, NULL, sel, 0, 0); if (!i) return NULL; @@ -503,7 +503,7 @@ exp_list(backend *be, list *exps, stmt * for( n = exps->h; n; n = n->next) { sql_exp *e = n->data; - stmt *i = exp_bin(be, e, l, r, grp, ext, cnt, sel); + stmt *i = exp_bin(be, e, l, r, grp, ext, cnt, sel, 0, 0); if(!i) return NULL; @@ -533,7 +533,7 @@ exp_count_no_nil_arg( sql_exp *e, stmt * } stmt * -exp_bin(backend *be, sql_exp *e, stmt *left, stmt *right, stmt *grp, stmt *ext, stmt *cnt, stmt *sel) +exp_bin(backend *be, sql_exp *e, stmt *left, stmt *right, stmt *grp, stmt *ext, stmt *cnt, stmt *sel, int depth, int reduce) { mvc *sql = be->mvc; stmt *s = NULL; @@ -549,7 +549,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l switch(e->type) { case e_psm: if (e->flag & PSM_SET) { - stmt *r = exp_bin(be, e->l, left, right, grp, ext, cnt, sel); + stmt *r = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, 0, 0); if(!r) return NULL; if (e->card <= CARD_ATOM && r->nrcols > 0) /* single value, get result from bat */ @@ -562,7 +562,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l return stmt_var(be, exp_name(e), &e->tpe, 1, GET_PSM_LEVEL(e->flag)); } else if (e->flag & PSM_RETURN) { sql_exp *l = e->l; - stmt *r = exp_bin(be, l, left, right, grp, ext, cnt, sel); + stmt *r = exp_bin(be, l, left, right, grp, ext, cnt, sel, 0, 0); if (!r) return NULL; @@ -590,7 +590,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l /* while is a if - block true with leave statement * needed because the condition needs to be inside this outer block */ stmt *ifstmt = stmt_cond(be, stmt_bool(be, 1), NULL, 0, 0); - stmt *cond = exp_bin(be, e->l, left, right, grp, ext, cnt, sel); + stmt *cond = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, 0, 0); stmt *wstmt; if(!cond) @@ -602,7 +602,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l (void)stmt_control_end(be, wstmt); return stmt_control_end(be, ifstmt); } else if (e->flag & PSM_IF) { - stmt *cond = exp_bin(be, e->l, left, right, grp, ext, cnt, sel); + stmt *cond = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, 0, 0); stmt *ifstmt, *res; if(!cond) @@ -629,7 +629,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l return r; return stmt_table(be, r, 1); } else if (e->flag & PSM_EXCEPTION) { - stmt *cond = exp_bin(be, e->l, left, right, grp, ext, cnt, sel); + stmt *cond = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, 0, 0); if (!cond) return NULL; return stmt_exception(be, cond, (const char *) e->r, 0); @@ -657,7 +657,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l if (from->type->localtype == 0) { l = stmt_atom(be, atom_general(sql->sa, to, NULL)); } else { - l = exp_bin(be, e->l, left, right, grp, ext, cnt, sel); + l = exp_bin(be, e->l, left, right, grp, ext, cnt, sel, depth+1, 0); } if (!l) return NULL; @@ -693,7 +693,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l sql_exp *e = en->data; stmt *es; - es = exp_bin(be, e, left, right, grp, ext, cnt, (push_cands)?sel:NULL); + es = exp_bin(be, e, left, right, grp, ext, cnt, (push_cands)?sel:NULL, depth+1, 0); if (!es) return NULL; @@ -787,7 +787,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l for (en = attr->h; en; en = en->next) { sql_exp *at = en->data; - as = exp_bin(be, at, left, right, NULL, NULL, NULL, sel); + as = exp_bin(be, at, left, right, NULL, NULL, NULL, sel, depth+1, 0); if (as && as->nrcols <= 0 && left) as = stmt_const(be, bin_first_column(be, left), as); @@ -851,6 +851,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l int swapped = 0, is_select = 0; sql_exp *re = e->r, *re2 = e->f; + assert((reduce && !depth) || e->flag == cmp_in || e->flag == cmp_notin); + /* general predicate, select and join */ if (e->flag == cmp_filter) { list *args; @@ -863,9 +865,9 @@ exp_bin(backend *be, sql_exp *e, stmt *l for( n = args->h; n; n = n->next ) { s = NULL; if (!swapped) - s = exp_bin(be, n->data, left, NULL, grp, ext, cnt, NULL); + s = exp_bin(be, n->data, left, NULL, grp, ext, cnt, NULL, depth+1, reduce); if (!s && (first || swapped)) { - s = exp_bin(be, n->data, right, NULL, grp, ext, cnt, NULL); + s = exp_bin(be, n->data, right, NULL, grp, ext, cnt, NULL, depth+1, reduce); swapped = 1; } if (!s) @@ -879,7 +881,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l ops = sa_list(sql->sa); args = e->r; for( n = args->h; n; n = n->next ) { - s = exp_bin(be, n->data, (swapped || !right)?left:right, NULL, grp, ext, cnt, NULL); + s = exp_bin(be, n->data, (swapped || !right)?left:right, NULL, grp, ext, cnt, NULL, depth+1, reduce); if (!s) return s; list_append(ops, s); @@ -895,7 +897,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l return s; } 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); + 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"); @@ -913,7 +915,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l /* propagate the anti flag */ if (anti) set_anti(c); - s = exp_bin(be, c, left, right, grp, ext, cnt, sin); + s = exp_bin(be, c, left, right, grp, ext, cnt, sin, depth, reduce); if (!s) return s; @@ -940,7 +942,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l /* propagate the anti flag */ if (anti) set_anti(c); - s = exp_bin(be, c, left, right, grp, ext, cnt, sin); + s = exp_bin(be, c, left, right, grp, ext, cnt, sin, depth, reduce); if (!s) return s; @@ -989,27 +991,27 @@ exp_bin(backend *be, sql_exp *e, stmt *l sql->opt_stats[0]++; if (!l) { - l = exp_bin(be, e->l, left, NULL, grp, ext, cnt, sel); + l = exp_bin(be, e->l, left, NULL, grp, ext, cnt, sel, depth+1, reduce); swapped = 0; } if (!l && right) { - l = exp_bin(be, e->l, right, NULL, grp, ext, cnt, sel); + l = exp_bin(be, e->l, right, NULL, grp, ext, cnt, sel, depth+1, reduce); swapped = 1; } if (swapped || !right) - r = exp_bin(be, re, left, NULL, grp, ext, cnt, sel); + r = exp_bin(be, re, left, NULL, grp, ext, cnt, sel, depth+1, reduce); else - r = exp_bin(be, re, right, NULL, grp, ext, cnt, sel); + r = exp_bin(be, re, right, NULL, grp, ext, cnt, sel, depth+1, reduce); if (!r && !swapped) { - r = exp_bin(be, re, left, NULL, grp, ext, cnt, sel); + r = exp_bin(be, re, left, NULL, grp, ext, cnt, sel, depth+1, reduce); is_select = 1; } if (!r && swapped) { - r = exp_bin(be, re, right, NULL, grp, ext, cnt, sel); + r = exp_bin(be, re, right, NULL, grp, ext, cnt, sel, depth+1, reduce); is_select = 1; } if (re2) - r2 = exp_bin(be, re2, left, right, grp, ext, cnt, sel); + r2 = exp_bin(be, re2, left, right, grp, ext, cnt, sel, depth+1, reduce); if (!l || !r || (re2 && !r2)) { TRC_ERROR(SQL_EXECUTION, "Query: '%s'\n", sql->query); @@ -1421,7 +1423,7 @@ rel_parse_value(backend *be, char *query 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); + s = exp_bin(be, e, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0); } } GDKfree(query); @@ -1558,7 +1560,7 @@ rel2bin_basetable(backend *be, sql_rel * append(l, s); if (exps->h->next) { sql_exp *at = exps->h->next->data; - stmt *u = exp_bin(be, at, NULL, NULL, NULL, NULL, NULL, NULL); + stmt *u = exp_bin(be, at, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0); if(!u) return NULL; @@ -1810,7 +1812,7 @@ rel2bin_table(backend *be, sql_rel *rel, sql_exp *e = en->data; /* find column */ - stmt *s = exp_bin(be, e, sub, NULL, NULL, NULL, NULL, NULL); + stmt *s = exp_bin(be, e, sub, NULL, NULL, NULL, NULL, NULL, 0, 0); if (!s) return NULL; if (en->next) @@ -1820,7 +1822,7 @@ rel2bin_table(backend *be, sql_rel *rel, } } } else { - psub = exp_bin(be, op, sub, NULL, NULL, NULL, NULL, NULL); /* table function */ + psub = exp_bin(be, op, sub, NULL, NULL, NULL, NULL, NULL, 0, 0); /* table function */ if (!psub) return NULL; } @@ -2007,9 +2009,9 @@ rel2bin_hash_lookup(backend *be, sql_rel if (e->type == e_cmp && e->flag == cmp_equal) { sql_exp *ee = (swap_exp)?e->l:e->r; if (swap_rel) - s = exp_bin(be, ee, left, NULL, NULL, NULL, NULL, NULL); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list