Changeset: ce93ebd4e34a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ce93ebd4e34a
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_statement.c
sql/backends/monet5/sql_statement.h
sql/test/SQLancer/Tests/sqlancer09.stable.out
Branch: Oct2020
Log Message:
Fix for sqlancer09 query, push candidates for functions at stmt_Nop, so it
becomes generalized at other parts of the code generation.
However I have to check a corner case at coalesce (not changed there yet).
diffs (truncated from 660 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
@@ -75,7 +75,7 @@ sql_unop_(backend *be, sql_schema *s, co
f->res.scale = rt->scale;
}
*/
- return stmt_unop(be, rs, f);
+ return stmt_unop(be, rs, NULL, f);
} else if (rs) {
char *type = tail_type(rs)->type->sqlname;
@@ -395,9 +395,9 @@ handle_in_exps(backend *be, sql_exp *ce,
if(!i)
return NULL;
- i = stmt_binop(be, c, i, cmp);
+ i = stmt_binop(be, c, i, sel, cmp);
if (s)
- s = stmt_binop(be, s, i, a);
+ s = stmt_binop(be, s, i, sel, a);
else
s = i;
@@ -558,7 +558,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt
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);
+ s = stmt_binop(be, sel1, s, sin, f);
} else if (sel1 && (sel1->nrcols == 0 || s->nrcols == 0)) {
stmt *predicate = bin_first_column(be, left);
@@ -585,7 +585,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt
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);
+ s = stmt_binop(be, sel2, s, sin, f);
} else if (sel2 && (sel2->nrcols == 0 || s->nrcols == 0)) {
stmt *predicate = bin_first_column(be, left);
@@ -600,7 +600,7 @@ exp_bin_or(backend *be, sql_exp *e, stmt
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);
+ return stmt_binop(be, sel1, sel2, NULL, f);
}
if (sel1->nrcols == 0) {
stmt *predicate = bin_first_column(be, left);
@@ -714,7 +714,7 @@ exp2bin_case(backend *be, sql_exp *fe, s
assert(next_cond);
if (next_cond) {
if (cond) {
- ncond = stmt_binop(be, cond,
es, and);
+ ncond = stmt_binop(be, cond,
es, nsel, and);
} else {
ncond = es;
}
@@ -728,12 +728,12 @@ exp2bin_case(backend *be, sql_exp *fe, s
res = NULL;
if (en->next) {
- cond = stmt_unop(be, cond, not);
+ cond = stmt_unop(be, cond, nsel, not);
sql_subfunc *isnull =
sql_bind_func(be->mvc->sa, be->mvc->session->schema, "isnull", bt, NULL,
F_FUNC);
- cond = stmt_binop(be, cond,
stmt_unop(be, cond, isnull), or);
+ cond = stmt_binop(be, cond,
stmt_unop(be, cond, nsel, isnull), nsel, or);
if (ocond)
- cond = stmt_binop(be, ocond,
cond, and);
+ cond = stmt_binop(be, ocond,
cond, nsel, and);
ocond = cond;
if (!en->next->next)
ncond = cond;
@@ -799,7 +799,7 @@ exp2bin_coalesce(backend *be, sql_exp *f
if (en->next) {
sql_subfunc *a =
sql_bind_func(be->mvc->sa, be->mvc->session->schema, "isnotnull",
tail_type(es), NULL, F_FUNC);
- ncond = stmt_unop(be, es, a);
+ ncond = stmt_unop(be, es, NULL, a);
/*TODO sql/test/coalesce failing for passing 'nsel' here */
if (ncond->nrcols == 0) {
stmt *l = bin_first_column(be,
left);
if (nsel && l)
@@ -839,10 +839,10 @@ exp2bin_coalesce(backend *be, sql_exp *f
stmt *cond = ocond;
if (en->next) {
sql_subfunc *a = sql_bind_func(be->mvc->sa,
be->mvc->session->schema, "isnotnull", tail_type(es), NULL, F_FUNC);
- ncond = stmt_unop(be, es, a);
+ ncond = stmt_unop(be, es, nsel, a);
if (ocond)
- cond = stmt_binop(be, ocond, ncond,
and);
+ cond = stmt_binop(be, ocond, ncond,
nsel, and);
else
cond = ncond;
}
@@ -854,9 +854,9 @@ exp2bin_coalesce(backend *be, sql_exp *f
/* endif_barrier */
(void)stmt_control_end(be, b);
- cond = stmt_unop(be, ncond, not);
+ cond = stmt_unop(be, ncond, nsel, not);
if (ocond)
- ocond = stmt_binop(be, cond, ocond, and);
+ ocond = stmt_binop(be, cond, ocond, nsel, and);
else
ocond = cond;
}
@@ -1003,11 +1003,8 @@ exp_bin(backend *be, sql_exp *e, stmt *l
node *en;
list *l = sa_list(sql->sa), *exps = e->l;
sql_subfunc *f = e->f;
- stmt *rows = NULL, *isel = sel;
- int nrcands = 0, push_cands = 0;
-
- if (sel && (strcmp(sql_func_mod(f->func), "calc") == 0 ||
strcmp(sql_func_mod(f->func), "mmath") == 0))
- push_cands = 1;
+ stmt *rows = NULL;
+ int nrcands = 0, push_cands = can_push_cands(sel, f);
if (f->func->side_effect && left && left->nrcols > 0) {
sql_subfunc *f1 = NULL;
@@ -1051,33 +1048,15 @@ exp_bin(backend *be, sql_exp *e, stmt *l
}
if (es->nrcols > nrcols)
nrcols = es->nrcols;
- list_append(l,es);
- if (push_cands && es->nrcols)
- nrcands++;
- }
- }
- if (push_cands) {
- int i;
- for (i=0, en = l->h; i<nrcands && en; en = en->next) {
- stmt *s = en->data;
- /* if handled use bat nil */
- if (s->nrcols) { /* only for cols not values */
- i++;
- if (s->cand && s->cand == isel)
- list_append(l, NULL);
- else
- list_append(l,sel);
- }
+ list_append(l, es);
}
}
if (f->func->rel)
s = stmt_func(be, stmt_list(be, l), sa_strdup(sql->sa,
f->func->base.name), f->func->rel, (f->func->type == F_UNION));
else
- s = stmt_Nop(be, stmt_list(be, l), f);
+ s = stmt_Nop(be, stmt_list(be, l), sel, f);
if (!s)
return NULL;
- if (s && isel && push_cands && s->nrcols)
- s->cand = isel;
} break;
case e_aggr: {
list *attr = e->l;
@@ -1301,7 +1280,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
in_flag = !in_flag;
sql_subfunc *f = sql_bind_func(sql->sa,
sql->session->schema, in_flag?"=":"<>", tail_type(l), tail_type(l), F_FUNC);
assert(f);
- s = stmt_binop(be, l, r, f);
+ s = stmt_binop(be, l, r, sel, f);
if (l->cand)
s->cand = l->cand;
if (r->cand)
@@ -1320,10 +1299,10 @@ exp_bin(backend *be, sql_exp *e, stmt *l
list_append(args, l);
list_append(args, r);
list_append(args,
stmt_bool(be, 1));
- s = stmt_Nop(be,
stmt_list(be, args), f);
+ s = stmt_Nop(be,
stmt_list(be, args), sel, f);
}
} else {
- s = stmt_binop(be, l, r, f);
+ s = stmt_binop(be, l, r, sel,
f);
}
if (l->cand)
s->cand = l->cand;
@@ -1466,7 +1445,7 @@ sql_Nop_(backend *be, const char *fname,
f = sql_bind_func_(sql->sa, sql->session->schema, fname, tl, F_FUNC);
if (f)
- return stmt_Nop(be, stmt_list(be, sl), f);
+ return stmt_Nop(be, stmt_list(be, sl), NULL, f);
return sql_error(sql, 02, SQLSTATE(42000) "SELECT: no such operator
'%s'", fname);
}
@@ -1592,7 +1571,7 @@ rel2bin_basetable(backend *be, sql_rel *
append(l, u);
}
- s = stmt_Nop(be, stmt_list(be, l), exp->f);
+ s = stmt_Nop(be, stmt_list(be, l), NULL, exp->f);
} else if (oname[0] == '%' && strcmp(oname, TID) == 0) {
/* tid function sql.tid(t) */
const char *rnme = t->base.name;
@@ -2055,12 +2034,12 @@ rel2bin_hash_lookup(backend *be, sql_rel
sql_subfunc *xor = sql_bind_func_result(sql->sa,
sql->session->schema, "rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s));
h = stmt_Nop(be, stmt_list(be, list_append( list_append(
- list_append(sa_list(sql->sa), h), bits), s)),
xor);
+ list_append(sa_list(sql->sa), h), bits), s)),
NULL, xor);
semantics = 1;
} else {
sql_subfunc *hf = sql_bind_func_result(sql->sa,
sql->session->schema, "hash", F_FUNC, lng, 1, tail_type(s));
- h = stmt_unop(be, s, hf);
+ h = stmt_unop(be, s, NULL, hf);
}
}
if (h && h->nrcols) {
@@ -2091,10 +2070,10 @@ join_hash_key( backend *be, list *l )
if (h) {
sql_subfunc *xor = sql_bind_func_result(sql->sa,
sql->session->schema, "rotate_xor_hash", F_FUNC, lng, 3, lng, it, tail_type(s));
- h = stmt_Nop(be, stmt_list(be, list_append(
list_append( list_append(sa_list(sql->sa), h), bits), s )), xor);
+ h = stmt_Nop(be, stmt_list(be, list_append(
list_append( list_append(sa_list(sql->sa), h), bits), s )), NULL, xor);
} else {
sql_subfunc *hf = sql_bind_func_result(sql->sa,
sql->session->schema, "hash", F_FUNC, lng, 1, tail_type(s));
- h = stmt_unop(be, s, hf);
+ h = stmt_unop(be, s, NULL, hf);
}
}
return h;
@@ -2157,7 +2136,7 @@ releqjoin( backend *be, list *l1, list *
}
if (semantics)
list_append(ops, stmt_bool(be, 1));
- cmp = stmt_Nop(be, stmt_list(be, ops), f);
+ cmp = stmt_Nop(be, stmt_list(be, ops), NULL, f);
cmp = stmt_uselect(be, cmp, stmt_bool(be, 1), cmp_equal, NULL,
0, 0);
l = stmt_project(be, cmp, l );
r = stmt_project(be, cmp, r );
@@ -2977,7 +2956,7 @@ rel2bin_except(backend *be, sql_rel *rel
rcnt = stmt_append(be, rcnt, zero);
min = sql_bind_func(sql->sa, sql->session->schema, "sql_sub", lng, lng,
F_FUNC);
- s = stmt_binop(be, lcnt, rcnt, min); /* use count */
+ s = stmt_binop(be, lcnt, rcnt, NULL, min); /* use count */
/* now we have gid,cnt, blowup to full groupsizes */
s = stmt_gen_group(be, lext, s);
@@ -3075,7 +3054,7 @@ rel2bin_inter(backend *be, sql_rel *rel,
rcnt = stmt_project(be, rm, rcnt);
min = sql_bind_func(sql->sa, sql->session->schema, "sql_min", lng, lng,
F_FUNC);
- s = stmt_binop(be, lcnt, rcnt, min);
+ s = stmt_binop(be, lcnt, rcnt, NULL, min);
/* now we have gid,cnt, blowup to full groupsizes */
s = stmt_gen_group(be, lext, s);
@@ -3164,7 +3143,7 @@ rel2bin_project(backend *be, sql_rel *re
stmt *o = exp_bin(be, oe, NULL, NULL, NULL,
NULL, NULL, NULL, 0, 0, 0);
if(!o)
return NULL;
- l = stmt_binop(be, l, o, add);
+ l = stmt_binop(be, l, o, NULL, add);
}
}
}
@@ -3676,7 +3655,7 @@ insert_check_ukey(backend *be, list *ins
s = releqjoin(be, lje, rje, NULL, 1 /* hash used */, 0,
0);
s = stmt_result(be, s, 0);
}
- s = stmt_binop(be, stmt_aggr(be, s, NULL, NULL, cnt, 1, 0, 1),
stmt_atom_lng(be, 0), ne);
+ s = stmt_binop(be, stmt_aggr(be, s, NULL, NULL, cnt, 1, 0, 1),
stmt_atom_lng(be, 0), NULL, ne);
/* 2nd stage: find out if inserted are unique */
if ((!idx_inserts && ins->nrcols) || (idx_inserts &&
idx_inserts->nrcols)) { /* insert columns not atoms */
@@ -3716,7 +3695,7 @@ insert_check_ukey(backend *be, list *ins
sum = sql_bind_func(sql->sa, sql->session->schema,
"not_unique", tail_type(orderby_grp), NULL, F_AGGR);
ssum = stmt_aggr(be, orderby_grp, NULL, NULL, sum, 1,
0, 1);
/* combine results */
- s = stmt_binop(be, s, ssum, or);
+ s = stmt_binop(be, s, ssum, NULL, or);
}
if (k->type == pkey) {
@@ -3745,7 +3724,7 @@ insert_check_ukey(backend *be, list *ins
s = stmt_aggr(be, s, NULL, NULL, cnt, 1, 0, 1);
}
/* s should be empty */
- s = stmt_binop(be, s, stmt_atom_lng(be, 0), ne);
+ s = stmt_binop(be, s, stmt_atom_lng(be, 0), NULL, ne);
/* 2e stage: find out if inserts are unique */
if (h->nrcols) { /* insert multiple atoms */
@@ -3768,10 +3747,10 @@ insert_check_ukey(backend *be, list *ins
sum = sql_bind_func(sql->sa, sql->session->schema,
"sum", lng, NULL, F_AGGR);
ssum = stmt_aggr(be, ss, NULL, NULL, sum, 1, 0, 1);
ssum = sql_Nop_(be, "ifthenelse", sql_unop_(be, NULL,
"isnull", ssum), stmt_atom_lng(be, 0), ssum, NULL);
- count_sum = stmt_binop(be, check_types(be,
tail_type(ssum), stmt_aggr(be, ss, NULL, NULL, cnt, 1, 0, 1), type_equal),
ssum, ne);
+ count_sum = stmt_binop(be, check_types(be,
tail_type(ssum), stmt_aggr(be, ss, NULL, NULL, cnt, 1, 0, 1), type_equal),
ssum, NULL, ne);
/* combine results */
- s = stmt_binop(be, s, count_sum, or);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list