Changeset: 644fe1fee2ef for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/644fe1fee2ef
Added Files:
        sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.sql
        sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.err
        sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.out
Modified Files:
        sql/server/rel_unnest.c
        sql/test/BugTracker-2021/Tests/All
        sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.sql
        
sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.stable.out
        sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.sql
        sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.stable.out
Branch: Oct2020
Log Message:

Fix for bug #7127 While pushing up a set relation, merge set expressions with 
the projections of the dependent join's left side, not the left side itself. 
Also added inputs to further test correctness


diffs (234 lines):

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
@@ -1333,7 +1333,6 @@ push_up_set(mvc *sql, sql_rel *rel, list
 
                /* left of rel should be a set */
                if (d && is_distinct_set(sql, d, ad) && s && is_set(s->op)) {
-                       list *sexps;
                        sql_rel *sl = s->l, *sr = s->r, *n;
 
                        sl = rel_project(sql->sa, sl, rel_projections(sql, sl, 
NULL, 1, 1));
@@ -1350,12 +1349,11 @@ push_up_set(mvc *sql, sql_rel *rel, list
                        s->l = rel;
                        s->r = n;
                        if (is_join(rel->op)) {
-                               sexps = sa_list(sql->sa);
-                               for (node *m = d->exps->h; m; m = m->next) {
-                                       sql_exp *e = m->data, *pe;
-
-                                       pe = exp_ref(sql, e);
-                                       append(sexps, pe);
+                               list *sexps = sa_list(sql->sa), *dexps = 
rel_projections(sql, d, NULL, 1, 1);
+                               for (node *m = dexps->h; m; m = m->next) {
+                                       sql_exp *e = m->data;
+
+                                       list_append(sexps, exp_ref(sql, e));
                                }
                                s->exps = list_merge(sexps, s->exps, 
(fdup)NULL);
                        }
diff --git a/sql/test/BugTracker-2021/Tests/All 
b/sql/test/BugTracker-2021/Tests/All
--- a/sql/test/BugTracker-2021/Tests/All
+++ b/sql/test/BugTracker-2021/Tests/All
@@ -6,5 +6,6 @@ union-groupby.Bug-7108
 merge-stmt.wrong-error.Bug-7109
 remote-table-groupby.Bug-7110
 lowercase-cryllic.Bug-7126
+unnest-union.Bug-7127
 subquery-missing.Bug-7128
 batcalc-between-undefined.Bug-7129
diff --git 
a/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.sql 
b/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.sql
--- a/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.sql
+++ b/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.sql
@@ -1,10 +1,17 @@
 start transaction;
 
 create table t_qh ( c_f INTEGER , c_y2 INTEGER , primary key(c_f), unique(c_f) 
);
+insert into t_qh values (1,1), (2,2), (3,3);
 
 WITH cte_1 AS (select count( cast(87.53 as INTEGER)) as c0, avg( cast(abs( 
cast(50.40 as INTEGER)) as INTEGER)) as c1, subq_0.c0 as c2 from
 (select distinct ref_5.c_f as c0, 75 as c1, ref_5.c_f as c2 from t_qh as ref_5 
where ref_5.c_f is not NULL) as subq_0 group by subq_0.c0)
 select distinct cast(sum( cast((case when (ref_23.c0 > ref_23.c0) and 
(ref_23.c0 < ref_23.c1) then ref_23.c1 else ref_23.c1 end & ref_23.c1) as 
INTEGER)) as bigint)
 as c3, ref_23.c0 as c4 from cte_1 as ref_23 group by ref_23.c0;
 
+WITH cte_1 AS (select count( cast(87.53 as INTEGER)) as c0, avg( cast(abs( 
cast(50.40 as INTEGER)) as INTEGER)) as c1, subq_0.c0 as c2 from
+(select distinct ref_5.c_f as c0, 75 as c1, ref_5.c_f as c2 from t_qh as ref_5 
where ref_5.c_f is not NULL) as subq_0 group by subq_0.c0)
+select distinct cast(sum( cast((case when (ref_23.c0 > ref_23.c0) and 
(ref_23.c0 < ref_23.c1) then ref_23.c1 else ref_23.c1 end) as INTEGER)) as 
bigint)
+as c3, ref_23.c0 as c4 from cte_1 as ref_23 group by ref_23.c0;
+       -- 150 1
+
 rollback;
diff --git 
a/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.stable.out 
b/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.stable.out
--- 
a/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.stable.out
+++ 
b/sql/test/BugTracker-2021/Tests/batcalc-between-undefined.Bug-7129.stable.out
@@ -25,6 +25,8 @@ stdout of test 'batcalc-between-undefine
 
 #start transaction;
 #create table t_qh ( c_f INTEGER , c_y2 INTEGER , primary key(c_f), 
unique(c_f) );
+#insert into t_qh values (1,1), (2,2), (3,3);
+[ 3    ]
 #WITH cte_1 AS (select count( cast(87.53 as INTEGER)) as c0, avg( cast(abs( 
cast(50.40 as INTEGER)) as INTEGER)) as c1, subq_0.c0 as c2 from
 #(select distinct ref_5.c_f as c0, 75 as c1, ref_5.c_f as c2 from t_qh as 
ref_5 where ref_5.c_f is not NULL) as subq_0 group by subq_0.c0)
 #select distinct cast(sum( cast((case when (ref_23.c0 > ref_23.c0) and 
(ref_23.c0 < ref_23.c1) then ref_23.c1 else ref_23.c1 end & ref_23.c1) as 
INTEGER)) as bigint)
@@ -32,7 +34,17 @@ stdout of test 'batcalc-between-undefine
 % .,   . # table_name
 % c3,  c4 # name
 % bigint,      bigint # type
-% 1,   1 # length
+% 3,   1 # length
+[ 150, 1       ]
+#WITH cte_1 AS (select count( cast(87.53 as INTEGER)) as c0, avg( cast(abs( 
cast(50.40 as INTEGER)) as INTEGER)) as c1, subq_0.c0 as c2 from
+#(select distinct ref_5.c_f as c0, 75 as c1, ref_5.c_f as c2 from t_qh as 
ref_5 where ref_5.c_f is not NULL) as subq_0 group by subq_0.c0)
+#select distinct cast(sum( cast((case when (ref_23.c0 > ref_23.c0) and 
(ref_23.c0 < ref_23.c1) then ref_23.c1 else ref_23.c1 end) as INTEGER)) as 
bigint)
+#as c3, ref_23.c0 as c4 from cte_1 as ref_23 group by ref_23.c0;
+% .,   . # table_name
+% c3,  c4 # name
+% bigint,      bigint # type
+% 3,   1 # length
+[ 150, 1       ]
 #rollback;
 
 # 17:25:34 >  
diff --git a/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.sql 
b/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.sql
--- a/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.sql
+++ b/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.sql
@@ -1,9 +1,11 @@
 start transaction;
 
 create table t_qh ( c_f INTEGER , c_y2 INTEGER , c_i768 INTEGER , c_tqx TEXT , 
primary key(c_f, c_y2), unique(c_y2) );
+insert into t_qh values (1,1,1,'a'), (2,2,2,'b'), (3,3,3,'c');
 
 select ref_1.c_i768 as c0 from t_qh as ref_1 cross join (select ref_2.c_i768 
as c0 from t_qh as ref_2 inner join t_qh as
 ref_3 on (1=1) where ref_3.c_f <> ref_3.c_y2) as subq_0 where ref_1.c_y2 < ( 
select ref_1.c_f as c0 from t_qh as ref_4
 where (EXISTS ( select distinct ref_5.c_i768 as c0 from t_qh as ref_5)) and 
(ref_1.c_i768 between ref_4.c_y2 and ref_1.c_y2));
+       -- empty
 
 rollback;
diff --git 
a/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.stable.out 
b/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.stable.out
--- a/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.stable.out
+++ b/sql/test/BugTracker-2021/Tests/subquery-missing.Bug-7128.stable.out
@@ -24,6 +24,8 @@ stdout of test 'subquery-missing.Bug-712
 
 #start transaction;
 #create table t_qh ( c_f INTEGER , c_y2 INTEGER , c_i768 INTEGER , c_tqx TEXT 
, primary key(c_f, c_y2), unique(c_y2) );
+#insert into t_qh values (1,1,1,'a'), (2,2,2,'b'), (3,3,3,'c');
+[ 3    ]
 #select ref_1.c_i768 as c0 from t_qh as ref_1 cross join (select ref_2.c_i768 
as c0 from t_qh as ref_2 inner join t_qh as
 #ref_3 on (1=1) where ref_3.c_f <> ref_3.c_y2) as subq_0 where ref_1.c_y2 < ( 
select ref_1.c_f as c0 from t_qh as ref_4
 #where (EXISTS ( select distinct ref_5.c_i768 as c0 from t_qh as ref_5)) and 
(ref_1.c_i768 between ref_4.c_y2 and ref_1.c_y2));
diff --git a/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.sql 
b/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.sql
@@ -0,0 +1,17 @@
+start transaction;
+
+create table t_qh ( c_f INTEGER , c_y2 INTEGER , c_i768 INTEGER , c_tqx TEXT , 
c_mknkhml TEXT , primary key(c_f, c_y2), unique(c_y2) );
+insert into t_qh values (1,1,1,'a','a'), (2,2,2,'b','b'), (3,3,3,'c','c');
+
+create table t_ckfystsc ( c_kvhq5p INTEGER , c_aifpl INTEGER , c_jf6 TEXT , 
c_f31ix TEXT NOT NULL, c_lk0zqfa INTEGER , c_qotzuxn INTEGER , c_w_z TEXT , 
primary key(c_lk0zqfa), unique(c_kvhq5p) );
+insert into t_ckfystsc values (1,1,'a','a',1,1,'a'), (2,2,'b','b',2,2,'b'), 
(3,3,'c','c',3,3,'c');
+
+create table t_irwrntam7 as select ref_0.c_i768 as c0, ref_0.c_i768 as c1, 
ref_0.c_f as c2, ref_0.c_i768 as c3 from t_qh as ref_0 where 
+(ref_0.c_f in ( select ref_1.c_lk0zqfa as c0 from t_ckfystsc as ref_1)) and 
(ref_0.c_y2 >= ( select ref_0.c_y2 as c0 from t_qh as ref_7 union select 
ref_0.c_f as c0 from t_qh as ref_9));
+
+select ref_0.c_i768 as c0, ref_0.c_i768 as c1, ref_0.c_f as c2, ref_0.c_i768 
as c3 from t_qh as ref_0 where 
+(ref_0.c_f in ( select ref_1.c_lk0zqfa as c0 from t_ckfystsc as ref_1)) and 
(ref_0.c_y2 >= ( select ref_0.c_y2 as c0 from t_qh as ref_7 union select 
ref_0.c_f as c0 from t_qh as ref_9));
+
+select 1 from t_qh where c_f in (select 2 from t_ckfystsc) and c_y2 = (select 
c_y2 union select c_f);
+
+rollback;
diff --git a/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.err 
b/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.err
@@ -0,0 +1,29 @@
+stderr of test 'unnest-union.Bug-7127` in directory 'sql/test/BugTracker-2021` 
itself:
+
+
+# 14:49:37 >  
+# 14:49:37 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_listenaddr=all" "--set" "mapi_port=36196" "--set" 
"mapi_usock=/var/tmp/mtest-239088/.s.monetdb.36196" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021"
 "--set" "embedded_r=yes" "--set" "embedded_c=true"
+# 14:49:37 >  
+
+# builtin opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/monetdb5/dbfarm/demo
+# builtin opt  mapi_port = 50000
+# builtin opt  sql_optimizer = default_pipe
+# builtin opt  sql_debug = 0
+# builtin opt  raw_strings = false
+# cmdline opt  gdk_nr_threads = 0
+# cmdline opt  mapi_listenaddr = all
+# cmdline opt  mapi_port = 36196
+# cmdline opt  mapi_usock = /var/tmp/mtest-239088/.s.monetdb.36196
+# cmdline opt  gdk_dbpath = 
/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021
+# cmdline opt  embedded_r = yes
+# cmdline opt  embedded_c = true
+
+# 14:49:37 >  
+# 14:49:37 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-239088" "--port=36196"
+# 14:49:37 >  
+
+
+# 14:49:38 >  
+# 14:49:38 >  "Done."
+# 14:49:38 >  
+
diff --git a/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.out 
b/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.out
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2021/Tests/unnest-union.Bug-7127.stable.out
@@ -0,0 +1,55 @@
+stdout of test 'unnest-union.Bug-7127` in directory 'sql/test/BugTracker-2021` 
itself:
+
+
+# 14:49:37 >  
+# 14:49:37 >  "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" 
"mapi_listenaddr=all" "--set" "mapi_port=36196" "--set" 
"mapi_usock=/var/tmp/mtest-239088/.s.monetdb.36196" "--forcemito" 
"--dbpath=/home/ferreira/repositories/MonetDB-Oct2020/BUILD/var/MonetDB/mTests_sql_test_BugTracker-2021"
 "--set" "embedded_r=yes" "--set" "embedded_c=true"
+# 14:49:37 >  
+
+# MonetDB 5 server v11.39.18 (hg id: af88b10dddb7)
+# This is an unreleased version
+# Serving database 'mTests_sql_test_BugTracker-2021', using 8 threads
+# Compiled for x86_64-pc-linux-gnu/64bit with 128bit integers
+# Found 15.343 GiB available main-memory of which we use 12.504 GiB
+# Copyright (c) 1993 - July 2008 CWI.
+# Copyright (c) August 2008 - 2021 MonetDB B.V., all rights reserved
+# Visit https://www.monetdb.org/ for further information
+# Listening for connection requests on mapi:monetdb://fedora:36196/
+# Listening for UNIX domain connection requests on 
mapi:monetdb:///var/tmp/mtest-239088/.s.monetdb.36196
+# MonetDB/GIS module loaded
+# MonetDB/R   module loaded
+# MonetDB/SQL module loaded
+
+# 14:49:37 >  
+# 14:49:37 >  "mclient" "-lsql" "-ftest" "-tnone" "-Eutf-8" "-i" "-e" 
"--host=/var/tmp/mtest-239088" "--port=36196"
+# 14:49:37 >  
+
+#start transaction;
+#create table t_qh ( c_f INTEGER , c_y2 INTEGER , c_i768 INTEGER , c_tqx TEXT 
, c_mknkhml TEXT , primary key(c_f, c_y2), unique(c_y2) );
+#insert into t_qh values (1,1,1,'a','a'), (2,2,2,'b','b'), (3,3,3,'c','c');
+[ 3    ]
+#create table t_ckfystsc ( c_kvhq5p INTEGER , c_aifpl INTEGER , c_jf6 TEXT , 
c_f31ix TEXT NOT NULL, c_lk0zqfa INTEGER , c_qotzuxn INTEGER , c_w_z TEXT , 
primary key(c_lk0zqfa), unique(c_kvhq5p) );
+#insert into t_ckfystsc values (1,1,'a','a',1,1,'a'), (2,2,'b','b',2,2,'b'), 
(3,3,'c','c',3,3,'c');
+[ 3    ]
+#create table t_irwrntam7 as select ref_0.c_i768 as c0, ref_0.c_i768 as c1, 
ref_0.c_f as c2, ref_0.c_i768 as c3 from t_qh as ref_0 where 
+#(ref_0.c_f in ( select ref_1.c_lk0zqfa as c0 from t_ckfystsc as ref_1)) and 
(ref_0.c_y2 >= ( select ref_0.c_y2 as c0 from t_qh as ref_7 union select 
ref_0.c_f as c0 from t_qh as ref_9));
+#select ref_0.c_i768 as c0, ref_0.c_i768 as c1, ref_0.c_f as c2, ref_0.c_i768 
as c3 from t_qh as ref_0 where 
+#(ref_0.c_f in ( select ref_1.c_lk0zqfa as c0 from t_ckfystsc as ref_1)) and 
(ref_0.c_y2 >= ( select ref_0.c_y2 as c0 from t_qh as ref_7 union select 
ref_0.c_f as c0 from t_qh as ref_9));
+% .,   .,      .,      . # table_name
+% c0,  c1,     c2,     c3 # name
+% int, int,    int,    int # type
+% 1,   1,      1,      1 # length
+[ 1,   1,      1,      1       ]
+[ 2,   2,      2,      2       ]
+[ 3,   3,      3,      3       ]
+#select 1 from t_qh where c_f in (select 2 from t_ckfystsc) and c_y2 = (select 
c_y2 union select c_f);
+% .%14 # table_name
+% %14 # name
+% tinyint # type
+% 1 # length
+[ 1    ]
+#rollback;
+
+# 14:49:38 >  
+# 14:49:38 >  "Done."
+# 14:49:38 >  
+
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to