Skip to content

MDEV-39440: Failed to match the stats from replay context with the optimizer stats:#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: Failed to match the stats from replay context with the optimizer stats:#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 Outdated
@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 13.0-MDEV-39440-stats-matching-failed-from-replay-context branch 3 times, most recently from 58cc38e to a745b59 Compare May 12, 2026 02:44
@spetrunia
Copy link
Copy Markdown
Member

spetrunia commented May 18, 2026

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

"throwed"? Is "altering an index" required at all? Please change the commit message to be more descriptive.
(wait I will provide more input)

Comment thread sql/opt_range.cc Outdated
Comment thread sql/opt_range.cc
}
}

if (range && (rec= param->thd->opt_ctx_recorder))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you elaborate about the case where range==NULL. When does that happen?
Is it correct that we will not make a record in the optimizer context in that case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

range is now initialized to null. And if the rows is not HA_POS_ERROR, then it will never be null.

From all the tests that I ran it was never null though.

@bsrikanth-mariadb bsrikanth-mariadb force-pushed the 13.0-MDEV-39440-stats-matching-failed-from-replay-context branch from a745b59 to ab86775 Compare May 19, 2026 00:49
@bsrikanth-mariadb bsrikanth-mariadb changed the title MDEV-39440: replay context throwed a warning for a query after altering an index MDEV-39440: replay context stats mismatch for a query after altering an index May 19, 2026
@bsrikanth-mariadb bsrikanth-mariadb changed the title MDEV-39440: replay context stats mismatch for a query after altering an index MDEV-39440: Failed to match the stats from replay context with the optimizer stats: May 19, 2026
…timizer stats

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 ab86775 to 40514d9 Compare May 19, 2026 03:48
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.

2 participants