Skip to content

Conversation

srmppn
Copy link

@srmppn srmppn commented Oct 20, 2025

Description

This pull request fixes Bug#119198, which occurs when a reverse index range scan returns incorrect results.

During SQL query optimization, the used_key_parts may need to be extended — for example, when a query requires ordering by both a column and its primary key. However, the optimizer did not properly check for this condition, causing m_using_extended_key_parts in the reverse_index_range_scan to remain false. As a result, the logic incorrectly falls into the eqrange_all_keyparts section instead, leading to wrong results:

if (eqrange_all_keyparts) {
      result = table()->file->ha_index_read_map(
          table()->record[0], last_range->max_key, last_range->max_keypart_map,
          HA_READ_KEY_EXACT);
 } 

Proposed solution

Assign used_key_parts variable to retrieve possible extended key parts — similar to the approach used in test_if_skip_sort_order method. Additionally, I check for the maximum value using std::max to ensure we use extended key parts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant