Bug #45774 | Selecting the data, ordered by the field, containing the same value in all rows | ||
---|---|---|---|
Submitted: | 26 Jun 2009 6:38 | Modified: | 2 Jul 2009 9:46 |
Reporter: | Sergei Fundaev | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: Row Based Replication ( RBR ) | Severity: | S3 (Non-critical) |
Version: | 5.0.75, 4.1.22 | OS: | FreeBSD |
Assigned to: | CPU Architecture: | Any | |
Tags: | limit, order by, SELECT |
[26 Jun 2009 6:38]
Sergei Fundaev
[26 Jun 2009 6:54]
Valeriy Kravchuk
Sorry, but why do you expect any specific order of rows when you have the same value in all of them? The result will depend on storage engine (and optimizer plan!) used. I am sure your table is MyISAM. Check with InnoDB. Check EXPLAIN results for your selects. To summarize: this is NOT a bug.
[2 Jul 2009 9:46]
Sergei Fundaev
> Sorry, but why do you expect any specific order of rows when you have the same > value in all of them? In few, it is according to the architecture of the web-software. I.e. the situation, when the 'order_by' field contains the same value, is possible in our web-software, and in this case the problem, described above, occurs. > The result will depend on storage engine (and optimizer plan!) used. I am sure > your table is MyISAM. Check with InnoDB. Check EXPLAIN results for your > selects. Yes, when InnoDB is used, the problem doesn't exist. The 'EXPLAIN' results are presented here: MyISAM ---------- mysql> EXPLAIN SELECT field_id, order_by FROM test ORDER BY order_by LIMIT 130,8; +----+-------------+-------+------+---------------+------+---------+------+------+----------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+------+----------------+ | 1 | SIMPLE | test | ALL | NULL | NULL | NULL | NULL | 138 | Using filesort | +----+-------------+-------+------+---------------+------+---------+------+------+----------------+ 1 row in set (0.00 sec) InnoDB ---------- mysql> EXPLAIN SELECT field_id, order_by FROM test ORDER BY order_by LIMIT 130,8; +----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+ | 1 | SIMPLE | test2 | index | NULL | order_by | 4 | NULL | 138 | Using index | +----+-------------+-------+-------+---------------+----------+---------+------+------+-------------+ 1 row in set (0.02 sec) On the one hand I understand, that it is strange and may be incorrect when the field, used to order the selection result, contains the same value for all rows. But on the other hand, why does MySQL return the duplicated result in this case? I think it would be more logically, if in the described case MySQL returns the same result as if the 'ORDER BY' statement is not used at all. Do you agree?