mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
Fixed bug #16382.
When an ambiguous field name is used in a group by clause a warning is issued in the find_order_in_list function by a call to push_warning_printf. An expression that was not always valid was passed to this call as the field name parameter. mysql-test/r/view.result: Added a test case for bug #16382. mysql-test/t/view.test: Added a test case for bug #16382.
This commit is contained in:
@ -2504,3 +2504,37 @@ id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Select tables optimized away
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
CREATE TABLE t1 (x varchar(10));
|
||||
INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x;
|
||||
IF(x IS NULL, 'blank', 'not blank')
|
||||
blank
|
||||
not blank
|
||||
not blank
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x;
|
||||
x
|
||||
blank
|
||||
not blank
|
||||
not blank
|
||||
Warnings:
|
||||
Warning 1052 Column 'x' in group statement is ambiguous
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1;
|
||||
x
|
||||
blank
|
||||
not blank
|
||||
not blank
|
||||
blank
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y;
|
||||
y
|
||||
blank
|
||||
not blank
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x;
|
||||
x
|
||||
blank
|
||||
not blank
|
||||
not blank
|
||||
Warnings:
|
||||
Warning 1052 Column 'x' in group statement is ambiguous
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
|
@ -2363,3 +2363,20 @@ EXPLAIN SELECT MIN(a) FROM v1;
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
|
||||
#
|
||||
# Bug#16382: grouping name is resolved against a view column name
|
||||
# which coincides with a select column name
|
||||
|
||||
CREATE TABLE t1 (x varchar(10));
|
||||
INSERT INTO t1 VALUES (null), ('foo'), ('bar'), (null);
|
||||
CREATE VIEW v1 AS SELECT * FROM t1;
|
||||
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') FROM v1 GROUP BY x;
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM t1 GROUP BY x;
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1;
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS y FROM v1 GROUP BY y;
|
||||
SELECT IF(x IS NULL, 'blank', 'not blank') AS x FROM v1 GROUP BY x;
|
||||
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
|
@ -12381,7 +12381,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
|
||||
overshadows the column reference from the SELECT list.
|
||||
*/
|
||||
push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
|
||||
ER(ER_NON_UNIQ_ERROR), from_field->field_name,
|
||||
ER(ER_NON_UNIQ_ERROR),
|
||||
((Item_ident*) order_item)->field_name,
|
||||
current_thd->where);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user