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

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

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Fixed
    • 10.1.6, 5.5, 10.0
    • 10.1.7
    • Optimizer
    • 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.

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.