Bug #117809 Statistics update failed.
Submitted: 27 Mar 2025 13:06 Modified: 27 Mar 2025 19:49
Reporter: yangyang wang Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S5 (Performance)
Version: OS:Any
Assigned to: CPU Architecture:Any

[27 Mar 2025 13:06] yangyang wang
Description:
For MySQL, when the number of tables is changed to more than 10%, statistics update is triggered and the table is sent to dict_stats_thread to update statistics. However, table objects in the memory are eliminated. If multiple tables are updated, statistics may fail to be updated for a long time.

void row_update_statistics_if_needed(dict_table_t *table) /*!< in: table */
{
  ib_uint64_t counter;
  ib_uint64_t n_rows;

  ...
  counter = table->stat_modified_counter++;
  n_rows = dict_table_get_n_rows(table);

  if (dict_stats_is_persistent_enabled(table)) {
    double recalc_pct = rds_recalc_persistent_stats_threshold_pct / 100;
    if (counter > (n_rows * recalc_pct) &&
        dict_stats_auto_recalc_is_enabled(table)) {
      dict_stats_recalc_pool_add(table);
      table->stat_modified_counter = 0;
    }
    return;
  }
The dict_table_t may be removed from the cache.

How to repeat:
1.create table
2.insert values
3.flush table
4.insert values
5.flush table
6.Check statistics.We can see that the statistics of the table are not updated.
[27 Mar 2025 19:49] MySQL Verification Team
Hi,
I believe this is not a bug but a design decision but I'll pass this back to optimizer team to confirm.
[2 Jun 10:05] Øystein Grøvlen
Posted by developer:
 
Update of statistics is the responsibility of the InnoDB engine.
[30 Jun 5:31] Mayank Prasad
Hi Yangyang Wang,

Thanks for filing the bug!

I need some help understanding the issue and the claim being made here.

> For MySQL, when the number of tables is changed to more than 10%, statistics update is triggered

This does not seem quite accurate to me. My understanding is that InnoDB triggers statistics recalculation for a table if more than 10% of the table rows have been modified, assuming persistent statistics and auto-recalc are enabled.

> However, table objects in the memory are eliminated. If multiple tables are updated, statistics may fail to be updated for a long time.

Could you clarify the exact failure scenario here? Is the concern that statistics recalculation for some tables may be delayed after the table objects are evicted from memory?

If so, could you please provide a reproducible test case, or preferably an MTR test, that demonstrates the delayed or missing statistics update?

Thanks.
-Mayank