[MDEV-8222] "string_field LIKE int_const" returns a wrong result in case of UCS2 Created: 2015-05-25  Updated: 2015-06-09  Resolved: 2015-06-02

Status: Closed
Project: MariaDB Server
Component/s: Character Sets
Affects Version/s: 5.5, 10.0, 10.1
Fix Version/s: 10.1.5

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Alexander Barkov
Resolution: Fixed Votes: 0
Labels: None


 Description   

This script:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(10) CHARSET utf8);
INSERT INTO t1 VALUES ('1');
SELECT * FROM t1 WHERE a LIKE 1;

correctly returns one row:

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

If I change character set from utf8 to ucs2, it returns empty set:

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (a VARCHAR(10) CHARSET ucs2);
INSERT INTO t1 VALUES ('1');
SELECT * FROM t1 WHERE a LIKE 1;

The problem happens in this piece of the code:

bool Item_func::setup_args_and_comparator(THD *thd, Arg_comparator *cmp)
{
  DBUG_ASSERT(arg_count == 2);
 
  if (args[0]->cmp_type() == STRING_RESULT &&
      args[1]->cmp_type() == STRING_RESULT &&
      agg_arg_charsets_for_comparison(cmp->cmp_collation, args, 2))
      return true;

In case of LIKE it should unconditionally call arg_arg_charsets_for_comparison(), no matter that cmp_type() of the arguments are.


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