server
server copied to clipboard
MDEV-19574 innodb_stats_method is not honored when innodb_stats_persistent=ON
- [x] The Jira issue number for this PR is: MDEV-19574
Description
MDEV-19574: innodb_stats_method ignored with persistent statistics
Problem:
When persistent statistics are enabled (innodb_stats_persistent=ON), the innodb_stats_method setting was not being properly passed through the statistics calculation chain. This caused NULL handling to always use the default behavior, regardless of the configured stats method.
The issue affected query optimization for queries involving NULL values, as the statistics collection wasn't respecting the user's preference for NULL value treatment (NULLS_EQUAL, NULLS_UNEQUAL, or NULLS_IGNORED).
Solution:
-
Passed innodb_stats_method parameter through the statistics calculation chain:
- dict_stats_scan_page()
- dict_stats_analyze_index_below_cur()
- dict_stats_analyze_index_for_n_prefix()
- dict_stats_analyze_index_level
- dict_stats_analyze_index
- dict_stats_update_persistent
- dict_stats_save
-
Conditionally set n_non_null_key_vals based on the NULLS_IGNORED method.
-
Introduced IndexLevelStats which is to collect statistics at a specific B-tree level during index analysis
-
Introduced LeafPageStats which is to collect statistics for leaf page analysis
-
IndexLevelStats, LeafPageStats replaces multiple individual parameters in function signatures.
-
Add stats method name to stat_description in case of non default innodb_stats_method variable value
-
When InnoDB scan the leaf page directly, assign leaf page count as number of pages scanned in case of multi-level index. For single page indexes, use 1. This change leads to multiple changes in existing test case.
Release Notes
Fixed innodb_stats_method being ignored when innodb_stats_persistent=ON, causing
incorrect cardinality estimates for indexes with NULL values. Now it gives more accurate
cardinality estimates for NULL-containing indexes for all three stats method.
How can this PR be tested?
./mtr innodb.stats_method
Basing the PR against the correct MariaDB version
- [ ] This is a new feature or a refactoring, and the PR is based against the
mainbranch. - [x] This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.
PR quality check
- [x] I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
- [x] For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.
msan failure is MDEV-28165