Skip to content
Permalink
Browse files

MDEV-7301: Unknown column quoted with backticks in HAVING clause

when using function.

Merged upstream fix to Bug#16221433 MYSQL REJECTS QUERY DUE TO BAD
RESOLUTION OF NAMES IN HAVING; VIEW UNREADABLE
authored by Guilhem Bichot <guilhem.bichot@oracle.com>.
  • Loading branch information...
janlindstrom committed Mar 23, 2015
1 parent 9253064 commit 86f46a3da4a6d82cb510dc4c270d46cfd6a8965b
Showing with 67 additions and 1 deletion.
  1. +31 −0 mysql-test/r/having.result
  2. +34 −0 mysql-test/t/having.test
  3. +2 −1 sql/sql_yacc.yy
@@ -666,3 +666,34 @@ SELECT * FROM t1 WHERE f = 2 HAVING ( pk IN ( SELECT 9 ) AND f != 0 );
pk f
DROP TABLE t1;
End of 5.3 tests
#
# Bug MDEV-7301: Unknown column quoted with backticks in HAVING clause when using function.
# Bug#16221433 MYSQL REJECTS QUERY DUE TO BAD RESOLUTION OF NAMES IN HAVING; VIEW UNREADABLE
#
CREATE TABLE `t1` (
`id` int(11) NOT NULL,
`title` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
INSERT INTO `t1` VALUES ('1', 'Just for fun');
INSERT INTO `t1` VALUES ('2', 'Wait until a sunhine');
INSERT INTO `t1` VALUES ('3', 'Take a new turn');
SELECT `id`, SHA1(`title`) AS `column_1`
FROM `t1`
HAVING `column_1` LIKE '8%';
id column_1
1 80a12660d24a72460e5e292fe33f870276d7f40a
expected 1 row(s) returned
SELECT `id`, SHA1(`title`) AS `column_1`
FROM `t1`
HAVING UPPER(column_1) LIKE '8%';
id column_1
1 80a12660d24a72460e5e292fe33f870276d7f40a
expected -- 1 row(s) returned
SELECT `id`, SHA1(`title`) AS `column_1`
FROM `t1`
HAVING UPPER(`column_1`) LIKE '8%';
id column_1
1 80a12660d24a72460e5e292fe33f870276d7f40a
expected -- 1 row(s) returned not ER_BAD_FIELD_ERROR
drop table t1;
@@ -693,3 +693,37 @@ DROP TABLE t1;

--echo End of 5.3 tests

--echo #
--echo # Bug MDEV-7301: Unknown column quoted with backticks in HAVING clause when using function.
--echo # Bug#16221433 MYSQL REJECTS QUERY DUE TO BAD RESOLUTION OF NAMES IN HAVING; VIEW UNREADABLE
--echo #

CREATE TABLE `t1` (
`id` int(11) NOT NULL,
`title` varchar(45) DEFAULT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;

INSERT INTO `t1` VALUES ('1', 'Just for fun');
INSERT INTO `t1` VALUES ('2', 'Wait until a sunhine');
INSERT INTO `t1` VALUES ('3', 'Take a new turn');

SELECT `id`, SHA1(`title`) AS `column_1`
FROM `t1`
HAVING `column_1` LIKE '8%';

--echo expected 1 row(s) returned

SELECT `id`, SHA1(`title`) AS `column_1`
FROM `t1`
HAVING UPPER(column_1) LIKE '8%';

--echo expected -- 1 row(s) returned

SELECT `id`, SHA1(`title`) AS `column_1`
FROM `t1`
HAVING UPPER(`column_1`) LIKE '8%';

--echo expected -- 1 row(s) returned not ER_BAD_FIELD_ERROR

drop table t1;
@@ -9214,7 +9214,8 @@ udf_expr:
parse it out. If we hijack the input stream with
remember_name we may get quoted or escaped names.
*/
else if ($2->type() != Item::FIELD_ITEM)
else if ($2->type() != Item::FIELD_ITEM &&
$2->type() != Item::REF_ITEM /* For HAVING */ )
$2->set_name($1, (uint) ($3 - $1), thd->charset());
$$= $2;
}

0 comments on commit 86f46a3

Please sign in to comment.
You can’t perform that action at this time.