Skip to content

Commit

Permalink
MDEV-9886 Illegal mix of collations with a view comparing a field to …
Browse files Browse the repository at this point in the history
…a binary constant
  • Loading branch information
Alexander Barkov committed Oct 7, 2017
1 parent dbeffab commit ca948e3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
18 changes: 18 additions & 0 deletions mysql-test/r/ctype_gbk.result
Original file line number Diff line number Diff line change
Expand Up @@ -4944,5 +4944,23 @@ E05B
DROP TABLE t1;
# Start of ctype_E05C.inc
#
# MDEV-9886 Illegal mix of collations with a view comparing a field to a binary constant
#
SET NAMES latin1;
CREATE TABLE t1 (a TEXT CHARACTER SET gbk);
INSERT INTO t1 VALUES (0xEE5D);
SELECT a<>0xEE5D AS a FROM t1;
a
0
CREATE VIEW v1 AS SELECT a<>0xEE5D AS a FROM t1;
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (`t1`.`a` <> 0xee5d) AS `a` from `t1` latin1 latin1_swedish_ci
SELECT * FROM v1;
a
0
DROP VIEW v1;
DROP TABLE t1;
#
# End of 10.0 tests
#
18 changes: 18 additions & 0 deletions mysql-test/r/ctype_latin1.result
Original file line number Diff line number Diff line change
Expand Up @@ -7922,5 +7922,23 @@ SELECT _latin1 0x7E, _latin1 X'7E', _latin1 B'01111110';
_latin1 0x7E _latin1 X'7E' _latin1 B'01111110'
~ ~ ~
#
# MDEV-9886 Illegal mix of collations with a view comparing a field to a binary constant
#
SET NAMES latin1;
CREATE TABLE t1 (a TEXT CHARACTER SET latin1);
INSERT INTO t1 VALUES (0xC0);
SELECT a<>0xEE5D AS a FROM t1;
a
1
CREATE VIEW v1 AS SELECT a<>0xC0 AS a FROM t1;
SHOW CREATE VIEW v1;
View Create View character_set_client collation_connection
v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (`t1`.`a` <> 0xc0) AS `a` from `t1` latin1 latin1_swedish_ci
SELECT * FROM v1;
a
0
DROP VIEW v1;
DROP TABLE t1;
#
# End of 10.0 tests
#
14 changes: 14 additions & 0 deletions mysql-test/t/ctype_gbk.test
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,20 @@ let $ctype_unescape_combinations=selected;
SET NAMES gbk;
--source include/ctype_E05C.inc

--echo #
--echo # MDEV-9886 Illegal mix of collations with a view comparing a field to a binary constant
--echo #

SET NAMES latin1;
CREATE TABLE t1 (a TEXT CHARACTER SET gbk);
INSERT INTO t1 VALUES (0xEE5D);
SELECT a<>0xEE5D AS a FROM t1;
CREATE VIEW v1 AS SELECT a<>0xEE5D AS a FROM t1;
SHOW CREATE VIEW v1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;


--echo #
--echo # End of 10.0 tests
Expand Down
16 changes: 16 additions & 0 deletions mysql-test/t/ctype_latin1.test
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,22 @@ DROP TABLE t1;
--echo #
SELECT _latin1 0x7E, _latin1 X'7E', _latin1 B'01111110';


--echo #
--echo # MDEV-9886 Illegal mix of collations with a view comparing a field to a binary constant
--echo #

SET NAMES latin1;
CREATE TABLE t1 (a TEXT CHARACTER SET latin1);
INSERT INTO t1 VALUES (0xC0);
SELECT a<>0xEE5D AS a FROM t1;
CREATE VIEW v1 AS SELECT a<>0xC0 AS a FROM t1;
SHOW CREATE VIEW v1;
SELECT * FROM v1;
DROP VIEW v1;
DROP TABLE t1;


--echo #
--echo # End of 10.0 tests
--echo #
4 changes: 3 additions & 1 deletion sql/item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,9 @@ bool agg_item_collations_for_comparison(DTCollation &c, const char *fname,
bool agg_item_set_converter(DTCollation &coll, const char *fname,
Item **args, uint nargs, uint flags, int item_sep)
{
THD *thd= current_thd;
if (thd->lex->is_ps_or_view_context_analysis())
return false;
Item **arg, *safe_args[2]= {NULL, NULL};

/*
Expand All @@ -2177,7 +2180,6 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname,
safe_args[1]= args[item_sep];
}

THD *thd= current_thd;
bool res= FALSE;
uint i;

Expand Down

0 comments on commit ca948e3

Please sign in to comment.