Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 10.1, 10.0, 5.5
    • Fix Version/s: 10.1
    • Component/s: None
    • Labels:
      None

      Description

      This script:

      DROP TABLE IF EXISTS t1;
      CREATE TABLE t1 (id INT NOT NULL, a VARCHAR(20), KEY(id,a)) ENGINE=MyISAM;
      INSERT INTO t1 VALUES (1,'01');
      INSERT INTO t1 VALUES (1,'02');
      INSERT INTO t1 VALUES (1,'03');
      INSERT INTO t1 VALUES (1,'04');
      INSERT INTO t1 VALUES (2,'01'); 
      INSERT INTO t1 VALUES (2,'02'); 
      INSERT INTO t1 VALUES (2,'03'); 
      INSERT INTO t1 VALUES (2,'04');
      INSERT INTO t1 VALUES (3,'01'); 
      INSERT INTO t1 VALUES (3,'02'); 
      INSERT INTO t1 VALUES (3,'03'); 
      INSERT INTO t1 VALUES (3,'04');
      INSERT INTO t1 VALUES (4,'01'); 
      INSERT INTO t1 VALUES (4,'02'); 
      INSERT INTO t1 VALUES (4,'03'); 
      INSERT INTO t1 VALUES (4,'04');
      EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a BETWEEN '04' AND '05' GROUP BY id;
      

      returns

      +------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
      | id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                                 |
      +------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
      |    1 | SIMPLE      | t1    | range | NULL          | id   | 27      | NULL |    9 | Using where; Using index for group-by |
      +------+-------------+-------+-------+---------------+------+---------+------+------+---------------------------------------+
      

      If I used LIKE instead of BETWEEN with the same table:

      EXPLAIN SELECT id,MIN(a),MAX(a) FROM t1 WHERE a LIKE '04%' GROUP BY id;
      

      group-min-max is not applied:

      +------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
      | id   | select_type | table | type  | possible_keys | key  | key_len | ref  | rows | Extra                    |
      +------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
      |    1 | SIMPLE      | t1    | index | NULL          | id   | 27      | NULL |   16 | Using where; Using index |
      +------+-------------+-------+-------+---------------+------+---------+------+------+--------------------------+
      

      Group-min-max could safely be applied.

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

                Dates

                • Created:
                  Updated: