Skip to content

Commit

Permalink
MDEV-33318 ORDER BY COLLATE improperly applied to non-character columns
Browse files Browse the repository at this point in the history
when changing charset from latin1 to utf8, adjust max_length accordingly
  • Loading branch information
vuvova committed Mar 13, 2024
1 parent 67abdb9 commit 7828aad
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
24 changes: 24 additions & 0 deletions mysql-test/main/ctype_collate.result
Original file line number Diff line number Diff line change
Expand Up @@ -772,3 +772,27 @@ string
#
# End of 10.2 tests
#
#
# MDEV-33318 ORDER BY COLLATE improperly applied to non-character columns
#
set names utf8;
create table t1 (ts datetime);
insert t1 values ('2024-01-26 21:37:54'), ('2024-01-26 21:37:54'),
('2024-01-26 21:37:54'), ('2024-01-26 21:37:54'),
('2024-01-26 21:37:58'), ('2024-01-26 21:37:58'),
('2024-01-26 21:37:58'), ('2024-01-26 21:38:02'),
('2024-01-26 21:38:02'), ('2024-01-26 21:38:02');
select * from t1 order by ts collate utf8_bin;
ts
2024-01-26 21:37:54
2024-01-26 21:37:54
2024-01-26 21:37:54
2024-01-26 21:37:54
2024-01-26 21:37:58
2024-01-26 21:37:58
2024-01-26 21:37:58
2024-01-26 21:38:02
2024-01-26 21:38:02
2024-01-26 21:38:02
drop table t1;
# End of 10.6 tests
15 changes: 15 additions & 0 deletions mysql-test/main/ctype_collate.test
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,18 @@ SELECT COLUMN_GET(COLUMN_CREATE(0, 'string'),0 AS CHAR CHARACTER SET latin1 COLL
--echo #
--echo # End of 10.2 tests
--echo #

--echo #
--echo # MDEV-33318 ORDER BY COLLATE improperly applied to non-character columns
--echo #
set names utf8;
create table t1 (ts datetime);
insert t1 values ('2024-01-26 21:37:54'), ('2024-01-26 21:37:54'),
('2024-01-26 21:37:54'), ('2024-01-26 21:37:54'),
('2024-01-26 21:37:58'), ('2024-01-26 21:37:58'),
('2024-01-26 21:37:58'), ('2024-01-26 21:38:02'),
('2024-01-26 21:38:02'), ('2024-01-26 21:38:02');
select * from t1 order by ts collate utf8_bin;
drop table t1;

--echo # End of 10.6 tests
4 changes: 3 additions & 1 deletion sql/item_strfunc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3590,7 +3590,9 @@ bool Item_func_set_collation::fix_length_and_dec()
}
collation.set(m_set_collation, DERIVATION_EXPLICIT,
args[0]->collation.repertoire);
max_length= args[0]->max_length;
ulonglong max_char_length= (ulonglong) args[0]->max_char_length();
fix_char_length_ulonglong(max_char_length * collation.collation->mbmaxlen);

return FALSE;
}

Expand Down

0 comments on commit 7828aad

Please sign in to comment.