[MDEV-8705] Wrong result for SELECT..WHERE latin1_bin_column='a' AND latin1_bin_column='A' Created: 2015-08-30  Updated: 2015-09-12  Resolved: 2015-09-11

Status: Closed
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 10.1.8

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: propagation, upstream

Issue Links:
Blocks
blocks MDEV-8728 Fix a number of problems in equal fie... Closed
Duplicate
is duplicated by MDEV-8712 Wrong result for SELECT..WHERE latin1... Closed

 Description   

This script:

SET NAMES latin1;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
INSERT INTO t1 VALUES ('a'),('A');
SELECT * FROM t1 WHERE a='a' AND a='A';

erroneously returns one row:

+------+
| a    |
+------+
| a    |
+------+

The expected result is empty set.

If I change the order in WHERE:

SELECT * FROM t1 WHERE a='A' AND a='a';

it erroneously returns one row again, but a different row:

+------+
| a    |
+------+
| A    |
+------+

The problem happens in Item_equal::add_const(). It does not take into account collation of the field and compares the two string literals using the current session collation, which is latin1_swedish_ci.

A related problem:

SET NAMES utf8 COLLATE utf8_german2_ci;
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(10) CHARACTER SET utf8 COLLATE utf8_bin);
INSERT INTO t1 VALUES ('a');
SELECT * FROM t1 WHERE a='a';
SELECT * FROM t1 WHERE a=_utf8'a';
SELECT * FROM t1 WHERE a='a' AND a=_utf8'a';

The first and the second SELECT queries correctly return one row.
The third query returns error:

ERROR 1267 (HY000): Illegal mix of collations (utf8_general_ci,COERCIBLE) and (utf8_german2_ci,COERCIBLE) for operation '='

It should return one row.


Generated at Thu Feb 08 07:29:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.