[Commits] 86f46a3d: MDEV-7301: Unknown column quoted with backticks in HAVING clause

Jan Lindström jan.lindstrom at mariadb.com
Mon Mar 23 09:50:05 EET 2015


revision-id: 86f46a3da4a6d82cb510dc4c270d46cfd6a8965b
parent(s): 9253064c0547b16b867565a05f8305780c2ecc34
committer: Jan Lindström
branch nick: 5.5-git
timestamp: 2015-03-23 09:49:32 +0200
message:

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 at oracle.com>.

---
 mysql-test/r/having.result | 31 +++++++++++++++++++++++++++++++
 mysql-test/t/having.test   | 34 ++++++++++++++++++++++++++++++++++
 sql/sql_yacc.yy            |  3 ++-
 3 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/having.result b/mysql-test/r/having.result
index 7ead7e3..514abbf 100644
--- a/mysql-test/r/having.result
+++ b/mysql-test/r/having.result
@@ -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;
diff --git a/mysql-test/t/having.test b/mysql-test/t/having.test
index a2bbfb8..505fb9a 100644
--- a/mysql-test/t/having.test
+++ b/mysql-test/t/having.test
@@ -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;
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 777cef5..257001c 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -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;
           }


More information about the commits mailing list