Changeset: d834d31b360d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d834d31b360d
Modified Files:
        sql/backends/monet5/rel_bin.c
        sql/server/rel_optimizer.c
        sql/server/sql_mvc.c
        sql/server/sql_mvc.h
        
sql/test/BugTracker-2017/Tests/type-resolution-error.Bugs-6313.stable.err
Branch: Mar2018
Log Message:

cleanup subquery administration


diffs (163 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
@@ -557,10 +557,10 @@ exp_bin(backend *be, sql_exp *e, stmt *l
                if (!s && left) 
                        s = bin_find_column(be, left, e->l, e->r);
                if (!s) {
-                       sql_rel *rel = mvc_find_subquery(be->mvc, 
e->l?e->l:e->r, e->r);
-
-                       if (rel) { 
-                               stmt *s = rel->p;
+                       sql_subquery *sq = mvc_find_subquery(be->mvc, 
e->l?e->l:e->r, e->r);
+
+                       if (sq) { 
+                               stmt *s = sq->s;
 
                                if (s && s->type == st_list)
                                        s = bin_find_column(be, s, 
e->l?e->l:e->r, e->r);
@@ -5122,9 +5122,10 @@ static stmt *
                node *n;
 
                for(n = be->mvc->sqs->h; n; n = n->next) {
-                       sql_var *v = n->data;
-
-                       v->rel->p = subrel_bin(be, v->rel, refs);
+                       sql_subquery *v = n->data;
+
+                       if (!v->s)
+                               v->s = subrel_bin(be, v->rel, refs);
                }
        }
        return subrel_bin(be, rel, refs);
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
@@ -6552,7 +6552,7 @@ rel_dce(mvc *sql, sql_rel *rel)
                node *n;
 
                for(n = sql->sqs->h; n; n = n->next) {
-                       sql_var *v = n->data;
+                       sql_subquery *v = n->data;
                        sql_rel *i = v->rel;
 
                        while (!rel_is_ref(i) && i->l && !is_base(i->op))
@@ -9340,7 +9340,7 @@ rel_optimizer(mvc *sql, sql_rel *rel)
                node *n;
 
                for(n = sql->sqs->h; n; n = n->next) {
-                       sql_var *v = n->data;
+                       sql_subquery *v = n->data;
 
                        v->rel = optimize(sql, v->rel);
                }
diff --git a/sql/server/sql_mvc.c b/sql/server/sql_mvc.c
--- a/sql/server/sql_mvc.c
+++ b/sql/server/sql_mvc.c
@@ -1829,25 +1829,26 @@ mvc_copy_idx(mvc *m, sql_table *t, sql_i
        return sql_trans_copy_idx(m->session->tr, t, i);
 }
 
-sql_rel *
+sql_subquery *
 mvc_push_subquery(mvc *m, const char *name, sql_rel *r)
 {
-       sql_rel *res = NULL;
+       sql_subquery *res = NULL;
 
        if (!m->sqs)
                m->sqs = sa_list(m->sa);
        if (m->sqs) {
-               sql_var *v = SA_NEW(m->sa, sql_var);
+               sql_subquery *v = SA_NEW(m->sa, sql_subquery);
 
                v->name = name;
                v->rel = r;
+               v->s = NULL;
                list_append(m->sqs, v);
-               res = r;
+               res = v;
        }
        return res;
 }
 
-sql_rel *
+sql_subquery *
 mvc_find_subquery(mvc *m, const char *rname, const char *name) 
 {
        node *n;
@@ -1855,13 +1856,13 @@ mvc_find_subquery(mvc *m, const char *rn
        if (!m->sqs)
                return NULL;
        for (n = m->sqs->h; n; n = n->next) {
-               sql_var *v = n->data;
+               sql_subquery *v = n->data;
 
                if (strcmp(v->name, rname) == 0) {
                        sql_exp *ne = exps_bind_column2(v->rel->exps, rname, 
name);
 
                        if (ne)
-                               return v->rel;
+                               return v;
                }
        }
        return NULL;
@@ -1875,7 +1876,7 @@ mvc_find_subexp(mvc *m, const char *rnam
        if (!m->sqs)
                return NULL;
        for (n = m->sqs->h; n; n = n->next) {
-               sql_var *v = n->data;
+               sql_subquery *v = n->data;
 
                if (strcmp(v->name, rname) == 0) {
                        sql_exp *ne = exps_bind_column2(v->rel->exps, rname, 
name);
diff --git a/sql/server/sql_mvc.h b/sql/server/sql_mvc.h
--- a/sql/server/sql_mvc.h
+++ b/sql/server/sql_mvc.h
@@ -74,6 +74,12 @@ typedef struct sql_var {
        char frame;
 } sql_var;
 
+typedef struct sql_subquery {
+       const char *name;
+       sql_rel *rel;   
+       void *s;
+} sql_subquery;
+
 #define MAXSTATS 8
 
 typedef struct mvc {
@@ -262,8 +268,8 @@ extern sql_idx *mvc_copy_idx(mvc *m, sql
 extern void *sql_error(mvc *sql, int error_code, _In_z_ _Printf_format_string_ 
char *format, ...)
        __attribute__((__format__(__printf__, 3, 4)));
 
-extern sql_rel *mvc_push_subquery(mvc *m, const char *name, sql_rel *r);
-extern sql_rel *mvc_find_subquery(mvc *m, const char *rname, const char *name);
+extern sql_subquery *mvc_push_subquery(mvc *m, const char *name, sql_rel *r);
+extern sql_subquery *mvc_find_subquery(mvc *m, const char *rname, const char 
*name);
 extern sql_exp *mvc_find_subexp(mvc *m, const char *rname, const char *name);
 
 #endif /*_SQL_MVC_H*/
diff --git 
a/sql/test/BugTracker-2017/Tests/type-resolution-error.Bugs-6313.stable.err 
b/sql/test/BugTracker-2017/Tests/type-resolution-error.Bugs-6313.stable.err
--- a/sql/test/BugTracker-2017/Tests/type-resolution-error.Bugs-6313.stable.err
+++ b/sql/test/BugTracker-2017/Tests/type-resolution-error.Bugs-6313.stable.err
@@ -44,6 +44,19 @@ QUERY = select auxiliary
           or ((select index_type_name from sys.index_types) is not NULL);
 ERROR = !SELECT: no such table 'region'
 CODE  = 42S02
+MAPI  = (monetdb) /var/tmp/mtest-32496/.s.monetdb.36380
+QUERY = select
+                  sample_69.f_table_catalog as c2
+        from    
+          sys.storagemodel as sample_65
+               left join sys.geometry_columns as sample_69
+               on (sample_65.type = sample_69.f_table_catalog )
+                where 
+                ((select default_schema from sys.users) is NULL)
+                  or (cast(coalesce((select side_effect from sys.functions) ,
+                      sample_65.revsorted) as boolean) is not NULL);
+ERROR = !Cardinality violation, scalar value expected
+CODE  = 21000
 
 # 12:52:03 >  
 # 12:52:03 >  "Done."
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to