Changeset: 78991d4cff5c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/78991d4cff5c
Modified Files:
sql/backends/monet5/rel_bin.c
sql/backends/monet5/sql_execute.c
sql/backends/monet5/sql_statement.c
sql/test/SQLancer/Tests/sqlancer19.SQL.py
Branch: default
Log Message:
When generating a statement from a sql function or table relation with a
subquery, then inner relation may get rewritten by an optimizer, so update
pointer afterwards
diffs (124 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
@@ -1294,12 +1294,13 @@ exp_bin(backend *be, sql_exp *e, stmt *l
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), sel, f);
- if (!s)
+ if (f->func->rel) {
+ if (!(s = stmt_func(be, stmt_list(be, l),
sa_strdup(sql->sa, f->func->base.name), f->func->rel, (f->func->type ==
F_UNION))))
+ return NULL;
+ f->func->rel = s->op4.rel; /* f->func->rel may get
rewritten */
+ } else if (!(s = stmt_Nop(be, stmt_list(be, l), sel, f))) {
return NULL;
+ }
} break;
case e_aggr: {
list *attr = e->l;
@@ -2166,18 +2167,6 @@ rel2bin_table(backend *be, sql_rel *rel,
s = stmt_alias(be, s, rnme, a->name);
list_append(l, s);
}
-#if 0
- if (list_length(f->res) ==
list_length(f->func->res) + 1) {
- assert(0);
- /* add missing %TID% column */
- sql_subtype *t = f->res->t->data;
- stmt *s = stmt_rs_column(be, psub, i,
t);
- const char *rnme =
exp_find_rel_name(op);
-
- s = stmt_alias(be, s, rnme, TID);
- list_append(l, s);
- }
-#endif
}
}
assert(rel->flag != TABLE_PROD_FUNC || !sub || !(sub->nrcols));
@@ -2195,7 +2184,7 @@ rel2bin_table(backend *be, sql_rel *rel,
sub = stmt_list(be, l);
if (!(sub = stmt_func(be, sub, sa_strdup(sql->sa, nme), rel->l,
0)))
return NULL;
- fr = rel->l;
+ fr = rel->l = sub->op4.rel; /* rel->l may get rewritten */
l = sa_list(sql->sa);
for(i = 0, n = rel->exps->h; n; n = n->next, i++ ) {
sql_exp *c = n->data;
diff --git a/sql/backends/monet5/sql_execute.c
b/sql/backends/monet5/sql_execute.c
--- a/sql/backends/monet5/sql_execute.c
+++ b/sql/backends/monet5/sql_execute.c
@@ -774,20 +774,16 @@ RAstatement(Client c, MalBlkPtr mb, MalS
return RAcommit_statement(be,
createException(SQL,"RAstatement",SQLSTATE(HY013) MAL_MALLOC_FAIL));
refs = sa_list(m->sa);
rel = rel_read(m, *expr, &pos, refs);
+ if (*opt && rel)
+ rel = sql_processrelation(m, rel, 1, 1);
if (!rel) {
if (strlen(m->errstr) > 6 && m->errstr[5] == '!')
msg = createException(SQL, "RAstatement", "%s",
m->errstr);
else
msg = createException(SQL, "RAstatement",
SQLSTATE(42000) "%s", m->errstr);
} else {
-
- if (*opt && rel)
- rel = sql_processrelation(m, rel, 1, 1);
-
- if ((msg = MSinitClientPrg(c, sql_private_module_name, "test"))
!= MAL_SUCCEED) {
- rel_destroy(rel);
+ if ((msg = MSinitClientPrg(c, sql_private_module_name, "test"))
!= MAL_SUCCEED)
return RAcommit_statement(be, msg);
- }
/* generate MAL code, ignoring any code generation error */
setVarType(c->curprg->def, 0, 0);
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
@@ -3408,17 +3408,17 @@ stmt_func(backend *be, stmt *ops, const
if (ops && ops->nr < 0)
return NULL;
- p = find_prop(rel->p, PROP_REMOTE);
- if (p)
+ if ((p = find_prop(rel->p, PROP_REMOTE)))
rel->p = prop_remove(rel->p, p);
- rel = sql_processrelation(be->mvc, rel, 1, 1);
+ if (!(rel = sql_processrelation(be->mvc, rel, 1, 1)))
+ return NULL;
if (p) {
p->p = rel->p;
rel->p = p;
}
if (monet5_create_relational_function(be->mvc, mod, name, rel, ops,
NULL, 1) < 0)
- return NULL;
+ return NULL;
if (f_union)
q = newStmt(mb, batmalRef, multiplexRef);
diff --git a/sql/test/SQLancer/Tests/sqlancer19.SQL.py
b/sql/test/SQLancer/Tests/sqlancer19.SQL.py
--- a/sql/test/SQLancer/Tests/sqlancer19.SQL.py
+++ b/sql/test/SQLancer/Tests/sqlancer19.SQL.py
@@ -228,6 +228,18 @@ with SQLTestCase() as cli:
.assertSucceeded().assertDataResultMatch([(7,)])
cli.execute("SELECT count(*) FROM ((select 7 from t3, (values (1)) y(y))
union all (select 3)) x(x);") \
.assertSucceeded().assertDataResultMatch([(7,)])
+ cli.execute("create view v2(vc0) as ((select 3 from rt3) intersect (select
2 from t3));") \
+ .assertSucceeded()
+ cli.execute("create view v3(vc0) as (select 1 from rt3, v2 where
\"right_shift_assign\"(inet '228.236.62.235/6', inet '82.120.56.164'));") \
+ .assertSucceeded()
+ cli.execute("create view v4(vc0, vc1, vc2) as (select 1, 2, 3);") \
+ .assertSucceeded()
+ cli.execute("create view v5(vc0) as ((select time '01:00:00') intersect
(select time '01:00:00' from v3));") \
+ .assertSucceeded()
+ cli.execute("create view v6(vc0) as ((select 1) union all (select 2));") \
+ .assertSucceeded()
+ cli.execute("select 1 from v4, v5, v6;") \
+ .assertSucceeded().assertDataResultMatch([])
cli.execute("ROLLBACK;")
cli.execute("""
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list