Changeset: 9d259f704d50 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9d259f704d50
Modified Files:
        sql/server/rel_unnest.c
        sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
        sql/test/SQLancer/Tests/sqlancer17.test
        sql/test/miscellaneous/Tests/decimal-atoms.test
        sql/test/miscellaneous/Tests/simple_selects.test
        sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.test
        sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
Branch: unnest2
Log Message:

rewrite
project(
        [ true ]
) [ values ]

into

 [ values ]


diffs (290 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
@@ -1166,7 +1166,7 @@ rewrite_exp_rel(visitor *v, sql_rel *rel
        return e;
 }
 
-/* add an dummy true projection column */
+/* add an dummy true projection column and simplify project[project[true]] */
 static inline sql_rel *
 rewrite_empty_project(visitor *v, sql_rel *rel)
 {
@@ -1177,6 +1177,17 @@ rewrite_empty_project(visitor *v, sql_re
                list_append(rel->exps, e);
                v->changes++;
        }
+       sql_rel *l = rel->l;
+       if (l && !l->l && is_simple_project(rel->op) && 
is_simple_project(l->op) && list_length(l->exps) == 1) {
+               list *exps = l->exps;
+               sql_exp *e = exps->h->data;
+               if (!e->f && exp_is_atom(e) && exp_is_true(e) && 
!exps_uses_exp(rel->exps, e) && !exps_have_rel_exp(rel->exps) && 
exps_are_atoms(rel->exps) && !exps_have_rank(rel->exps)) {
+                       //printf("cleanup \n");
+                       rel_destroy(v->sql, l);
+                       rel->l = NULL;
+                       v->changes++;
+               }
+       }
        if (is_left(rel->op) && rel->attr) { /* group join */
                sql_rel *r = rel->r;
                if (!rel_is_ref(r) && is_simple_project(r->op) && r->l) {
diff --git a/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test 
b/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
--- a/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
+++ b/sql/test/BugTracker-2011/Tests/crash_on_alias.Bug-2798.test
@@ -16,9 +16,7 @@ project (
 | | group by (
 | | | table("sys"."dbg") [ "dbg"."a" NOT NULL UNIQUE, "dbg"."b" NOT NULL 
UNIQUE ]
 | | ) [ "dbg"."a" NOT NULL UNIQUE as "d" ] [ "d" NOT NULL UNIQUE, "sys"."min" 
no nil ("dbg"."b" NOT NULL UNIQUE) NOT NULL as "%1"."%1" ],
-| | project (
-| | |  [ boolean(1) "true" as "%2"."%2" ]
-| | ) [ tinyint(2) "2" as "%3"."%3" ]
+| |  [ tinyint(2) "2" as "%3"."%3" ]
 | ) [  ]
 ) [ "d" NOT NULL, "%1"."%1" NOT NULL, "sys"."sql_mul"(tinyint(2) "2", 
"sys"."sql_div"("%1"."%1" NOT NULL, "%3"."%3")) as "f" ]
 
@@ -56,9 +54,7 @@ project (
 | | group by (
 | | | table("sys"."dbg") [ "dbg"."a" NOT NULL UNIQUE, "dbg"."b" NOT NULL 
UNIQUE ]
 | | ) [ "dbg"."a" NOT NULL UNIQUE as "d" ] [ "d" NOT NULL UNIQUE, "sys"."min" 
no nil ("dbg"."b" NOT NULL UNIQUE) NOT NULL as "%1"."%1" ],
-| | project (
-| | |  [ boolean(1) "true" as "%2"."%2" ]
-| | ) [ tinyint(2) "2" as "%3"."%3" ]
+| |  [ tinyint(2) "2" as "%3"."%3" ]
 | ) [  ]
 ) [ "d" NOT NULL, "%1"."%1" NOT NULL as "e", "sys"."sql_mul"(tinyint(2) "2", 
"sys"."sql_div"("%1"."%1" NOT NULL, "%3"."%3")) as "f" ]
 
diff --git a/sql/test/SQLancer/Tests/sqlancer17.test 
b/sql/test/SQLancer/Tests/sqlancer17.test
--- a/sql/test/SQLancer/Tests/sqlancer17.test
+++ b/sql/test/SQLancer/Tests/sqlancer17.test
@@ -637,10 +637,12 @@ least(3, sub0.c1) FROM vx JOIN (SELECT 4
 project (
 | crossproduct (
 | | table("sys"."rt0") [ "rt0"."%TID%" NOT NULL UNIQUE ],
-| | crossproduct (
-| | |  [ boolean(1) "true" as "%1"."%1" ],
-| | |  [ boolean(1) "true" as "%3"."%3" ]
-| | ) [  ]
+| | project (
+| | | crossproduct (
+| | | |  [ varchar(1) "a" as "%2"."%2" ],
+| | | |  [ tinyint(2) "2" as "%4"."%4" ]
+| | | ) [  ]
+| | ) [ "sys"."casewhen"("%4"."%4" NOT NULL, tinyint(3) "4", varchar(1) "c", 
varchar(1) NULL) as "sub0"."c0" ]
 | ) [  ]
 ) [ tinyint(1) "1" ]
 
diff --git a/sql/test/miscellaneous/Tests/decimal-atoms.test 
b/sql/test/miscellaneous/Tests/decimal-atoms.test
--- a/sql/test/miscellaneous/Tests/decimal-atoms.test
+++ b/sql/test/miscellaneous/Tests/decimal-atoms.test
@@ -1,35 +1,25 @@
 query T nosort
 explain show details select 0.001
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ decimal(4,3) "1" ]
+ [ decimal(4,3) "1" ]
 
 query T nosort
 explain show details select .001
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ decimal(3,3) "1" ]
+ [ decimal(3,3) "1" ]
 
 query T nosort
 explain show details select 100.00
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ decimal(5,2) "10000" ]
+ [ decimal(5,2) "10000" ]
 
 query T nosort
 explain show details select 100.0
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ decimal(4,1) "1000" ]
+ [ decimal(4,1) "1000" ]
 
 query T nosort
 explain show details select 100.
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ tinyint(7) "100" ]
+ [ tinyint(7) "100" ]
 
diff --git a/sql/test/miscellaneous/Tests/simple_selects.test 
b/sql/test/miscellaneous/Tests/simple_selects.test
--- a/sql/test/miscellaneous/Tests/simple_selects.test
+++ b/sql/test/miscellaneous/Tests/simple_selects.test
@@ -231,7 +231,7 @@ NULL
 NULL
 NULL
 
-query RRIIIII rowsort
+query RDIIIII rowsort
 select avg(10), avg(NULL),
        patindex('o', 'foo'), patindex(NULL, 'foo'), patindex('o', NULL), 
patindex('o', NULL), patindex(NULL, NULL)
 ----
@@ -678,9 +678,7 @@ explain show details select x as z, 2 fr
 ----
 project (
 | group by (
-| | project (
-| | |  [ boolean(1) "true" as "%1"."%1" ]
-| | ) [ tinyint(1) "1" as "x"."x" ]
+| |  [ tinyint(1) "1" as "x"."x" ]
 | ) [ "x"."x" NOT NULL as "z" ] [ "z" NOT NULL UNIQUE ]
 ) [ "z" NOT NULL UNIQUE, tinyint(2) "2" ]
 
@@ -690,11 +688,11 @@ select x as z, y as z from (select 1, 2)
 statement error
 select x as z, y as z from (select 1, 2) as x(x,y) order by z
 
-query II rowsort
+query IT rowsort
 select 1, null except select 1, null
 ----
 
-query II rowsort
+query IT rowsort
 select 1, null intersect select 1, null
 ----
 1
diff --git 
a/sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.test 
b/sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.test
--- a/sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.test
+++ b/sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.test
@@ -848,44 +848,32 @@ NULL
 query T nosort
 explain show details select nullif(null, null)
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."nullif"(smallint(15) NULL, smallint(15) NULL) ]
+ [ "sys"."nullif"(smallint(15) NULL, smallint(15) NULL) ]
 
 query T nosort
 explain show details select CASE WHEN null = null THEN NULL ELSE null END
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."case"(boolean(1) NULL, smallint(15) NULL, smallint(15) NULL) ]
+ [ "sys"."case"(boolean(1) NULL, smallint(15) NULL, smallint(15) NULL) ]
 
 query T nosort
 explain show details select nullif('ac', 'ac')
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."nullif"(varchar(2) "ac", varchar(2) "ac") ]
+ [ "sys"."nullif"(varchar(2) "ac", varchar(2) "ac") ]
 
 query T nosort
 explain show details select CASE WHEN 'ac' = 'ac' THEN NULL ELSE 'ac' END
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."case"((varchar(2) "ac") = (varchar(2) "ac"), varchar NULL, varchar 
"ac") ]
+ [ "sys"."case"((varchar(2) "ac") = (varchar(2) "ac"), varchar NULL, varchar 
"ac") ]
 
 query T nosort
 explain show details select nullif(9, 9)
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."nullif"(tinyint(4) "9", tinyint(4) "9") ]
+ [ "sys"."nullif"(tinyint(4) "9", tinyint(4) "9") ]
 
 query T nosort
 explain show details select CASE WHEN 9 = 9 THEN NULL ELSE 9 END
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."case"((tinyint(4) "9") = (tinyint(4) "9"), tinyint(7) NULL, 
tinyint(7) "9") ]
+ [ "sys"."case"((tinyint(4) "9") = (tinyint(4) "9"), tinyint(7) NULL, 
tinyint(7) "9") ]
 
 query I rowsort
 select 'db' between 'abc' and 'db' as tru
diff --git 
a/sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test 
b/sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
--- a/sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
+++ b/sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
@@ -16,9 +16,7 @@ select 2 ^ 3
 query T nosort
 explain show details select 2 ^ 3
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."bit_xor"(tinyint(2) "2", tinyint(2) "3") NOT NULL ]
+ [ "sys"."bit_xor"(tinyint(2) "2", tinyint(2) "3") NOT NULL ]
 
 query I nosort
 select 2 ^ 3
@@ -63,9 +61,7 @@ select 17 ^ 5
 query T nosort
 explain show details select 17 ^ 5
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."bit_xor"(tinyint(5) "17", tinyint(3) "5") NOT NULL ]
+ [ "sys"."bit_xor"(tinyint(5) "17", tinyint(3) "5") NOT NULL ]
 
 query I nosort
 select 2 ^ 3
@@ -75,9 +71,7 @@ select 2 ^ 3
 query T nosort
 explain show details select 2 ^ 3
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."bit_xor"(tinyint(2) "2", tinyint(2) "3") NOT NULL ]
+ [ "sys"."bit_xor"(tinyint(2) "2", tinyint(2) "3") NOT NULL ]
 
 query I nosort
 select ~1
@@ -87,9 +81,7 @@ select ~1
 query T nosort
 explain show details select ~1
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."bit_not"(tinyint(1) "1") NOT NULL ]
+ [ "sys"."bit_not"(tinyint(1) "1") NOT NULL ]
 
 query I nosort
 select 1 << 4
@@ -99,9 +91,7 @@ select 1 << 4
 query T nosort
 explain show details select 1 << 4
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."left_shift"(tinyint(1) "1", int(3) "4") NOT NULL ]
+ [ "sys"."left_shift"(tinyint(1) "1", int(3) "4") NOT NULL ]
 
 query I nosort
 select left_shift(1, 4)
@@ -116,9 +106,7 @@ select 8 >> 2
 query T nosort
 explain show details select 8 >> 2
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."right_shift"(tinyint(4) "8", int(2) "2") NOT NULL ]
+ [ "sys"."right_shift"(tinyint(4) "8", int(2) "2") NOT NULL ]
 
 query I nosort
 select right_shift(16, 2)
@@ -308,9 +296,7 @@ select 2144156907 / 2147483648
 query T nosort
 explain show details select CAST(RAND() as float) / 2147483648
 ----
-project (
-|  [ boolean(1) "true" as "%1"."%1" ]
-) [ "sys"."sql_div"(double(53)["sys"."rand"()], double(53) "2147483648") ]
+ [ "sys"."sql_div"(double(53)["sys"."rand"()], double(53) "2147483648") ]
 
 query I nosort
 select rand(-5) >= 0
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to