Changeset: 7488738bdd7e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=7488738bdd7e
Modified Files:
sql/server/rel_select.c
sql/test/subquery/Tests/subquery3.stable.err
Branch: linear-hashing
Log Message:
Fix for the order by crash, ie when adding a new column into a projection,
check for cardinality mismatches
diffs (79 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
@@ -1284,8 +1284,6 @@ exp_fix_scale(mvc *sql, sql_subtype *ct,
return e;
}
-
-
static int
rel_binop_check_types(mvc *sql, sql_rel *rel, sql_exp *ls, sql_exp *rs, int
upcast)
{
@@ -4176,10 +4174,20 @@ rel_order_by_column_exp(sql_query *query
p->l = r;
if (e && p) {
e = rel_project_add_exp(sql, p, e);
+ for (node *n = p->exps->h ; n ; n = n->next) {
+ sql_exp *ee = n->data;
+
+ if (ee->card > r->card) {
+ if (exp_name(ee))
+ return sql_error(sql, ERR_GROUPBY,
SQLSTATE(42000) "SELECT: cannot use non GROUP BY column '%s' in query results
without an aggregate function", exp_name(ee));
+ else
+ return sql_error(sql, ERR_GROUPBY,
SQLSTATE(42000) "SELECT: cannot use non GROUP BY column in query results
without an aggregate function");
+ }
+ }
return e;
}
if (e && r && is_project(r->op)) {
- sql_exp * found = exps_find_exp(r->exps, e);
+ sql_exp *found = exps_find_exp(r->exps, e);
if (!found) {
append(r->exps, e);
@@ -4262,14 +4270,14 @@ rel_order_by(sql_query *query, sql_rel *
return sql_error(sql, 02,
SQLSTATE(42000) "order not of type SQL_COLUMN");
}
} else if (e && exp_card(e) > rel->card) {
- if (e && exp_name(e)) {
+ if (exp_name(e)) {
return sql_error(sql,
ERR_GROUPBY, SQLSTATE(42000) "SELECT: cannot use non GROUP BY column '%s' in
query results without an aggregate function", exp_name(e));
} else {
return sql_error(sql,
ERR_GROUPBY, SQLSTATE(42000) "SELECT: cannot use non GROUP BY column in query
results without an aggregate function");
}
}
if (e && rel && is_project(rel->op)) {
- sql_exp * found =
exps_find_exp(rel->exps, e);
+ sql_exp *found =
exps_find_exp(rel->exps, e);
if (!found) {
append(rel->exps, e);
diff --git a/sql/test/subquery/Tests/subquery3.stable.err
b/sql/test/subquery/Tests/subquery3.stable.err
--- a/sql/test/subquery/Tests/subquery3.stable.err
+++ b/sql/test/subquery/Tests/subquery3.stable.err
@@ -212,7 +212,23 @@ MAPI = (monetdb) /var/tmp/mtest-54567/.
QUERY = SELECT col1 FROM another_T WHERE (col2, col3) IN (VALUES(1,2,3)); --
error, too many columns in the subquery
ERROR = !Subquery has too many columns
CODE = 42000
-MAPI = (monetdb) /var/tmp/mtest-135307/.s.monetdb.36213
+MAPI = (monetdb) /var/tmp/mtest-116419/.s.monetdb.38396
+QUERY = SELECT * FROM integers i1 ORDER BY SUM(i); --column "i1.i" must appear
in the GROUP BY clause or be used in an aggregate function
+ERROR = !SELECT: cannot use non GROUP BY column 'i' in query results without
an aggregate function
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-116419/.s.monetdb.38396
+QUERY = SELECT i FROM integers i1 ORDER BY SUM(i); --column "i1.i" must appear
in the GROUP BY clause or be used in an aggregate function
+ERROR = !SELECT: cannot use non GROUP BY column 'i' in query results without
an aggregate function
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-116419/.s.monetdb.38396
+QUERY = SELECT * FROM integers i1 ORDER BY (SELECT SUM(i1.i) FROM integers
i2); --column "i1.i" must appear in the GROUP BY clause or be used in an
aggregate function
+ERROR = !SELECT: cannot use non GROUP BY column 'i' in query results without
an aggregate function
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-116419/.s.monetdb.38396
+QUERY = SELECT i FROM integers i1 ORDER BY (SELECT SUM(i1.i) FROM integers
i2); --column "i1.i" must appear in the GROUP BY clause or be used in an
aggregate function
+ERROR = !SELECT: cannot use non GROUP BY column 'i' in query results without
an aggregate function
+CODE = 42000
+MAPI = (monetdb) /var/tmp/mtest-116419/.s.monetdb.38396
QUERY = SELECT
(SELECT outt FROM evilfunction((SELECT col0)))
FROM another_T; --error, col0 doesn't exist
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list