It seems that when Im uses the order by name
operator, where name
is of type varchar(255)
, MySQL on my server does not put the records in the correct order if they have the same 20 first characters of the name
field. MySQL doesn't seem to care about the 21st character at all: it actually keeps the same wrong order when sorting in descending order.
I repeated my table on another MySQL installation, and everything is fine there. But what should I do with this restriction on the server? I cannot reinstall MySQL there because I use shared hosting.
Update : the name
field does not belong to any index, and creating an index in this field also does not help.
MySQL version is 5.1.55, the engine is MyISAM.
Update 2 . I originally used cp1251_general_ci
sort, but then I tried other sortings and got the same result. For strings, I used '123456789012345678901'/'123456789012345678902'
and 'abcdefghijklmnopqrstauvwxyz'/'abcdefghijklmnopqrstbuvwxyz'
, the same result.
The order, apparently, does not take into account all the characters starting from the 21st, but otherwise it works as it should.
Interestingly, when using ORDER BY substring ( name
, 2)
, the 21st character is significant, and the 22nd is not.
source share