According to our performance investigations, these functions are hot when we
use utf8 collation:
Since the commit https://github.com/mysql/mysql-server/commit/67ce24796584
from 2004 skipping trailing spaces in my_hash_sort_utf8 has been implemented
via naive chopping spaces one after another from the end of the string:
We know that for CHAR(XXX) utf8 fields all unused space is filled with spaces.
So, using brand new skip_trailing_space for my_hash_sort_utf8 function
significantly increase performance here. See for a reference:
The performance increase achives by skipping not 1 but 8 spaces for every
For my_strnncollsp_utf8 function these approach can't be applied as is.
However, we proved, than aggressive forward space skipping still improves
performance with no degradation in all other cases. Following this idea,
we introduce additional function for forward space skipping:
After that every time when we run into two simultaneous spaces while comparing
two strings in my_strnncollsp_utf8 function, we invoke skip_space instead of
slow utf8 processing code:
Using this simple approach we achived significant performance improvement in
the case when two strings are equal (more than 7 times faster for CHAR(120)).
If we speak about general database performance, we improve single-threaded
sysbench OLTP RO by up to 2.5%.
1. For my_hash_sort_utf8(mb4) - use skip_trailing_space as is.
2. For my_strnncollsp_utf8(mb4) - use aggressive forward space skipping right
in the main loop which processes utf8 characters one by one.