We're trying to figure out the best way to determine a key field's
non-padded length in records_in_range().
Our storage engine (IBM DB2) stores key values in a format that is
different from MySQL's. One consequence of this is that we need to be able
to determine in handler::records_in_range() the true length of a padded
character field in a key. An example of a query which generates a padded
character field in the key would be: select * from t1 where keyA like
"ABC%". For this query, we need to be able to know in records_in_range()
that there are exactly 3 characters in the key describing the lower bound.
As far as I can tell, this information is not available explicitly in any
data structure available to records_in_range().
Therefore, we need to analyze the key field data to determine the length.
This appears simple for single-byte or double-byte character sets, because
we can use a function like memchr() to search for the first occurrence of
the CHARSET_INFO::min_sort_char in the field. This is what we are
currently doing. However, from looking at the various my_like_range_*
functions in ./strings/ it appears that this strategy cannot be applied to
multi-byte character sets, such as cp932 or utf8. In fact, it looks like
we almost have to reverse-engineer each implementation of my_like_range to
produce a complementary function that can determine when padding starts.
Obviously, we would prefer a solution that is more maintainable and more
easily implemented. Do we have any options?