Skip to content

MDEV-19574 innodb_stats_method is not honored when innodb_stats_persistent=ON #4204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 10.11
Choose a base branch
from

Conversation

Thirunarayanan
Copy link
Member

  • The Jira issue number for this PR is: MDEV-19574

Description

Problem:

InnoDB persistent statistics doesn't take innodb_stats_method
variable while calculating n_diff_pfx for the n-prefix index columns.

Solution:

While calculating the persistent statistics, InnoDB consider all NULLS as different value when innodb_stats_method is set to NULLS_UNEQUAL or NULLS_IGNORED. InnoDB statistics depends on the value of "innodb_stats_method" variable when the statistics were last recalculated.

dict_stats_analyze_index_level(),
dict_stats_scan_page(),
dict_stats_analyze_index_below_cur(),
dict_stats_analyze_index_for_n_prefix(): All function accepts the parameter to indicate the innodb_stats_method. It also calculates the number of non-null key value for each level or leaf page

dict_stats_index_set_n_diff(): calculates the number of non-null values similar to number of different key values.

Append the innodb_stats_method variable name for n_diff_pfx statistics description in mysql.innodb_index_stats.

Release Notes

InnoDB persisent statistics is stored in mysql.innodb_index_stats based on innodb_stats_method variable

How can this PR be tested?

./mtr innodb.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 main branch.
  • 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

  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.
  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.

@CLAassistant
Copy link

CLA assistant check
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.

@grooverdan
Copy link
Member

msan failure is MDEV-28165

@Thirunarayanan Thirunarayanan force-pushed the 10.11-MDEV-19574 branch 4 times, most recently from a1aa0d8 to ab6c670 Compare July 18, 2025 11:21
Comment on lines +4 to +7
CREATE TABLE t1(f1 INT NOT NULL, f2 INT NOT NULL,
f3 INT, KEY(f1, f3), key(f3)) STATS_PERSISTENT=1,ENGINE=INNODB;
INSERT INTO t1 SELECT seq, seq, NULL from seq_1_to_16384;
ANALYZE TABLE t1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we cover this for the maximum number of index columns, similar to how 464055f extended the test innodb.purge? I think that the maximum would be with a 32-column PRIMARY KEY and a 32-column non-unique secondary index.

Comment on lines 2145 to 2152
dict_stats_analyze_index_for_n_prefix(
dict_index_t* index,
ulint n_prefix,
bool nulls_unequal,
bool calc_non_null,
const boundaries_t* boundaries,
n_diff_data_t* n_diff_data,
mtr_t* mtr)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we pass fewer parameters here? Could IndexScanStatistics or something similar be used here as well?

Comment on lines 1930 to +1938
static
void
dict_stats_analyze_index_below_cur(
const btr_cur_t* cur,
ulint n_prefix,
bool nulls_unequal,
ib_uint64_t* n_diff,
ib_uint64_t* n_external_pages)
ib_uint64_t* n_external_pages,
ib_uint64_t* n_non_null)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we pass fewer parameters here? Can IndexScanStatistics or something similar be used here?

…stent=ON

Problem:
=======
 InnoDB persistent statistics doesn't take innodb_stats_method
variable while calculating n_diff_pfx for the n-prefix index
columns.

Solution:
=========
While calculating the persistent statistics, InnoDB consider all
NULLS as different value when innodb_stats_method is
set to NULLS_UNEQUAL or NULLS_IGNORED. InnoDB statistics depends
on the value of "innodb_stats_method" variable when the
statistics were last recalculated.

dict_stats_analyze_index_level(),
dict_stats_scan_page(),
dict_stats_analyze_index_below_cur(),
dict_stats_analyze_index_for_n_prefix(): All function accepts
the parameter to indicate the innodb_stats_method. It also
calculates the number of non-null key value for each level or leaf page

dict_stats_index_set_n_diff(): calculates the number of non-null
values similar to number of different key values.

Append the non-default innodb_stats_method variable name
for n_diff_pfx statistics description in mysql.innodb_index_stats.

IndexScanStatistics: Structure to store the various statistical
metric gathered during index scan fetch operation. This structure
is being used in dict_stats_analyze_index_level() to fetch the
statistics
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.

4 participants