Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-8222

"string_field LIKE int_const" returns a wrong result in case of UCS2

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.1, 10.0, 5.5
    • Fix Version/s: 10.1.5
    • Component/s: Character Sets
    • 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.

        Gliffy Diagrams

          Attachments

            Activity

            There are no comments yet on this issue.

              People

              • Assignee:
                bar Alexander Barkov
                Reporter:
                bar Alexander Barkov
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: