Changeset: 4aa429bd5eee for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=4aa429bd5eee
Modified Files:
        sql/server/rel_rel.h
        sql/server/rel_select.c
        sql/server/rel_updates.c
        sql/test/SQLancer/Tests/sqlancer07.sql
        sql/test/SQLancer/Tests/sqlancer07.stable.err
        sql/test/SQLancer/Tests/sqlancer07.stable.out
Branch: Oct2020
Log Message:

Look for joins while using set operations under subqueries under the where 
clause


diffs (109 lines):

diff --git a/sql/server/rel_rel.h b/sql/server/rel_rel.h
--- a/sql/server/rel_rel.h
+++ b/sql/server/rel_rel.h
@@ -29,8 +29,7 @@
 #define sql_psm          (1 << 13) //ORed
 #define sql_values       (1 << 14) //ORed
 #define psm_call         (1 << 15) //ORed
-#define sql_merge        (1 << 16) //ORed
-#define sql_or           (1 << 17) //ORed
+#define sql_or           (1 << 16) //ORed
 
 #define is_sql_from(X)         ((X & sql_from) == sql_from)
 #define is_sql_where(X)        ((X & sql_where) == sql_where)
@@ -48,7 +47,6 @@
 #define is_sql_psm(X)          ((X & sql_psm) == sql_psm)
 #define is_sql_values(X)       ((X & sql_values) == sql_values)
 #define is_psm_call(X)         ((X & psm_call) == psm_call)
-#define is_sql_merge(X)        ((X & sql_merge) == sql_merge)
 #define is_sql_or(X)           ((X & sql_or) == sql_or)
 
 #define is_updateble(rel) \
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
@@ -2353,7 +2353,7 @@ rel_logical_value_exp(sql_query *query, 
                        return NULL;
                if (ek.card <= card_set && is_project(sq->op) && 
list_length(sq->exps) > 1)
                        return sql_error(sql, 02, SQLSTATE(42000) "SELECT: 
subquery must return only one column");
-               if (ek.card < card_set && sq->card >= CARD_MULTI && 
(is_sql_sel(f) | is_sql_having(f) | ( is_sql_where(f) && rel && (!*rel || 
is_basetable((*rel)->op) || is_simple_project((*rel)->op) || is_sql_merge(f)))))
+               if (ek.card < card_set && sq->card >= CARD_MULTI && 
(is_sql_sel(f) | is_sql_having(f) | ( is_sql_where(f) && rel && (!*rel || 
is_basetable((*rel)->op) || is_simple_project((*rel)->op) || 
is_joinop((*rel)->op)))))
                        sq = rel_zero_or_one(sql, sq, ek);
                return exp_rel(sql, sq);
        }
diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -1291,7 +1291,7 @@ merge_into_table(sql_query *query, dlist
                                        join_rel = rel_dup(join_rel);
                                } else {
                                        join_rel = rel_crossproduct(sql->sa, 
joined, bt, op_left);
-                                       if (!(join_rel = rel_logical_exp(query, 
join_rel, search_cond, sql_where | sql_join | sql_merge)))
+                                       if (!(join_rel = rel_logical_exp(query, 
join_rel, search_cond, sql_where | sql_join)))
                                                return NULL;
                                        set_processed(join_rel);
                                }
@@ -1328,7 +1328,7 @@ merge_into_table(sql_query *query, dlist
                                        join_rel = rel_dup(join_rel);
                                } else {
                                        join_rel = rel_crossproduct(sql->sa, 
joined, bt, op_left);
-                                       if (!(join_rel = rel_logical_exp(query, 
join_rel, search_cond, sql_where | sql_join | sql_merge)))
+                                       if (!(join_rel = rel_logical_exp(query, 
join_rel, search_cond, sql_where | sql_join)))
                                                return NULL;
                                        set_processed(join_rel);
                                }
@@ -1369,7 +1369,7 @@ merge_into_table(sql_query *query, dlist
                                join_rel = rel_dup(join_rel);
                        } else {
                                join_rel = rel_crossproduct(sql->sa, joined, 
bt, op_left);
-                               if (!(join_rel = rel_logical_exp(query, 
join_rel, search_cond, sql_where | sql_join | sql_merge)))
+                               if (!(join_rel = rel_logical_exp(query, 
join_rel, search_cond, sql_where | sql_join)))
                                        return NULL;
                                set_processed(join_rel);
                        }
diff --git a/sql/test/SQLancer/Tests/sqlancer07.sql 
b/sql/test/SQLancer/Tests/sqlancer07.sql
--- a/sql/test/SQLancer/Tests/sqlancer07.sql
+++ b/sql/test/SQLancer/Tests/sqlancer07.sql
@@ -109,6 +109,8 @@ INSERT INTO "t2" VALUES 
('4'),('4'),('3eSU8,'),(''),('5E~쟱'),('~'),('1386006226'),('0.19005213960704492'),('''{Mdd뒆VB'''),('\015␱%L%]'),('+'),(''),('㕚o+k');
 
 select t0.c1 from t0 where (5) in (case when t0.c1 = 'a' then 1 end, (select 
3));
        -- empty
+select t0.c1 from t0 where (5) in ((select 3), case when t0.c1 = 'a' then 1 
end);
+       -- empty
 select t0.c1 from t0 where (5) in (case when t0.c1 = 'a' then 1 end, (select 3 
from t0));
        -- empty
 select t0.c1 from t0 where (-5) in (case when t0.c1 = 'a' then 1 else -2 end, 
(select -3 from t0, t2 where false));
diff --git a/sql/test/SQLancer/Tests/sqlancer07.stable.err 
b/sql/test/SQLancer/Tests/sqlancer07.stable.err
--- a/sql/test/SQLancer/Tests/sqlancer07.stable.err
+++ b/sql/test/SQLancer/Tests/sqlancer07.stable.err
@@ -27,6 +27,15 @@ MAPI  = (monetdb) /var/tmp/mtest-57059/.
 QUERY = INSERT INTO t1(c0) VALUES(((((COALESCE(0.6548429615298178, 
0.20317629894456002))*(COALESCE(0.3050008736497528, 
0.2277902039419617))))/(0.5061323979270875))); --error, scale too large
 ERROR = !Scale (49) overflows type
 CODE  = 42000
+MAPI  = (monetdb) /var/tmp/mtest-23025/.s.monetdb.36001
+QUERY = SELECT 1 FROM t2, t0 WHERE (SELECT 1 UNION SELECT 2) > 0;
+ERROR = !GDK reported error: BATsubcross: more than one match
+MAPI  = (monetdb) /var/tmp/mtest-23025/.s.monetdb.36001
+QUERY = SELECT 1 FROM t2, t0, t1 WHERE (SELECT 1 UNION SELECT 2) > 0;
+ERROR = !GDK reported error: BATsubcross: more than one match
+MAPI  = (monetdb) /var/tmp/mtest-23025/.s.monetdb.36001
+QUERY = SELECT 1 FROM t2, t0 CROSS JOIN t1 WHERE (SELECT 1 UNION SELECT 2) > 0;
+ERROR = !GDK reported error: BATsubcross: more than one match
 
 # 10:16:14 >  
 # 10:16:14 >  "Done."
diff --git a/sql/test/SQLancer/Tests/sqlancer07.stable.out 
b/sql/test/SQLancer/Tests/sqlancer07.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer07.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer07.stable.out
@@ -156,6 +156,11 @@ stdout of test 'sqlancer07` in directory
 % c1 # name
 % varchar # type
 % 0 # length
+#select t0.c1 from t0 where (5) in ((select 3), case when t0.c1 = 'a' then 1 
end);
+% .t0 # table_name
+% c1 # name
+% varchar # type
+% 0 # length
 #select t0.c1 from t0 where (5) in (case when t0.c1 = 'a' then 1 end, (select 
3 from t0));
 % .t0 # table_name
 % c1 # name
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to