Bug #3482 MySQL returns empty set when using index
Submitted: 16 Apr 2004 1:59 Modified: 28 Apr 2004 10:47
Reporter: Christian Roche Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S1 (Critical)
Version:4.1.1a-alpha OS:Microsoft Windows (Windows NT 4.0 SP6a)
Assigned to: CPU Architecture:Any

[16 Apr 2004 1:59] Christian Roche
Description:
A simple SELECT statement that uses an index returns a number of rows when placed without GROUP BY statement and an empty set when placed with a GROUP BY statement.

This bug was noticed on 4.1.1a-alpha-nt, although people on the win32 mailing list confirmed it on 4.1.2 also.

How to repeat:
CREATE TABLE test (
  idate date NOT NULL default '0000-00-00',
  country varchar(15) NOT NULL default '',
  block varchar(15) NOT NULL default '',
  carrier varchar(4) NOT NULL default '',
  PRIMARY KEY  (block,idate,carrier),
  KEY COUNTRY (country,idate,carrier)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO test VALUES ('2004-01-01','GBRMORA','447890','BELG'),('2004-01-01','GBRMORA','447890','CWLS'),('2004-01-01','GBRMORA','447890','FTLD'),('2004-01-02','GBRMORA','447890','CWLS'),('2004-01-03','GBRMORA','447890','CWLS'),('2004-01-04','GBRMORA','447890','CWLS'),('2004-01-05','GBRMORA','447890','CWLS'),('2004-01-06','GBRMORA','447890','CWLS'),('2004-01-07','GBRMORA','447890','CWLS'),('2004-01-08','GBRMORA','447890','CWLS'),('2004-01-09','GBRMORA','447890','CWLS'),('2004-01-10','GBRMORA','447890','CWLS'),('2004-01-11','GBRMORA','447890','CWLS'),('2004-01-12','GBRMORA','447890','CWLS'),('2004-01-13','GBRMORA','447890','CWLS'),('2004-01-14','GBRMORA','447890','CWLS'),('2004-01-15','GBRMORA','447890','CWLS'),('2004-01-16','GBRMORA','447890','CWLS'),('2004-01-17','GBRMORA','447890','CWLS'),('2004-01-18','GBRMORA','447890','CWLS'),('2004-01-19','GBRMORA','447890','CWLS'),('2004-01-19','GBRMORA','447890','FTLD'),('2004-01-20','GBRMORA','447890','FTLD'),('2004-01-21','GBRMORA','447890','FTLD'),('2004-01-22','GBRMORA','447890','FTLD'),('2004-01-23','GBRMORA','447890','FTLD'),('2004-01-24','GBRMORA','447890','FTLD'),('2004-01-25','GBRMORA','447890','FTLD'),('2004-01-26','GBRMORA','447890','FTLD'),('2004-01-27','GBRMORA','447890','FTLD'),('2004-01-28','GBRMORA','447890','FTLD'),('2004-01-29','GBRMORA','447890','FTLD'),('2004-01-30','GBRMORA','447890','FTLD'),('2004-01-31','GBRMORA','447890','FTLD'),('2004-01-12','GBRMCEL','44850','CWLS'),('2004-01-17','GBRMCEL','44850','CWLS');

SELECT block FROM test WHERE idate between '2004-01-01' AND '2004-01-06'
AND country = 'GBRMORA';
-> returns 8 rows

SELECT block FROM test WHERE idate between '2004-01-01' AND '2004-01-06'
AND country = 'GBRMORA' GROUP BY block;
-> return empty set

Suggested fix:
Not a fix but a workaround: this bug is easily circumvented by using "country IN ('GBRMORA')" or "country LIKE 'GBRMORA'" instead of "country = 'GBRMORA'"
[28 Apr 2004 7:27] MySQL Verification Team
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

C:\servers\4.1.2\bin>mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.2-alpha-max

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> SELECT block, count(*) FROM test WHERE idate
    -> between '2004-01-01' AND '2004-01-06'
    -> AND country = 'GBRMORA' GROUP BY block;
+--------+----------+
| block  | count(*) |
+--------+----------+
| 447890 |        8 |
+--------+----------+
1 row in set (0.00 sec)