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

Wrong result for SELECT..WHERE derived_table_enum_column='number' AND derived_table_enum_column OP number2

    XMLWordPrintable

Details

    Description

      This was originally reported in MDEV-8747, but then moved into a separate bug report.

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a ENUM('5','6')) ENGINE=MyISAM;
      INSERT INTO t1 VALUES ('5'),('6');
      SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5';
      SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a=1;
      SELECT * FROM (SELECT * FROM t1) AS table1 WHERE a='5' AND a=1;

      The first and the second query correctly return one row, equal to '5'. The third query erroneously returns empty set.

      The same problem is also demonstrated in this script:

      DROP TABLE IF EXISTS t1;
      DROP VIEW IF EXISTS v1;
      CREATE TABLE t1 (a varchar(10) character set cp1251 collate cp1251_ukrainian_ci, KEY (a)) ;
      INSERT INTO t1 VALUES ('DD'), ('ZZ'), ('ZZ'), ('KK'), ('FF'), ('HH'),('MM'),('`1');
      CREATE VIEW v1 AS SELECT * FROM t1;
      SELECT * FROM t1 WHERE a <> 0 AND a = ' 1';
      SELECT * FROM v1 WHERE a <> 0 AND a = ' 1';

      The first SELECT returns empty set, the second SELECT returns one row.

      The same problem is repeatable in this script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a ENUM('5','6'));
      INSERT INTO t1 VALUES ('5'),('6');
      DROP VIEW IF EXISTS v1;
      CREATE VIEW v1 AS SELECT * FROM t1;
      SELECT * FROM t1 WHERE a='5' AND a<2;
      SELECT * FROM v1 WHERE a='5' AND a<2;

      The first SELECT correctly return one row, the second SELECT erroneously returns no rows.

      As in MDEV-8747, the problem happens because Item_direct_view_ref does not set real_item()->cmp_context properly. But unlike MDEV-8747 it also additionally needs fixes in Item_field::replace_equal_field, that also relies on cmp_context being set properly.

      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.