Changeset: 8d51fe9ef825 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8d51fe9ef825
Modified Files:
        sql/server/rel_optimizer.c
        sql/test/mergetables/Tests/sqlsmith-exists2.sql
        sql/test/mergetables/Tests/sqlsmith-exists2.stable.out
        sql/test/miscellaneous/Tests/groupby_error.sql
        sql/test/miscellaneous/Tests/groupby_error.stable.out
Branch: Jun2020
Log Message:

Small bugfix from sqlsmith. At rel_distinct_project2groupby test if the 
projected column is already on the grouping list, so it won't group twice on it


diffs (111 lines):

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
@@ -2576,9 +2576,8 @@ rel_distinct_project2groupby(mvc *sql, s
                        if (!exp_name(e))
                                exp_label(sql->sa, e, ++sql->label);
                        ne = exp_ref(sql->sa, e);
-                       if (e->card > CARD_ATOM) { /* no need to group by on 
constants */
+                       if (e->card > CARD_ATOM && !list_find_exp(gbe, ne)) /* 
no need to group by on constants, or the same column multiple times */
                                append(gbe, ne);
-                       }
                        append(exps, ne);
                }
                rel->op = op_groupby;
diff --git a/sql/test/mergetables/Tests/sqlsmith-exists2.sql 
b/sql/test/mergetables/Tests/sqlsmith-exists2.sql
--- a/sql/test/mergetables/Tests/sqlsmith-exists2.sql
+++ b/sql/test/mergetables/Tests/sqlsmith-exists2.sql
@@ -214,4 +214,20 @@ select
  on (ref_1.bb is null);
  -- empty result set
 
+select
+  subq_0.c2 as c0, 
+  subq_0.c2 as c1, 
+  subq_0.c3 as c2, 
+  subq_0.c1 as c3 from 
+  (select distinct 
+      ref_0.col1 as c0, 
+      ref_0.col1 as c1, 
+      ref_0.col0 as c2, 
+      ref_0.col2 as c3
+      from 
+        tab1 as ref_0
+      where ref_0.col1 is null
+      limit 140) as subq_0 where false limit 61;
+ -- empty result set
+
 ROLLBACK;
diff --git a/sql/test/mergetables/Tests/sqlsmith-exists2.stable.out 
b/sql/test/mergetables/Tests/sqlsmith-exists2.stable.out
--- a/sql/test/mergetables/Tests/sqlsmith-exists2.stable.out
+++ b/sql/test/mergetables/Tests/sqlsmith-exists2.stable.out
@@ -163,6 +163,24 @@ stdout of test 'sqlsmith-exists2` in dir
 % single_value # name
 % tinyint # type
 % 1 # length
+#select
+#  subq_0.c2 as c0, 
+#  subq_0.c2 as c1, 
+#  subq_0.c3 as c2, 
+#  subq_0.c1 as c3 from 
+#  (select distinct 
+#      ref_0.col1 as c0, 
+#      ref_0.col1 as c1, 
+#      ref_0.col0 as c2, 
+#      ref_0.col2 as c3
+#      from 
+#        tab1 as ref_0
+#      where ref_0.col1 is null
+#      limit 140) as subq_0 where false limit 61;
+% sys.,        sys.,   sys.,   sys. # table_name
+% c0,  c1,     c2,     c3 # name
+% int, int,    int,    int # type
+% 1,   1,      1,      1 # length
 #ROLLBACK;
 
 # 22:12:15 >  
diff --git a/sql/test/miscellaneous/Tests/groupby_error.sql 
b/sql/test/miscellaneous/Tests/groupby_error.sql
--- a/sql/test/miscellaneous/Tests/groupby_error.sql
+++ b/sql/test/miscellaneous/Tests/groupby_error.sql
@@ -30,6 +30,13 @@ SELECT col0 FROM tab2 WHERE - - col2;
        -- 75
        -- 46
 
+PLAN SELECT DISTINCT col0, col1, col2, col0 FROM tab0;
+
+SELECT DISTINCT col0, col1, col2, col0 FROM tab0;
+       -- 97  1 99 97
+       -- 15 81 47 15
+       -- 87 21 10 87
+
 PLAN SELECT col0 FROM tab2 WHERE CAST(col2 AS BIGINT) = 40;
 
 SELECT col0 FROM tab2 WHERE CAST(col2 AS BIGINT) = 40;
diff --git a/sql/test/miscellaneous/Tests/groupby_error.stable.out 
b/sql/test/miscellaneous/Tests/groupby_error.stable.out
--- a/sql/test/miscellaneous/Tests/groupby_error.stable.out
+++ b/sql/test/miscellaneous/Tests/groupby_error.stable.out
@@ -126,6 +126,24 @@ stdout of test 'groupby_error` in direct
 [ 64   ]
 [ 75   ]
 [ 46   ]
+#PLAN SELECT DISTINCT col0, col1, col2, col0 FROM tab0;
+% .plan # table_name
+% rel # name
+% clob # type
+% 112 # length
+group by (
+| project (
+| | table(sys.tab0) [ "tab0"."col0", "tab0"."col1", "tab0"."col2" ] COUNT 
+| ) [ "tab0"."col0", "tab0"."col1", "tab0"."col2" ]
+) [ "tab0"."col0", "tab0"."col1", "tab0"."col2" ] [ "tab0"."col0", 
"tab0"."col1", "tab0"."col2", "tab0"."col0" ]
+#SELECT DISTINCT col0, col1, col2, col0 FROM tab0;
+% sys.tab0,    sys.tab0,       sys.tab0,       sys.tab0 # table_name
+% col0,        col1,   col2,   col0 # name
+% int, int,    int,    int # type
+% 2,   2,      2,      2 # length
+[ 97,  1,      99,     97      ]
+[ 15,  81,     47,     15      ]
+[ 87,  21,     10,     87      ]
 #PLAN SELECT col0 FROM tab2 WHERE CAST(col2 AS BIGINT) = 40;
 % .plan # table_name
 % rel # name
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to