Skip to content

MDEV-39440: replay context throwed a warning for a query after altering an index#5064

Open
bsrikanth-mariadb wants to merge 1 commit into
bb-12.3-MDEV-39368-test-replayfrom
13.0-MDEV-39440-stats-matching-failed-from-replay-context
Open

MDEV-39440: replay context throwed a warning for a query after altering an index#5064
bsrikanth-mariadb wants to merge 1 commit into
bb-12.3-MDEV-39368-test-replayfrom
13.0-MDEV-39440-stats-matching-failed-from-replay-context

Conversation

@bsrikanth-mariadb
Copy link
Copy Markdown
Contributor

The problem is that handler->multi_range_read_info_const() call in check_quick_select() returned rows equal to HA_POS_ERROR, both during context capture and replay. However, we never stored the ranges info into the context when rows=HA_POS_ERROR. However, during replay, we try to infuse stats for the given range, and since no match was found in the context, we produced a warning.

Solution is to store range_info for all the ranges even when they get HA_POS_ERROR number of rows.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a regression test for MDEV-39440 and modifies sql/opt_range.cc to move the optimizer context recording logic. A review comment correctly identifies that this change could lead to the use of uninitialized max_index_blocks and max_row_blocks variables when the row count is invalid, suggesting they be initialized to zero to prevent recording garbage data.

Comment thread sql/opt_range.cc
ha_rows replay_ctx_max_index_blocks;
ha_rows replay_ctx_max_row_blocks;
bool replay_ctx_rc;
TABLE::OPT_RANGE *range= param->table->opt_range + keynr;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The range->max_index_blocks and range->max_row_blocks fields are only assigned values when rows != HA_POS_ERROR (lines 12557-12561 in the original code). Since the recording logic has been moved outside of this conditional block (lines 12591-12597), these fields will contain uninitialized values when rows == HA_POS_ERROR, which are then passed to rec->record_multi_range_read_info_const. These should be initialized to a safe default value (e.g., 0) to avoid recording garbage data and potential undefined behavior.

  TABLE::OPT_RANGE *range= param->table->opt_range + keynr;
  range->max_index_blocks= range->max_row_blocks= 0;

@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 13.0-MDEV-39440-stats-matching-failed-from-replay-context branch 2 times, most recently from 7b8dcc0 to 58cc38e Compare May 11, 2026 15:19
…ng an index

The problem is that handler->multi_range_read_info_const() call in
check_quick_select() returned rows equal to HA_POS_ERROR, both during
context capture and replay. However, we never stored the ranges info
into the context when rows=HA_POS_ERROR. However, during replay, we try
to infuse stats for the given range, and since no match was found in the
context, we produced a warning.

Solution is to store range_info for all the ranges even when they get
HA_POS_ERROR number of rows.
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 13.0-MDEV-39440-stats-matching-failed-from-replay-context branch from 58cc38e to a745b59 Compare May 12, 2026 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

1 participant