mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Bug #21809: Error 1356 while selecting from view with grouping though underlying
select OK. The SQL parser was using Item::name to transfer user defined function attributes to the user defined function (udf). It was not distinguishing between user defined function call arguments and stored procedure call arguments. Setting Item::name was causing Item_ref::print() method to print the argument as quoted identifiers and caused views that reference aggregate functions as udf call arguments (and rely on Item::print() for the text of the view to store) to throw an undefined identifier error. Overloaded Item_ref::print to print aggregate functions as such when printing the references to aggregate functions taken out of context by split_sum_func2() Fixed the parser to properly detect using AS clause in stored procedure arguments as an error. Fixed printing the arguments of udf call to print properly the udf attribute. mysql-test/r/udf.result: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - test cases mysql-test/t/udf.test: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - test cases sql/item.cc: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - Don't print the refs to SUM functions as refs. sql/item_func.cc: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - print the aliases in the udf calls sql/item_func.h: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - print the aliases in the udf calls sql/sql_lex.cc: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - disable aliases for arguments in stored routine calls sql/sql_lex.h: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - disable aliases for arguments in stored routine calls sql/sql_yacc.yy: Bug #21809: Error 1356 while selecting from view with grouping though underlying select OK. - disable aliases for arguments in stored routine calls - fix bison duplicate symbol warnings
This commit is contained in:
@ -105,6 +105,85 @@ explain select myfunc_int(f1) from t1 order by 1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
||||
drop table t1;
|
||||
CREATE TABLE t1(a INT, b INT);
|
||||
INSERT INTO t1 values (1,1),(2,2);
|
||||
CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN a;
|
||||
END
|
||||
||
|
||||
CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
|
||||
SELECT myfunc_int(a AS attr_name) FROM t1;
|
||||
myfunc_int(a AS attr_name)
|
||||
1
|
||||
2
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
|
||||
Warnings:
|
||||
Note 1003 select myfunc_int(`test`.`t1`.`a` AS `attr_name`) AS `myfunc_int(a AS attr_name)` from `test`.`t1`
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2
|
||||
Warnings:
|
||||
Note 1003 select myfunc_int(`test`.`t1`.`a` AS `a`) AS `myfunc_int(a)` from `test`.`t1`
|
||||
SELECT a,c FROM v1;
|
||||
a c
|
||||
1 1
|
||||
2 2
|
||||
SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx) as c FROM t1 GROUP BY a' at line 1
|
||||
SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx)) as c FROM t1 GROUP BY a' at line 1
|
||||
SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
|
||||
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'xx)) as c FROM t1 GROUP BY a' at line 1
|
||||
SELECT myfunc_int(fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
|
||||
c
|
||||
1
|
||||
2
|
||||
SELECT myfunc_int(test.fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
|
||||
c
|
||||
1
|
||||
2
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
||||
Warnings:
|
||||
Note 1003 select myfunc_int(min(`test`.`t1`.`b`) AS `xx`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
|
||||
EXPLAIN EXTENDED SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
||||
Warnings:
|
||||
Note 1003 select `test`.`fn`(min(`test`.`t1`.`b`)) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
||||
Warnings:
|
||||
Note 1003 select myfunc_int(`test`.`fn`(min(`test`.`t1`.`b`)) AS `fn(MIN(b))`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
id select_type table type possible_keys key key_len ref rows Extra
|
||||
1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using temporary; Using filesort
|
||||
Warnings:
|
||||
Note 1003 select myfunc_int(`test`.`fn`(min(`test`.`t1`.`b`)) AS `test.fn(MIN(b))`) AS `c` from `test`.`t1` group by `test`.`t1`.`a`
|
||||
SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
|
||||
c
|
||||
1
|
||||
2
|
||||
SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
|
||||
c
|
||||
1
|
||||
2
|
||||
SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
c
|
||||
1
|
||||
2
|
||||
SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
c
|
||||
1
|
||||
2
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
DROP FUNCTION fn;
|
||||
End of 5.0 tests.
|
||||
DROP FUNCTION metaphon;
|
||||
DROP FUNCTION myfunc_double;
|
||||
|
@ -127,6 +127,50 @@ create table t1(f1 int);
|
||||
insert into t1 values(1),(2);
|
||||
explain select myfunc_int(f1) from t1 order by 1;
|
||||
drop table t1;
|
||||
|
||||
#
|
||||
# Bug #21809: Error 1356 while selecting from view with grouping though
|
||||
# underlying select OK.
|
||||
#
|
||||
CREATE TABLE t1(a INT, b INT); INSERT INTO t1 values (1,1),(2,2);
|
||||
|
||||
DELIMITER ||;
|
||||
CREATE FUNCTION fn(a int) RETURNS int DETERMINISTIC
|
||||
BEGIN
|
||||
RETURN a;
|
||||
END
|
||||
||
|
||||
DELIMITER ;||
|
||||
|
||||
CREATE VIEW v1 AS SELECT a, fn(MIN(b)) as c FROM t1 GROUP BY a;
|
||||
|
||||
SELECT myfunc_int(a AS attr_name) FROM t1;
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(a AS attr_name) FROM t1;
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(a) FROM t1;
|
||||
SELECT a,c FROM v1;
|
||||
|
||||
--error ER_PARSE_ERROR
|
||||
SELECT a, fn(MIN(b) xx) as c FROM t1 GROUP BY a;
|
||||
--error ER_PARSE_ERROR
|
||||
SELECT myfunc_int(fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
|
||||
--error ER_PARSE_ERROR
|
||||
SELECT myfunc_int(test.fn(MIN(b) xx)) as c FROM t1 GROUP BY a;
|
||||
|
||||
SELECT myfunc_int(fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
|
||||
SELECT myfunc_int(test.fn(MIN(b)) xx) as c FROM t1 GROUP BY a;
|
||||
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
|
||||
EXPLAIN EXTENDED SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
EXPLAIN EXTENDED SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
SELECT myfunc_int(MIN(b) xx) as c FROM t1 GROUP BY a;
|
||||
SELECT test.fn(MIN(b)) as c FROM t1 GROUP BY a;
|
||||
SELECT myfunc_int(fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
SELECT myfunc_int(test.fn(MIN(b))) as c FROM t1 GROUP BY a;
|
||||
DROP VIEW v1;
|
||||
DROP TABLE t1;
|
||||
DROP FUNCTION fn;
|
||||
|
||||
--echo End of 5.0 tests.
|
||||
|
||||
#
|
||||
|
Reference in New Issue
Block a user