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

Wrong result for SELECT..WHERE a NOT LIKE 'a ' AND a='a'

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 10.1.6, 10.0, 5.5
    • Fix Version/s: 10.1.7
    • Component/s: Optimizer
    • Labels:
      None

      Description

      This script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARCHAR(10) COLLATE latin1_bin);
      INSERT INTO t1 VALUES ('a'),('a ');
      SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ';
      

      returns one row:

      +------+-----------+
      | a    | LENGTH(a) |
      +------+-----------+
      | a    |         1 |
      +------+-----------+
      

      Now if I make the condition even stronger:

      SELECT a, LENGTH(a) FROM t1 WHERE a NOT LIKE 'a ' AND a='a';
      

      it erroneously returns 2 rows:

      +------+-----------+
      | a    | LENGTH(a) |
      +------+-----------+
      | a    |         1 |
      | a    |         2 |
      +------+-----------+
      

      The problem happens in equal fields propagation.

      WHERE a NOT LIKE 'a ' AND a='a'
      

      gets rewritten to

      WHERE 'a' NOT LIKE 'a ' AND a='a'
      

      then LIKE gets removed from the condition.

        Gliffy Diagrams

          Attachments

            Issue Links

              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:
                  1 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: