Changeset: 9002cd2e43b9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9002cd2e43b9
Added Files:
sql/test/BugTracker-2018/Tests/aggr-in-case.Bug-6526.sql
sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.sql
sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.stable.err
sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.stable.out
Modified Files:
sql/server/rel_select.c
sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
sql/test/BugTracker-2016/Tests/rename_exps.Bug-3974.stable.out
sql/test/BugTracker-2018/Tests/All
Branch: default
Log Message:
Merge with Jul2017 branch.
diffs (truncated from 395 to 300 lines):
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
@@ -238,6 +238,13 @@ rel_table_optname(mvc *sql, sql_rel *sq,
columnrefs = optname->data.lval->h->next->data.lval;
if (is_apply(sq->op))
sq = sq->r;
+ if (is_topn(sq->op) || (is_project(sq->op) && sq->r)) {
+ sq = rel_project(sql->sa, sq, rel_projections(sql, sq,
NULL, 1, 1));
+ if (osq != sq->l) /* apply */
+ osq->r = sq;
+ else
+ osq = sq;
+ }
if (columnrefs && sq->exps) {
dnode *d = columnrefs->h;
node *ne = sq->exps->h;
@@ -257,15 +264,6 @@ rel_table_optname(mvc *sql, sql_rel *sq,
if (!columnrefs && sq->exps) {
node *ne;
- if (is_topn(sq->op)) {
- assert(sq->l);
- assert(is_project(((sql_rel*)sq->l)->op));
- sq = rel_project(sql->sa, sq,
rel_projections(sql, sq, NULL, 1, 1));
- if (osq != sq->l) /* apply */
- osq->r = sq;
- else
- osq = sq;
- }
ne = sq->exps->h;
for (; ne; ne = ne->next) {
sql_exp *e = ne->data;
@@ -3626,6 +3624,7 @@ static sql_exp *
e = exp_column(sql->sa, exp_relname(e), exp_name(e),
exp_subtype(e), exp_card(e), has_nil(e), is_intern(e));
}
rel_project_add_exp(sql, project, e);
+ e = exp_column(sql->sa, exp_relname(e), exp_name(e),
exp_subtype(e), exp_card(e), has_nil(e), is_intern(e));
return e;
}
diff --git
a/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
b/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
---
a/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
+++
b/sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
@@ -310,24 +310,26 @@ project (
% .plan # table_name
% rel # name
% clob # type
-% 51 # length
+% 53 # length
project (
-| distinct union (
-| | project (
-| | | group by (
-| | | | project (
-| | | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | | | ) [ "t2606a"."a" ]
-| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | ) [ "t2606a"."a" as "L5"."a" ],
-| | project (
-| | | group by (
-| | | | project (
-| | | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | | | ) [ "t2606b"."a" ]
-| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | ) [ "t2606b"."a" as "L6"."a" ]
-| ) [ "L5"."a" as "t"."a" ]
+| project (
+| | distinct union (
+| | | project (
+| | | | group by (
+| | | | | project (
+| | | | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
+| | | | | ) [ "t2606a"."a" ]
+| | | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
+| | | ) [ "t2606a"."a" as "L5"."a" ],
+| | | project (
+| | | | group by (
+| | | | | project (
+| | | | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
+| | | | | ) [ "t2606b"."a" ]
+| | | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
+| | | ) [ "t2606b"."a" as "L6"."a" ]
+| | ) [ "L5"."a" as "L11"."a" ]
+| ) [ "L11"."a" as "t"."a" ]
) [ "t"."a" ] [ "t"."a" ASC ]
#select * from (select * from t2606a union select * from t2606b) as t order by
a;
% .t # table_name
@@ -347,16 +349,18 @@ project (
% .plan # table_name
% rel # name
% clob # type
-% 47 # length
+% 49 # length
project (
-| distinct except (
-| | project (
-| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "L5"."a" ],
-| | project (
-| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "L6"."a" ]
-| ) [ "L5"."a" as "t"."a" ]
+| project (
+| | distinct except (
+| | | project (
+| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
+| | | ) [ "t2606a"."a" as "L5"."a" ],
+| | | project (
+| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
+| | | ) [ "t2606b"."a" as "L6"."a" ]
+| | ) [ "L5"."a" as "L11"."a" ]
+| ) [ "L11"."a" as "t"."a" ]
) [ "t"."a" ] [ "t"."a" ASC ]
#select * from (select * from t2606a except select * from t2606b) as t order
by a;
% sys.t # table_name
@@ -370,16 +374,18 @@ project (
% .plan # table_name
% rel # name
% clob # type
-% 47 # length
+% 49 # length
project (
-| distinct intersect (
-| | project (
-| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "L5"."a" ],
-| | project (
-| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "L6"."a" ]
-| ) [ "L5"."a" as "t"."a" ]
+| project (
+| | distinct intersect (
+| | | project (
+| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
+| | | ) [ "t2606a"."a" as "L5"."a" ],
+| | | project (
+| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
+| | | ) [ "t2606b"."a" as "L6"."a" ]
+| | ) [ "L5"."a" as "L11"."a" ]
+| ) [ "L11"."a" as "t"."a" ]
) [ "t"."a" ] [ "t"."a" ASC ]
#select * from (select * from t2606a intersect select * from t2606b) as t
order by a;
% sys.t # table_name
diff --git a/sql/test/BugTracker-2016/Tests/rename_exps.Bug-3974.stable.out
b/sql/test/BugTracker-2016/Tests/rename_exps.Bug-3974.stable.out
--- a/sql/test/BugTracker-2016/Tests/rename_exps.Bug-3974.stable.out
+++ b/sql/test/BugTracker-2016/Tests/rename_exps.Bug-3974.stable.out
@@ -36,7 +36,7 @@ Ready.
% type, digits, scale, schema, table, column # name
% varchar, int, int, str, str, str # type
% 6, 2, 1, 0, 3, 3 # length
-[ "bigint", 64, 0, "", "L17", "L16" ]
+[ "bigint", 64, 0, "", "L20", "L17" ]
#drop table foo;
# 12:27:17 >
diff --git a/sql/test/BugTracker-2018/Tests/All
b/sql/test/BugTracker-2018/Tests/All
--- a/sql/test/BugTracker-2018/Tests/All
+++ b/sql/test/BugTracker-2018/Tests/All
@@ -1,10 +1,10 @@
HAVE_LIBPY?pyUDF-crash.Bug-6508
HAVE_HGE?sqlitelogictest-wrong-aggregation-count.Bug-6510
sqlitelogictest-wrong-select-not-between.Bug-6511
+case_with_orderby_limit.Bug-6512
sqlitelogictest-wrong-mal-function-generation.Bug-6513
sqlitelogictest-select-range-null.Bug-6514
insert-null-second-interval-0.Bug-6515
-case_with_orderby_limit.Bug-6512
sqlitelogictest-bat-undefined.Bug-6516
sqlitelogictest-overflow-in-conversion.Bug-6517
HAVE_HGE?sqlitelogictest-count-not-in.Bug-6518
@@ -13,3 +13,5 @@ update-with-correlated-subquery.Bug-6520
sqlitelogictest-in-single-column.Bug-6522
sqlitelogictest-case-subquery-missing.Bug-6523
sqlitelogictest-group-by-having-in-count.Bug-6524
+aggr-in-case.Bug-6526
+crash-orderby-alias.Bug-6527
diff --git a/sql/test/BugTracker-2018/Tests/aggr-in-case.Bug-6526.sql
b/sql/test/BugTracker-2018/Tests/aggr-in-case.Bug-6526.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2018/Tests/aggr-in-case.Bug-6526.sql
@@ -0,0 +1,49 @@
+start transaction;
+
+create table "t1" (
+ "id" int,
+ "c1" varchar(100),
+ "d1" int,
+ "d2" int
+);
+
+insert into "t1" values
+(1, 'A', 50, 80),
+(2, 'A', 200, 350),
+(3, 'A', 89, 125),
+(4, 'B', 4845, 13),
+(5, 'B', 194, 597),
+(6, 'C', 5636, 5802),
+(7, 'C', 375, 3405),
+(7, 'D', 365, 0),
+(7, 'D', 87, 0);
+
+-- Works
+select
+ "c1",
+ sum("d1") as "d1",
+ sum("d2") as "d2"
+from "t1"
+group by "c1"
+having sum("d1") < case when 5 > 10 then 500 else 400 end;
+
+-- Works
+select
+ "c1",
+ sum("d1")as "d1",
+ sum("d2") as "d2",
+ 1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null
end) as "formula"
+from "t1"
+group by "c1";
+
+-- Crashes
+select
+ "c1",
+ sum("d1")as "d1",
+ sum("d2") as "d2",
+ 1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else null
end) as "formula"
+from "t1"
+group by "c1"
+having (1.0 * sum("d1") / (1.0 * case when sum("d2") > 0 then sum("d2") else
null end)) > 1;
+
+rollback;
diff --git a/sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.sql
b/sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.sql
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.sql
@@ -0,0 +1,33 @@
+
+create table "t1" ("d1" int);
+insert into "t1" values (1), (2), (3), (4), (5);
+
+-- Works
+select
+ "d1" as "value"
+from "t1"
+order by "value";
+
+
+-- Works
+select
+ a."value"
+from (
+ select
+ "d1" as "value"
+ from "t1"
+ order by "d1"
+) as a;
+
+
+-- Crashes
+select
+ a."value"
+from (
+ select
+ "d1" as "value"
+ from "t1"
+ order by "value"
+) as a;
+
+drop table t1;
diff --git
a/sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.stable.err
b/sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.stable.err
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2018/Tests/crash-orderby-alias.Bug-6527.stable.err
@@ -0,0 +1,34 @@
+stderr of test 'crash-orderby-alias.Bug-6527` in directory
'sql/test/BugTracker-2018` itself:
+
+
+# 21:50:49 >
+# 21:50:49 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set"
"mapi_open=true" "--set" "mapi_port=31483" "--set"
"mapi_usock=/var/tmp/mtest-31627/.s.monetdb.31483" "--set" "monet_prompt="
"--forcemito"
"--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018"
+# 21:50:49 >
+
+# builtin opt gdk_dbpath =
/home/niels/scratch/rc-monetdb/Linux-x86_64/var/monetdb5/dbfarm/demo
+# builtin opt gdk_debug = 0
+# builtin opt gdk_vmtrim = no
+# builtin opt monet_prompt = >
+# builtin opt monet_daemon = no
+# builtin opt mapi_port = 50000
+# builtin opt mapi_open = false
+# builtin opt mapi_autosense = false
+# builtin opt sql_optimizer = default_pipe
+# builtin opt sql_debug = 0
+# cmdline opt gdk_nr_threads = 0
+# cmdline opt mapi_open = true
+# cmdline opt mapi_port = 31483
+# cmdline opt mapi_usock = /var/tmp/mtest-31627/.s.monetdb.31483
+# cmdline opt monet_prompt =
+# cmdline opt gdk_dbpath =
/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2018
+# cmdline opt gdk_debug = 553648138
+
+# 21:50:49 >
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list