Changeset: 206194fe6c3c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=206194fe6c3c
Modified Files:
sql/server/rel_rel.c
sql/server/rel_select.c
sql/test/BugTracker-2010/Tests/ORDER_BY_over_UNION_EXCEPT_INTERSECT.Bug-2606.stable.out
sql/test/BugTracker-2015/Tests/crash.Bug-3736.stable.out
sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out
sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-0join-view.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-query.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-1join-view.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-query.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-explain-2join-view.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-view.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-query.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-1join-view.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-query.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-2join-view.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-prologue.stable.out
sql/test/SQLancer/Tests/sqlancer07.sql
sql/test/SQLancer/Tests/sqlancer07.stable.err
sql/test/SQLancer/Tests/sqlancer07.stable.out
sql/test/Tests/order_by_complex_exp.stable.out
sql/test/merge-partitions/Tests/mergepart31.stable.out
sql/test/miscellaneous/Tests/groupby_error.stable.out
sql/test/miscellaneous/Tests/simple_plans.stable.out
sql/test/miscellaneous/Tests/simple_plans.stable.out.single
Branch: Oct2020
Log Message:
Making SQLancer happy. While parsing the from clause, there might be multiple
relations behind the current relation, so find duplicates more precisely. Also
don't increment SQL label counter if is not going to be used
diffs (truncated from 1096 to 300 lines):
diff --git a/sql/server/rel_rel.c b/sql/server/rel_rel.c
--- a/sql/server/rel_rel.c
+++ b/sql/server/rel_rel.c
@@ -1014,12 +1014,13 @@ list *
return exps;
case op_groupby:
if (list_empty(rel->exps) && rel->r) {
- node *en;
list *r = rel->r;
- int label = ++sql->label;
+ int label = 0;
+ if (!settname)
+ label = ++sql->label;
exps = new_exp_list(sql->sa);
- for (en = r->h; en; en = en->next) {
+ for (node *en = r->h; en; en = en->next) {
sql_exp *e = en->data;
if (basecol && !is_basecol(e))
@@ -1042,11 +1043,12 @@ list *
case op_except:
case op_inter:
if (rel->exps) {
- node *en;
- int label = ++sql->label;
+ int label = 0;
+ if (!settname)
+ label = ++sql->label;
exps = new_exp_list(sql->sa);
- for (en = rel->exps->h; en; en = en->next) {
+ for (node *en = rel->exps->h; en; en = en->next) {
sql_exp *e = en->data;
if (basecol && !is_basecol(e))
@@ -1064,9 +1066,11 @@ list *
rexps = _rel_projections(sql, rel->r, tname, settname, intern,
basecol);
exps = sa_list(sql->sa);
if (lexps && rexps && exps) {
- node *en, *ren;
- int label = ++sql->label;
- for (en = lexps->h, ren = rexps->h; en && ren; en =
en->next, ren = ren->next) {
+ int label = 0;
+
+ if (!settname)
+ label = ++sql->label;
+ for (node *en = lexps->h, *ren = rexps->h; en && ren;
en = en->next, ren = ren->next) {
sql_exp *e = en->data;
e->card = rel->card;
if (!settname) /* noname use alias */
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
@@ -5460,6 +5460,15 @@ rel_unique_names(mvc *sql, sql_rel *rel)
return rel;
}
+static int
+exp_relname_cmp(sql_exp *e1, sql_exp *e2)
+{
+ const char *r1 = exp_relname(e1), *r2 = exp_relname(e2);
+ if (!r1 || !r2)
+ return -1;
+ return strcmp(r1, r2);
+}
+
static sql_rel *
rel_query(sql_query *query, sql_rel *rel, symbol *sq, int toplevel, exp_kind
ek)
{
@@ -5498,8 +5507,8 @@ rel_query(sql_query *query, sql_rel *rel
list *names = new_exp_list(sql->sa);
for (dnode *n = fl->h; n ; n = n->next) {
- char *nrame = NULL;
int lateral = check_is_lateral(n->data.sym);
+ list *projs, *projs_distinct_names;
/* just used current expression */
fnd = table_ref(query, NULL, n->data.sym, lateral);
@@ -5514,13 +5523,20 @@ rel_query(sql_query *query, sql_rel *rel
}
if (!fnd)
break;
- if ((nrame = (char*) rel_name(fnd))) {
- if (list_find(names, nrame, (fcmp) &strcmp)) {
- if (res)
- rel_destroy(res);
- return sql_error(sql, 01,
SQLSTATE(42000) "SELECT: relation name \"%s\" specified more than once", nrame);
- } else
- list_append(names, nrame);
+ projs = rel_projections(sql, fnd, NULL, 1, 0);
+ projs_distinct_names = list_distinct(projs, (fcmp)
exp_relname_cmp, (fdup) NULL);
+
+ for (node *m = projs_distinct_names->h ; m ; m =
m->next) {
+ char *nrame = (char *)exp_relname((sql_exp
*)m->data);
+
+ if (nrame) {
+ if (list_find(names, nrame, (fcmp)
&strcmp)) {
+ if (res)
+ rel_destroy(res);
+ return sql_error(sql, 01,
SQLSTATE(42000) "SELECT: relation name \"%s\" specified more than once", nrame);
+ } else
+ list_append(names, nrame);
+ }
}
if (res) {
res = rel_crossproduct(sql->sa, res, fnd,
op_join);
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
@@ -67,16 +67,16 @@ project (
| | | group by (
| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | group by (
| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#select * from t2606a union select * from t2606b order by a;
-% .%7 # table_name
+% .%5 # table_name
% a # name
% int # type
% 2 # length
@@ -100,16 +100,16 @@ project (
| | | group by (
| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | group by (
| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#( select * from t2606a union select * from t2606b ) order by a;
-% .%7 # table_name
+% .%5 # table_name
% a # name
% int # type
% 2 # length
@@ -133,16 +133,16 @@ project (
| | | group by (
| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
| | | ) [ "t2606a"."a" ] [ "t2606a"."a" ]
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | group by (
| | | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
| | | ) [ "t2606b"."a" ] [ "t2606b"."a" ]
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#( select * from t2606a ) union ( select * from t2606b ) order by a;
-% .%7 # table_name
+% .%5 # table_name
% a # name
% int # type
% 2 # length
@@ -164,14 +164,14 @@ project (
| distinct except (
| | project (
| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#select * from t2606a except select * from t2606b order by a;
-% sys.%7 # table_name
+% sys.%5 # table_name
% a # name
% int # type
% 2 # length
@@ -187,14 +187,14 @@ project (
| distinct except (
| | project (
| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#( select * from t2606a except select * from t2606b ) order by a;
-% sys.%7 # table_name
+% sys.%5 # table_name
% a # name
% int # type
% 2 # length
@@ -210,14 +210,14 @@ project (
| distinct except (
| | project (
| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#( select * from t2606a ) except ( select * from t2606b ) order by a;
-% sys.%7 # table_name
+% sys.%5 # table_name
% a # name
% int # type
% 2 # length
@@ -233,14 +233,14 @@ project (
| distinct intersect (
| | project (
| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#select * from t2606a intersect select * from t2606b order by a;
-% sys.%7 # table_name
+% sys.%5 # table_name
% a # name
% int # type
% 2 # length
@@ -256,14 +256,14 @@ project (
| distinct intersect (
| | project (
| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#( select * from t2606a intersect select * from t2606b ) order by a;
-% sys.%7 # table_name
+% sys.%5 # table_name
% a # name
% int # type
% 2 # length
@@ -279,14 +279,14 @@ project (
| distinct intersect (
| | project (
| | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
-| | ) [ "t2606a"."a" as "%3"."a" ],
+| | ) [ "t2606a"."a" as "%1"."a" ],
| | project (
| | | table(sys.t2606b) [ "t2606b"."a" ] COUNT
-| | ) [ "t2606b"."a" as "%4"."a" ]
-| ) [ "%3"."a" as "%7"."a" ]
-) [ "%7"."a" ] [ "%7"."a" ASC ]
+| | ) [ "t2606b"."a" as "%2"."a" ]
+| ) [ "%1"."a" as "%5"."a" ]
+) [ "%5"."a" ] [ "%5"."a" ASC ]
#( select * from t2606a ) intersect ( select * from t2606b ) order by a;
-% sys.%7 # table_name
+% sys.%5 # table_name
% a # name
% int # type
% 2 # length
@@ -304,13 +304,13 @@ project (
| | | group by (
| | | | table(sys.t2606a) [ "t2606a"."a" ] COUNT
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list