Bug #1992 Strange behaviour with DISTINCT, SUBQUERY and LIMIT
Submitted: 1 Dec 2003 13:35 Modified: 4 Mar 2004 6:25
Reporter: jocelyn fournier (Silver Quality Contributor) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:MySQL 4.1.1 OS:Linux (Linux)
Assigned to: Alexey Botchkov CPU Architecture:Any

[1 Dec 2003 13:35] jocelyn fournier
Description:
Hi,

When using combination of DISTINCT, SUBQUERY and LIMIT, MySQL returns some strange results.

Thanks,
  Jocelyn

How to repeat:
CREATE TABLE test (a int(1));
INSERT INTO test VALUES (1),(1),(1),(1),(1),(2),(3),(4),(5);
SELECT (SELECT a) FROM test LIMIT 100;
+------------+
| (SELECT a) |
+------------+
|          1 |
|          1 |
|          1 |
|          1 |
|          1 |
|          2 |
|          3 |
|          4 |
|          5 |
+------------+

it's ok

SELECT DISTINCT (SELECT a) FROM test;
+------------+
| (SELECT a) |
+------------+
|          1 |
|          2 |
|          3 |
|          4 |
|          5 |
+------------+
5 rows in set (0.00 sec)

it's ok too

SELECT DISTINCT (SELECT a) FROM test LIMIT 100;
+------------+
| (SELECT a) |
+------------+
|          5 |
|          5 |
|          5 |
|          5 |
|          5 |
+------------+
5 rows in set (0.00 sec)

Bug ?

However

SELECT DISTINCT (SELECT a+0) FROM test LIMIT 100;
+--------------+
| (SELECT a+0) |
+--------------+
|            1 |
|            2 |
|            3 |
|            4 |
|            5 |
+--------------+
5 rows in set (0.00 sec)

is ok.
[1 Dec 2003 13:42] Dean Ellis
Verified against the latest BitKeeper sources.

Thank you.
[6 Dec 2003 10:36] Alexey Botchkov
Hi, Jocelyn!
proposed fix is here:

bk commit - 4.1 tree (hf:1.1657) (06 Dec 2003)
[4 Mar 2004 6:25] Alexey Botchkov
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