Commit deacf8b3 authored by mhansson@lamia.dupka's avatar mhansson@lamia.dupka

Merge mhansson@bk-internal.mysql.com:/home/bk/mysql-5.1-opt

into  lamia.dupka:/home/mhansson/my51-bug31797-pushee
parents 947715c2 481a9693
...@@ -1478,3 +1478,39 @@ NULL ...@@ -1478,3 +1478,39 @@ NULL
1 1
2 2
DROP TABLE t1; DROP TABLE t1;
CREATE TABLE t1 ( a INT, b INT );
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
c (SELECT a FROM t1 WHERE b = c)
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
c (SELECT a FROM t1 WHERE b = c)
SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
ERROR 42S22: Reference 'c' not supported (reference to group function)
SET @old_sql_mode = @@sql_mode;
SET @@sql_mode='ONLY_FULL_GROUP_BY';
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
c (SELECT a FROM t1 WHERE b = c)
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
ERROR 42000: non-grouping field 'b' is used in HAVING clause
SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
ERROR 42S22: Reference 'c' not supported (reference to group function)
INSERT INTO t1 VALUES (1, 1);
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
c (SELECT a FROM t1 WHERE b = c)
1 1
INSERT INTO t1 VALUES (2, 1);
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
ERROR 21000: Subquery returns more than 1 row
DROP TABLE t1;
SET @@sql_mode = @old_sql_mode;
...@@ -946,3 +946,51 @@ EXPLAIN SELECT b from t2 GROUP BY b; ...@@ -946,3 +946,51 @@ EXPLAIN SELECT b from t2 GROUP BY b;
SELECT b from t2 GROUP BY b; SELECT b from t2 GROUP BY b;
DROP TABLE t1; DROP TABLE t1;
#
# Bug #31797: error while parsing subqueries -- WHERE is parsed as HAVING
#
CREATE TABLE t1 ( a INT, b INT );
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
--error ER_ILLEGAL_REFERENCE
SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
SET @old_sql_mode = @@sql_mode;
SET @@sql_mode='ONLY_FULL_GROUP_BY';
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
--error ER_NON_GROUPING_FIELD_USED
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
--error ER_ILLEGAL_REFERENCE
SELECT MAX(b) c, (SELECT a FROM t1 WHERE b = c)
FROM t1
HAVING b = 10;
INSERT INTO t1 VALUES (1, 1);
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
INSERT INTO t1 VALUES (2, 1);
--error ER_SUBQUERY_NO_1_ROW
SELECT b c, (SELECT a FROM t1 WHERE b = c)
FROM t1;
DROP TABLE t1;
SET @@sql_mode = @old_sql_mode;
...@@ -3408,7 +3408,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list) ...@@ -3408,7 +3408,7 @@ static Item** find_field_in_group_list(Item *find_item, ORDER *group_list)
resolve_ref_in_select_and_group() resolve_ref_in_select_and_group()
thd current thread thd current thread
ref column reference being resolved ref column reference being resolved
select the sub-select that ref is resolved against select the select that ref is resolved against
DESCRIPTION DESCRIPTION
Resolve a column reference (usually inside a HAVING clause) against the Resolve a column reference (usually inside a HAVING clause) against the
...@@ -3479,6 +3479,7 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select) ...@@ -3479,6 +3479,7 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
} }
if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY && if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
select->having_fix_field &&
select_ref != not_found_item && !group_by_ref) select_ref != not_found_item && !group_by_ref)
{ {
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment