Changeset: d7746408f269 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=d7746408f269
Modified Files:
        sql/server/rel_select.c
        sql/server/rel_unnest.c
        sql/test/BugTracker-2009/Tests/assert_in_update.SF-2807336.stable.err
        sql/test/mergetables/Tests/part-elim.stable.out
Branch: Jun2020
Log Message:

fixed problem with unnesting of in expressions with multiple correlated 
subqueries


diffs (124 lines):

diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -745,7 +745,8 @@ exp_values_set_supertype(mvc *sql, sql_e
                        e = rel_check_type(sql, &values->tpe, NULL, e, 
type_equal);
                        if (!e)
                                return NULL;
-                       append(nexps, e); 
+                       exp_label(sql->sa, e, ++sql->label);
+                       append(nexps, e);
                }
                values->f = nexps;
        }
@@ -2045,7 +2046,6 @@ rel_in_value_exp(sql_query *query, sql_r
                        }
                } else { /* if it's not a tuple, enforce coersion on the type 
for every element on the list */
                        values = exp_values_set_supertype(sql, values);
-
                        if (rel_binop_check_types(sql, rel ? *rel : NULL, le, 
values, 0) < 0)
                                return NULL;
                }
diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c
--- a/sql/server/rel_unnest.c
+++ b/sql/server/rel_unnest.c
@@ -1786,7 +1786,7 @@ rel_union_exps(mvc *sql, sql_exp **l, li
                sql_exp *ve = n->data, *r, *s;
                sql_rel *sq = NULL;
 
-               if (exp_has_rel(ve)) 
+               if (exp_has_rel(ve))
                        sq = exp_rel_get_rel(sql->sa, ve); /* get subquery */
                else
                        sq = rel_project(sql->sa, NULL, 
append(sa_list(sql->sa), ve));
@@ -1799,20 +1799,21 @@ rel_union_exps(mvc *sql, sql_exp **l, li
                                m->data = r;
                        }
                } else {
-                       r = sq->exps->t->data;
-                       if (rel_convert_types(sql, NULL, NULL, l, &r, 1, 
type_equal) < 0)
+                       sq->nrcols = list_length(sq->exps);
+                       if (rel_convert_types(sql, NULL, NULL, l, &ve, 1, 
type_equal) < 0)
                                return NULL;
-                       sq->exps->t->data = r;
-                       sq->nrcols = list_length(sq->exps);
+                       /* flatten expressions */
+                       if (exp_has_rel(ve))
+                               ve = exp_rel_update_exp(sql->sa, ve);
+                       sq = rel_project(sql->sa, sq, append(sa_list(sql->sa), 
ve));
                }
                if (!u) {
                        u = sq;
-                       exps = rel_projections(sql, sq, NULL, 1/*keep names */, 
1);
                } else {
                        u = rel_setop(sql->sa, u, sq, op_union);
                        rel_set_exps(u, exps);
-                       exps = rel_projections(sql, sq, NULL, 1/*keep names */, 
1);
                }
+               exps = rel_projections(sql, sq, NULL, 1/*keep names */, 1);
        }
        return u;
 }
@@ -1906,6 +1907,8 @@ rewrite_anyequal(mvc *sql, sql_rel *rel,
                        if (is_atom(re->type) && re->f) { /* exp_values */
                                /* flatten using unions */
                                rsq = rel_union_exps(sql, &le, re->f, is_tuple);
+                               if (!rsq)
+                                       return NULL;
                                re = rsq->exps->t->data;
 
                                if (!is_tuple && !is_freevar(re)) {
@@ -2094,6 +2097,8 @@ rewrite_compare(mvc *sql, sql_rel *rel, 
                        if (is_values(re)) { /* exp_values */
                                /* flatten using unions */
                                rsq = rel_union_exps(sql, &le, re->f, is_tuple);
+                               if (!rsq)
+                                       return NULL;
                                re = rsq->exps->t->data;
 
                                if (!is_tuple) {
diff --git 
a/sql/test/BugTracker-2009/Tests/assert_in_update.SF-2807336.stable.err 
b/sql/test/BugTracker-2009/Tests/assert_in_update.SF-2807336.stable.err
--- a/sql/test/BugTracker-2009/Tests/assert_in_update.SF-2807336.stable.err
+++ b/sql/test/BugTracker-2009/Tests/assert_in_update.SF-2807336.stable.err
@@ -65,7 +65,7 @@ stderr of test 'assert_in_update.SF-2807
 #warning: please don't forget to set your vault key!
 #(see /ufs/niels/scratch/rc/Linux-x86_64/etc/monetdb5.conf)
 
-# 15:04:33 >  
-# 15:04:33 >  "Done."
-# 15:04:33 >  
+# 13:17:20 >  
+# 13:17:20 >  "Done."
+# 13:17:20 >  
 
diff --git a/sql/test/mergetables/Tests/part-elim.stable.out 
b/sql/test/mergetables/Tests/part-elim.stable.out
--- a/sql/test/mergetables/Tests/part-elim.stable.out
+++ b/sql/test/mergetables/Tests/part-elim.stable.out
@@ -153,23 +153,23 @@ union (
 | project (
 | | select (
 | | | table(sys.mt1) [ "mt1"."id" as "test"."id", "mt1"."posx" as 
"test"."posx" ] COUNT 
-| | ) [ "test"."id" in (bigint "1", bigint "1022") ]
+| | ) [ "test"."id" in (bigint "1" as "%2"."%2", bigint "1022" as "%3"."%3") ]
 | ) [ "test"."id", "test"."posx" ],
 | project (
 | | select (
 | | | table(sys.mt2) [ "mt2"."id" as "test"."id", "mt2"."posx" as 
"test"."posx" ] COUNT 
-| | ) [ "test"."id" in (bigint "1", bigint "1022") ]
+| | ) [ "test"."id" in (bigint "1" as "%2"."%2", bigint "1022" as "%3"."%3") ]
 | ) [ "test"."id", "test"."posx" ]
 ) [ "test"."id", "test"."posx" ]
 #plan select * from test where id in (1, 1000);
 % .plan # table_name
 % rel # name
 % clob # type
-% 56 # length
+% 76 # length
 project (
 | select (
 | | table(sys.mt2) [ "test"."id", "test"."posx" ] COUNT 
-| ) [ "test"."id" in (bigint "1", bigint "1000") ]
+| ) [ "test"."id" in (bigint "1" as "%2"."%2", bigint "1000" as "%3"."%3") ]
 ) [ "test"."id", "test"."posx" ]
 #drop table test;
 #drop table mt1;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to