Skip to content

Commit 429c5b1

Browse files
committed
MDEV-35049 fixup: Avoid useless rebuild if cmp=0
btr_search_info_update_hash(): Avoid useless rebuild if cmp==0. Consider index(col) on a VARCHAR column for which we have the values col='prefix1' and col='prefix2'. In WHERE col LIKE 'prefix%', page_cur_search_with_match_bytes() would return 0 as well as 0 matched fields and bytes on each side. It turns out that page_cur_search_with_match_bytes() can only return nonzero matched bytes when a binary comparison can be used, such as with VARBINARY or INT columns. Co-developed by: Alessandro Vetere
1 parent 83a48d2 commit 429c5b1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

storage/innobase/btr/btr0sea.cc

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,15 @@ static uint32_t btr_search_info_update_hash(const btr_cur_t &cursor) noexcept
562562
static_assert(buf_block_t::LEFT_SIDE == 1U << 31, "");
563563
left_bytes_fields= (cmp >= 0) << 31;
564564

565-
if (left_bytes_fields)
565+
if (cmp == 0)
566+
/* Reset to the default case (a single index field).
567+
Without this special handling, we could end up setting totally
568+
useless parameters buf_block_t::LEFT_SIDE | 1 << 16 below
569+
(rebuilding the adaptive hash index on a 1-byte prefix)
570+
for example when page_cur_search_with_match_bytes() finds matches
571+
of LIKE 'a%' in the first index field. */
572+
left_bytes_fields|= 1;
573+
else if (left_bytes_fields)
566574
{
567575
if (cursor.up_match >= n_uniq)
568576
left_bytes_fields|= n_uniq;

0 commit comments

Comments
 (0)