Bug #1264 | Incorrect behaviour of ORDER BY using indexed (var)char columns in ucs2 tables | ||
---|---|---|---|
Submitted: | 12 Sep 2003 10:27 | Modified: | 16 Sep 2003 4:27 |
Reporter: | Simon Detheridge | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server | Severity: | S2 (Serious) |
Version: | 4.1.1alpha (source distribution) | OS: | Linux (linux (gentoo)) |
Assigned to: | Alexander Barkov | CPU Architecture: | Any |
[12 Sep 2003 10:27]
Simon Detheridge
[15 Sep 2003 5:56]
Simon Detheridge
Additional info: This bug does not affect all table types. I have tested it with MyISAM, ISAM, HEAP, and BDB, and they all display the buggy behaviour. However, InnoDB tables do not. They display the results in the correct order. Using InnoDB tables therefore seems a better workaround for now, than removing indexes on CHAR/VARCHAR columns.
[15 Sep 2003 10:33]
Indrek Siitan
It seems to be dependent on the number of columns displayed, not actually contained in the db: DROP TABLE foo ; CREATE TABLE foo ( word VARCHAR(64) , bar INT(11) default 0 , PRIMARY KEY ( word ) ) TYPE=MyISAM CHARSET ucs2 COLLATE ucs2_general_ci ; INSERT INTO foo ( word ) VALUES ( "aar" ) ; INSERT INTO foo ( word ) VALUES ( "a" ) ; INSERT INTO foo ( word ) VALUES ( "aardvar" ) ; INSERT INTO foo ( word ) VALUES ( "aardvark" ) ; INSERT INTO foo ( word ) VALUES ( "aardvara" ) ; INSERT INTO foo ( word ) VALUES ( "aardvarz" ) ; mysql> select * from foo order by word; +----------+------+ | word | bar | +----------+------+ | aardvara | 0 | | aardvark | 0 | | aardvarz | 0 | | aardvar | 0 | | aar | 0 | | a | 0 | +----------+------+ 6 rows in set (0.00 sec) mysql> select word from foo order by word; +----------+ | word | +----------+ | a | | aar | | aardvar | | aardvara | | aardvark | | aardvarz | +----------+ 6 rows in set (0.00 sec) According to EXPLAIN, it looks like when the output includes columns that are not part of the index sorted on, it does a filesort, which fails. Using a straight index yields correct results. mysql> explain select * from foo order by word \G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: foo type: ALL possible_keys: NULL key: NULL key_len: NULL ref: NULL rows: 6 Extra: Using filesort 1 row in set (0.00 sec) mysql> explain select word from foo order by word \G *************************** 1. row *************************** id: 1 select_type: SIMPLE table: foo type: index possible_keys: NULL key: PRIMARY key_len: 128 ref: NULL rows: 6 Extra: Using index 1 row in set (0.01 sec)
[16 Sep 2003 1:39]
Alexander Barkov
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at http://www.mysql.com/downloads/
[16 Sep 2003 4:27]
Alexander Barkov
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at http://www.mysql.com/downloads/ Ok, it's now really fixed. Test suit is also added.