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

Wrong result for SELECT..WHERE COLLATION(a)='binary' AND a='a'

Details

    Description

      In this script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARBINARY(10));
      INSERT INTO t1 VALUES ('a');
      SELECT * FROM t1 WHERE COLLATION(a)='binary';
      SELECT * FROM t1 WHERE a='a'; 

      the two SELECT queries return one row.

      Now if I join both conditions using AND in the same query:

      SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a';

      It returns empty set.

      A similar script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARBINARY(10));
      INSERT INTO t1 VALUES ('a');
      SELECT * FROM t1 WHERE CHARSET(a)='binary';
      SELECT * FROM t1 WHERE a='a'; 
      SELECT * FROM t1 WHERE CHARSET(a)='binary' AND a='a';

      A similar script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARBINARY(10));
      INSERT INTO t1 VALUES ('a');
      SELECT * FROM t1 WHERE COERCIBILITY(a)=2;
      SELECT * FROM t1 WHERE a='a'; 
      SELECT * FROM t1 WHERE COERCIBILITY(a)=2 AND a='a';

      A similar script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (a VARBINARY(10));
      INSERT INTO t1 VALUES ('a');
      SELECT * FROM t1 WHERE WEIGHT_STRING(a)='a';
      SELECT * FROM t1 WHERE a='a'; 
      SELECT * FROM t1 WHERE WEIGHT_STRING(a)='a' AND a='a';

      Attachments

        Issue Links

          Activity

            After the fix

            EXPLAIN EXTENDED SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a';
            SHOW WARNINGS;

            returns

            +-------+------+------------------------------------------------------------------------------+
            | Level | Code | Message                                                                      |
            +-------+------+------------------------------------------------------------------------------+
            | Note  | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'a') |
            +-------+------+------------------------------------------------------------------------------+

            MySQL-5.7.8 does not support propagation in the same query:

            +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
            | Level   | Code | Message                                                                                                                                   |
            +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
            | Note    | 1003 | /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (collation(`test`.`t1`.`a`) = 'binary')) |
            +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+

            bar Alexander Barkov added a comment - After the fix EXPLAIN EXTENDED SELECT * FROM t1 WHERE COLLATION(a)='binary' AND a='a'; SHOW WARNINGS; returns +-------+------+------------------------------------------------------------------------------+ | Level | Code | Message | +-------+------+------------------------------------------------------------------------------+ | Note | 1003 | select `test`.`t1`.`a` AS `a` from `test`.`t1` where (`test`.`t1`.`a` = 'a') | +-------+------+------------------------------------------------------------------------------+ MySQL-5.7.8 does not support propagation in the same query: +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+ | Level | Code | Message | +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+ | Note | 1003 | /* select#1 */ select `test`.`t1`.`a` AS `a` from `test`.`t1` where ((`test`.`t1`.`a` = 'a') and (collation(`test`.`t1`.`a`) = 'binary')) | +---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+

            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.