Changeset: c0156b4f4fc6 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/c0156b4f4fc6
Modified Files:
        sql/server/rel_exp.c
        sql/server/sql_atom.c
        
sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.test
        sql/test/SQLancer/Tests/sqlancer17.test
        sql/test/SQLancer/Tests/sqlancer19.SQL.py
        sql/test/mergetables/Tests/mergequery.test
        sql/test/sys-schema/Tests/webExamplesComparisonFunctionsOperators.test
        sql/test/sys-schema/Tests/webExamplesMathematicalFunctionsOperators.test
Branch: Jan2022
Log Message:

If the to be casted type is a subtype, it may be different, so do the cast


diffs (150 lines):

diff --git a/sql/server/rel_exp.c b/sql/server/rel_exp.c
--- a/sql/server/rel_exp.c
+++ b/sql/server/rel_exp.c
@@ -3049,7 +3049,6 @@ exp_convert_inplace(mvc *sql, sql_subtyp
 
        if ((na = atom_cast(sql->sa, a, t))) {
                exp->l = na;
-               exp->tpe = *t;
                return exp;
        }
        return NULL;
diff --git a/sql/server/sql_atom.c b/sql/server/sql_atom.c
--- a/sql/server/sql_atom.c
+++ b/sql/server/sql_atom.c
@@ -697,8 +697,19 @@ atom_cast(sql_allocator *sa, atom *a, sq
        atom *na = NULL;
        sql_subtype *at = &a->tpe;
 
-       if (subtype_cmp(at, tp) == 0)
+       if (subtype_cmp(at, tp) == 0) {
+               /* it may be a subtype, but still a different one */
+               if (at->type->base.id != tp->type->base.id ||
+                       at->digits != tp->digits || at->scale != tp->scale) {
+                       na = atom_create(sa);
+                       SA_VALcopy(sa, &na->data, &a->data);
+                       na->data.vtype = tp->type->localtype;
+                       na->tpe = *tp;
+                       na->isnull = a->isnull;
+                       return na;
+               }
                return a;
+       }
        if (!a->isnull) {
                /* need to do a cast, start simple is atom type a subtype of tp 
*/
                if ((at->type->eclass == tp->type->eclass ||
diff --git 
a/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.test
 
b/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.test
--- 
a/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.test
+++ 
b/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.test
@@ -185,7 +185,7 @@ top N (
 | | | | ) [ ("a3"."t3pkcol" HASHCOL ) = ("table1"."t1cold113") ],
 | | | | table("sys"."table12") [ "table12"."t12cola1" ]
 | | | ) [ ("table12"."t12cola1") = ("table1"."t1cola1") ]
-| | ) [ ((((((((((((((("table1"."t1cold1") FILTER "sys"."like"(clob "%a%", 
clob "", boolean(1) "true")) or (("table1"."t1cola1") FILTER "sys"."like"(clob 
"%a%", clob "", boolean(1) "true"))) or (("table1"."t1colb1") FILTER 
"sys"."like"(clob "%a%", clob "", boolean(1) "true"))) or 
(("table1"."t1cola11") FILTER "sys"."like"(clob "%business%", clob "", 
boolean(1) "true"))) or (("table1"."t1colc91") >= (timestamp(7) "2016-03-21 
05:00:00.000000"))) or (("table1"."t1cola101") = (tinyint(1) "1"))) or 
(("table1"."t1cola12") FILTER "sys"."like"(clob "%Vijay%", clob "", boolean(1) 
"true"))) or (("table2"."t2cola1") ! FILTER "sys"."like"(clob "%gmail%", clob 
"", boolean(1) "true"), ("table2"."t2cola1") ! FILTER "sys"."like"(clob 
"%yahoo%", clob "", boolean(1) "true"))) or (("table2"."t2cola1") FILTER 
"sys"."like"(clob "%efequitygroup.com%", clob "", boolean(1) "true"))) or 
(("table4"."t4cola1") = (clob "Customer"))) or (("table4"."t4cola2") ! * = 
(clob NULL))) or (("table2"."t2cola81") >= (dat
 e "2009-08-31"))) or (((("table5"."t5cola1") = (clob "BAT")) or 
(("table5"."t5cola2") FILTER "sys"."like"(clob "%AUSTRALIA%", clob "", 
boolean(1) "true"))) or (("table5"."t5cola2") FILTER "sys"."like"(clob 
"%Monet%", clob "", boolean(1) "true"), ("table5"."t5cola3") = (clob 
"Facebook"), ("table5"."t5cola5") = (clob "new"), ("table5"."t5cola81") > (date 
"2015-07-30")))) or (((("table10"."t10cola1") != (clob "Completed"), 
("table9"."t9cola1") = (clob "Tasks"), ("table9"."t9cola91") >= (timestamp(7) 
"2012-01-01 04:32:27.000000"), ("table10"."t10cola91") <= (timestamp(7) 
"2013-01-01 04:32:27.000000")) or (("table9"."t9cola1") = (clob "Events"), 
(timestamp(7) "2012-01-01 04:32:27.000000") <= ("table11"."t11cola91") <= 
(timestamp(7) "2013-01-01 04:32:27.000000"))) or (("table9"."t9cola1") = (clob 
"Calls"), (timestamp(7) "2012-01-01 04:32:27.000000") <= 
("table10"."t10cola91") <= (timestamp(7) "2013-01-01 04:32:27.000000"))), 
("table1"."t1cold111") in (bigint(54) "15842000014793046", bigin
 t(54) "15842000017701488", bigint(54) "15842000000024019", bigint(54) 
"15842000000074007", bigint(54) "15842000009358096", bigint(54) 
"15842000010487625", bigint(54) "15842000006731919", bigint(54) 
"15842000002590112", bigint(54) "15842000000019001", bigint(54) 
"15842000014923682", bigint(54) "15842000027547249")) or 
(("table12"."t12cola1") in (clob[bigint(54) "15842000280111951"] NOT NULL, 
clob[bigint(54) "15842000280163015"] NOT NULL)) ]
+| | ) [ ((((((((((((((("table1"."t1cold1") FILTER "sys"."like"(clob "%a%", 
clob "", boolean(1) "true")) or (("table1"."t1cola1") FILTER "sys"."like"(clob 
"%a%", clob "", boolean(1) "true"))) or (("table1"."t1colb1") FILTER 
"sys"."like"(clob "%a%", clob "", boolean(1) "true"))) or 
(("table1"."t1cola11") FILTER "sys"."like"(clob "%business%", clob "", 
boolean(1) "true"))) or (("table1"."t1colc91") >= (timestamp(7) "2016-03-21 
05:00:00.000000"))) or (("table1"."t1cola101") = (tinyint(1) "1"))) or 
(("table1"."t1cola12") FILTER "sys"."like"(clob "%Vijay%", clob "", boolean(1) 
"true"))) or (("table2"."t2cola1") ! FILTER "sys"."like"(clob "%gmail%", clob 
"", boolean(1) "true"), ("table2"."t2cola1") ! FILTER "sys"."like"(clob 
"%yahoo%", clob "", boolean(1) "true"))) or (("table2"."t2cola1") FILTER 
"sys"."like"(clob "%efequitygroup.com%", clob "", boolean(1) "true"))) or 
(("table4"."t4cola1") = (clob "Customer"))) or (("table4"."t4cola2") ! * = 
(clob NULL))) or (("table2"."t2cola81") >= (dat
 e "2009-08-31"))) or (((("table5"."t5cola1") = (clob "BAT")) or 
(("table5"."t5cola2") FILTER "sys"."like"(clob "%AUSTRALIA%", clob "", 
boolean(1) "true"))) or (("table5"."t5cola2") FILTER "sys"."like"(clob 
"%Monet%", clob "", boolean(1) "true"), ("table5"."t5cola3") = (clob 
"Facebook"), ("table5"."t5cola5") = (clob "new"), ("table5"."t5cola81") > (date 
"2015-07-30")))) or (((("table10"."t10cola1") != (clob "Completed"), 
("table9"."t9cola1") = (clob "Tasks"), ("table9"."t9cola91") >= (timestamp(7) 
"2012-01-01 04:32:27.000000"), ("table10"."t10cola91") <= (timestamp(7) 
"2013-01-01 04:32:27.000000")) or (("table9"."t9cola1") = (clob "Events"), 
(timestamp(7) "2012-01-01 04:32:27.000000") <= ("table11"."t11cola91") <= 
(timestamp(7) "2013-01-01 04:32:27.000000"))) or (("table9"."t9cola1") = (clob 
"Calls"), (timestamp(7) "2012-01-01 04:32:27.000000") <= 
("table10"."t10cola91") <= (timestamp(7) "2013-01-01 04:32:27.000000"))), 
("table1"."t1cold111") in (bigint(64) "15842000014793046", bigin
 t(64) "15842000017701488", bigint(64) "15842000000024019", bigint(64) 
"15842000000074007", bigint(64) "15842000009358096", bigint(64) 
"15842000010487625", bigint(64) "15842000006731919", bigint(64) 
"15842000002590112", bigint(64) "15842000000019001", bigint(64) 
"15842000014923682", bigint(64) "15842000027547249")) or 
(("table12"."t12cola1") in (clob[bigint(54) "15842000280111951"] NOT NULL, 
clob[bigint(54) "15842000280163015"] NOT NULL)) ]
 | ) [ "table1"."t1pkcol" NOT NULL HASHCOL , "table1"."t1cola82", 
"table2"."t2cola10", "table1"."t1cola1", "table1"."t1cola91", "a1"."t3cola1" ] 
[ "table2"."t2cola82" NULLS LAST ]
 ) [ bigint(64) "10", bigint(64) "0" ]
 
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
@@ -72,12 +72,12 @@ project (
 | | | | project (
 | | | | | select (
 | | | | | |  [ boolean(1) "true" ]
-| | | | | ) [ (tinyint(2) "2") ! <= (tinyint(1) "1") ! <= (tinyint(2) "2"), 
(tinyint(2) "3") <= (tinyint(2) "2") <= (tinyint(3) "5") ]
+| | | | | ) [ (tinyint(2) "2") ! <= (tinyint(2) "1") ! <= (tinyint(2) "2"), 
(tinyint(3) "3") <= (tinyint(2) "2") <= (tinyint(2) "5") ]
 | | | | ) [ tinyint(2) "2" as "v0"."vc0" ],
 | | | | project (
 | | | | | select (
 | | | | | |  [ boolean(1) "true" ]
-| | | | | ) [ (tinyint(3) "4") ! <= (tinyint(1) "1") ! <= (tinyint(3) "4"), 
(tinyint(2) "3") <= (tinyint(3) "4") <= (tinyint(3) "5") ]
+| | | | | ) [ (tinyint(3) "4") ! <= (tinyint(2) "1") ! <= (tinyint(3) "4"), 
(tinyint(3) "3") <= (tinyint(3) "4") <= (tinyint(2) "5") ]
 | | | | ) [ tinyint(3) "4" as "v0"."vc0" ]
 | | | ) [ "v0"."vc0" NOT NULL ]
 | | ) [ "sys"."sql_max"(tinyint(1) "1", tinyint(1) "1") NOT NULL as 
"v20"."vc0" ]
diff --git a/sql/test/SQLancer/Tests/sqlancer19.SQL.py 
b/sql/test/SQLancer/Tests/sqlancer19.SQL.py
--- a/sql/test/SQLancer/Tests/sqlancer19.SQL.py
+++ b/sql/test/SQLancer/Tests/sqlancer19.SQL.py
@@ -166,6 +166,12 @@ with SQLTestCase() as cli:
         .assertSucceeded().assertDataResultMatch([("d\\\x06VW",)])
     cli.execute("SELECT U&'&+000064&+00005C&+000006&+000056&+000057' UESCAPE 
'&' from rt3 where rt3.c0 = 1;") \
         .assertSucceeded().assertDataResultMatch([("d\\\x06VW",)])
+    cli.execute("""SELECT 1 FROM t1 INNER JOIN (SELECT greatest('a', NULL), 
INTERVAL '4' DAY FROM t3 where t3.c0 = 1) AS q(c0,c1) ON INTERVAL '3' DAY
+            BETWEEN sql_sub(CAST(INTERVAL '3' SECOND AS INTERVAL DAY), 
INTERVAL '2' DAY) AND q.c1;""") \
+        
.assertSucceeded().assertDataResultMatch([(1,),(1,),(1,),(1,),(1,),(1,),(1,),(1,),(1,)])
+    cli.execute("""SELECT 1 FROM t1 INNER JOIN (SELECT greatest('a', NULL), 
INTERVAL '4' DAY FROM rt3 where rt3.c0 = 1) AS q(c0,c1) ON INTERVAL '3' DAY
+            BETWEEN sql_sub(CAST(INTERVAL '3' SECOND AS INTERVAL DAY), 
INTERVAL '2' DAY) AND q.c1;""") \
+        
.assertSucceeded().assertDataResultMatch([(1,),(1,),(1,),(1,),(1,),(1,),(1,),(1,),(1,)])
     cli.execute("""
     CREATE FUNCTION testremote(a int) RETURNS INT
     BEGIN
diff --git a/sql/test/mergetables/Tests/mergequery.test 
b/sql/test/mergetables/Tests/mergequery.test
--- a/sql/test/mergetables/Tests/mergequery.test
+++ b/sql/test/mergetables/Tests/mergequery.test
@@ -148,7 +148,7 @@ PLAN SELECT * FROM complete where x >= 1
 project (
 | select (
 | | table("sys"."part1") [ "part1"."x" as "complete"."x", "part1"."y" as 
"complete"."y", "part1"."z" as "complete"."z" ]
-| ) [ (double(53,1) "1") <= ("complete"."x") < (double(53,1) "2") ]
+| ) [ (double(53) "1") <= ("complete"."x") < (double(53) "2") ]
 ) [ "complete"."x", "complete"."y", "complete"."z" ]
 
 query RRR rowsort
@@ -167,7 +167,7 @@ PLAN SELECT * FROM complete where x > 1.
 project (
 | select (
 | | table("sys"."part2") [ "part2"."x" as "complete"."x", "part2"."y" as 
"complete"."y", "part2"."z" as "complete"."z" ]
-| ) [ (double(53,1) "1") < ("complete"."x") <= (double(53,1) "2") ]
+| ) [ (double(53) "1") < ("complete"."x") <= (double(53) "2") ]
 ) [ "complete"."x", "complete"."y", "complete"."z" ]
 
 query RRR rowsort
@@ -200,12 +200,12 @@ union (
 | project (
 | | select (
 | | | table("sys"."part1") [ "part1"."x" as "complete"."x", "part1"."y" as 
"complete"."y", "part1"."z" as "complete"."z" ]
-| | ) [ (double(53,1) "1") <= ("complete"."x") <= (double(53,1) "2") ]
+| | ) [ (double(53) "1") <= ("complete"."x") <= (double(53) "2") ]
 | ) [ "complete"."x", "complete"."y", "complete"."z" ],
 | project (
 | | select (
 | | | table("sys"."part2") [ "part2"."x" as "complete"."x", "part2"."y" as 
"complete"."y", "part2"."z" as "complete"."z" ]
-| | ) [ (double(53,1) "1") <= ("complete"."x") <= (double(53,1) "2") ]
+| | ) [ (double(53) "1") <= ("complete"."x") <= (double(53) "2") ]
 | ) [ "complete"."x", "complete"."y", "complete"."z" ]
 ) [ "complete"."x", "complete"."y", "complete"."z" ]
 
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
@@ -752,7 +752,7 @@ plan select CASE WHEN 9 = 9 THEN NULL EL
 ----
 project (
 |  [ boolean(1) "true" ]
-) [ "sys"."case"("sys"."="(tinyint(4) "9", tinyint(4) "9") NOT NULL, 
tinyint(8) NULL, tinyint(4) "9") ]
+) [ "sys"."case"("sys"."="(tinyint(4) "9", tinyint(4) "9") NOT NULL, 
tinyint(8) NULL, tinyint(8) "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
@@ -108,7 +108,7 @@ plan select 1 << 4
 ----
 project (
 |  [ boolean(1) "true" ]
-) [ "sys"."left_shift"(tinyint(1) "1", int(32) "4") NOT NULL ]
+) [ "sys"."left_shift"(tinyint(8) "1", int(32) "4") NOT NULL ]
 
 query I rowsort
 select left_shift(1, 4) 
@@ -125,7 +125,7 @@ plan select 8 >> 2
 ----
 project (
 |  [ boolean(1) "true" ]
-) [ "sys"."right_shift"(tinyint(4) "8", int(32) "2") NOT NULL ]
+) [ "sys"."right_shift"(tinyint(8) "8", int(32) "2") NOT NULL ]
 
 query I rowsort
 select right_shift(16, 2) 
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to