Skip to content

Fix MariaDB query cache efficiency underreporting#928

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-mariadb-query-cache-efficiency
Draft

Fix MariaDB query cache efficiency underreporting#928
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-mariadb-query-cache-efficiency

Conversation

Copilot AI commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

On MariaDB, Com_select already includes Qcache_hits (verified: Qcache_hits + Qcache_inserts + Qcache_not_cached ≈ Com_select). The old MySQL formula Qcache_hits / (Com_select + Qcache_hits) double-counts hits in the denominator, producing ~45% where the real hit ratio is ~84%.

Changes

  • calculations(): Use Qcache_hits / Com_select for MariaDB; keep Qcache_hits / (Com_select + Qcache_hits) for MySQL. Uses the existing $is_mariadb local variable (computed before the function strips the -MariaDB suffix from $myvar{'version'}). Stores result in $mycalc{'is_mariadb'} for downstream use.

  • mysql_stats(): Use $mycalc{'is_mariadb'} to display the correct denominator (Com_select vs Com_select + Qcache_hits).

  • tests/issue_927.t: New test asserting the MariaDB formula yields ~84.4% and the MySQL formula is unchanged for non-MariaDB versions.

# MariaDB (Com_select already includes hits)
$mycalc{'query_cache_efficiency'} = sprintf("%.1f",
    ($mystat{'Qcache_hits'} / $mystat{'Com_select'}) * 100
);

# MySQL (hits not counted in Com_select)
$mycalc{'query_cache_efficiency'} = sprintf("%.1f",
    ($mystat{'Qcache_hits'} / ($mystat{'Com_select'} + $mystat{'Qcache_hits'})) * 100
);

Note: The version-stripping gotcha — calculations() runs $myvar{'version'} =~ s/(.+)-.*?$/$1/ before reaching the query cache block, so $myvar{'version'} =~ /mariadb/i would silently fail there. The fix uses $is_mariadb set prior to the strip.

On MariaDB, Com_select already includes Qcache_hits, so the correct
efficiency formula is Qcache_hits / Com_select rather than the MySQL
formula Qcache_hits / (Com_select + Qcache_hits).

- In calculations(): use the already-computed $is_mariadb variable
  (detected before the version string is stripped) and store it in
  $mycalc{'is_mariadb'} for downstream use
- In mysql_stats(): use $mycalc{'is_mariadb'} to select the correct
  denominator in the display string
- Add tests/issue_927.t to verify both the MariaDB and MySQL formulas
Copilot AI changed the title [WIP] Fix reported efficiency of MariaDB query cache Fix MariaDB query cache efficiency underreporting Jun 17, 2026
Copilot AI requested a review from jmrenouard June 17, 2026 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants