The following test demonstrates that while InnoDB is collecting statistics are collected on a large table, any access from SQL to that table will be unnecessarily blocked by dict_table_stats_lock():
We can allow multiple threads to collect statistics for the same table in parallel, but only one thread at a time may be allowed to update the statistics. To prevent unnecessary work for multiple threads collecting statistics for the same table, we might introduce a counter of pending statistics-gathering operations. MySQL 5.7.32 preferred to introduce a lazily initialized mutex, which would not be easy to merge to 10.4.
Attachments
Issue Links
blocks
MDEV-23989Merge new release of InnoDB 5.7.32 to 10.2
Closed
causes
MDEV-24275InnoDB persistent stats analyze forces full scan forcing lock crash
I think that we should properly separate the statistics collection and the updates. If we do that, updating and accessing the statistics in dict_table_t and dict_index_t should be quick enough to be protected by dict_sys->mutex. Updating the persistent statistics tables will be holding it already.
Collecting that statistics can be protected by normal dict_index_t::lock and buf_block_t::lock. I do not think that multiple concurrent threads collecting statistics on the same index are going to be an issue.
Marko Mäkelä
added a comment - I think that we should properly separate the statistics collection and the updates. If we do that, updating and accessing the statistics in dict_table_t and dict_index_t should be quick enough to be protected by dict_sys->mutex . Updating the persistent statistics tables will be holding it already.
Collecting that statistics can be protected by normal dict_index_t::lock and buf_block_t::lock . I do not think that multiple concurrent threads collecting statistics on the same index are going to be an issue.
The fix so far looks good, except that in a few places we seem to be violating the latching order, by acquiring dict_sys->mutex while holding an index->lock. Be sure to release the latch via mtr_t::commit() or similar, to fix this. Run tests with ./mtr --mysqld=--loose-innodb-debug-sync to catch this.
Marko Mäkelä
added a comment - The fix so far looks good, except that in a few places we seem to be violating the latching order, by acquiring dict_sys->mutex while holding an index->lock . Be sure to release the latch via mtr_t::commit() or similar, to fix this. Run tests with ./mtr --mysqld=--loose-innodb-debug-sync to catch this.
People
Eugene Kosov (Inactive)
Marko Mäkelä
Votes:
0Vote for this issue
Watchers:
2Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":1402.2000007629395,"ttfb":739.1000003814697,"pageVisibility":"visible","entityId":92918,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"3086d4a8-a0d0-4c1e-8333-651a46debc89","navigationType":0,"readyForUser":1488.9000005722046,"redirectCount":0,"resourceLoadedEnd":1215.7000007629395,"resourceLoadedStart":745.2000007629395,"resourceTiming":[{"duration":139.5999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":745.2000007629395,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":745.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":884.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":139.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":745.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":745.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":885.1000003814697,"responseStart":0,"secureConnectionStart":0},{"duration":173.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":745.7000007629395,"connectEnd":745.7000007629395,"connectStart":745.7000007629395,"domainLookupEnd":745.7000007629395,"domainLookupStart":745.7000007629395,"fetchStart":745.7000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":745.7000007629395,"responseEnd":919,"responseStart":919,"secureConnectionStart":745.7000007629395},{"duration":274.3999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":745.9000005722046,"connectEnd":745.9000005722046,"connectStart":745.9000005722046,"domainLookupEnd":745.9000005722046,"domainLookupStart":745.9000005722046,"fetchStart":745.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":923.5,"responseEnd":1020.3000001907349,"responseStart":935.5,"secureConnectionStart":745.9000005722046},{"duration":174.89999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":746.1000003814697,"connectEnd":746.1000003814697,"connectStart":746.1000003814697,"domainLookupEnd":746.1000003814697,"domainLookupStart":746.1000003814697,"fetchStart":746.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":746.1000003814697,"responseEnd":921,"responseStart":921,"secureConnectionStart":746.1000003814697},{"duration":175.29999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":746.2000007629395,"connectEnd":746.2000007629395,"connectStart":746.2000007629395,"domainLookupEnd":746.2000007629395,"domainLookupStart":746.2000007629395,"fetchStart":746.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":746.2000007629395,"responseEnd":921.5,"responseStart":921.5,"secureConnectionStart":746.2000007629395},{"duration":175.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":746.5,"connectEnd":746.5,"connectStart":746.5,"domainLookupEnd":746.5,"domainLookupStart":746.5,"fetchStart":746.5,"redirectEnd":0,"redirectStart":0,"requestStart":746.5,"responseEnd":921.9000005722046,"responseStart":921.9000005722046,"secureConnectionStart":746.5},{"duration":176.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":746.6000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":746.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":922.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":175.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":746.9000005722046,"connectEnd":746.9000005722046,"connectStart":746.9000005722046,"domainLookupEnd":746.9000005722046,"domainLookupStart":746.9000005722046,"fetchStart":746.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":746.9000005722046,"responseEnd":922.5,"responseStart":922.5,"secureConnectionStart":746.9000005722046},{"duration":176.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":747,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":747,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":923.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":176,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":747.2000007629395,"connectEnd":747.2000007629395,"connectStart":747.2000007629395,"domainLookupEnd":747.2000007629395,"domainLookupStart":747.2000007629395,"fetchStart":747.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":747.2000007629395,"responseEnd":923.2000007629395,"responseStart":923.2000007629395,"secureConnectionStart":747.2000007629395},{"duration":308.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":748.2000007629395,"connectEnd":748.2000007629395,"connectStart":748.2000007629395,"domainLookupEnd":748.2000007629395,"domainLookupStart":748.2000007629395,"fetchStart":748.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":748.2000007629395,"responseEnd":1056.4000005722046,"responseStart":1056.4000005722046,"secureConnectionStart":748.2000007629395},{"duration":451.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":764.3000001907349,"connectEnd":764.3000001907349,"connectStart":764.3000001907349,"domainLookupEnd":764.3000001907349,"domainLookupStart":764.3000001907349,"fetchStart":764.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":764.3000001907349,"responseEnd":1215.7000007629395,"responseStart":1215.7000007629395,"secureConnectionStart":764.3000001907349},{"duration":160.10000038146973,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1146.6000003814697,"connectEnd":1146.6000003814697,"connectStart":1146.6000003814697,"domainLookupEnd":1146.6000003814697,"domainLookupStart":1146.6000003814697,"fetchStart":1146.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":1146.6000003814697,"responseEnd":1306.7000007629395,"responseStart":1306.7000007629395,"secureConnectionStart":1146.6000003814697}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":110,"responseStart":739,"responseEnd":763,"domLoading":742,"domInteractive":1554,"domContentLoadedEventStart":1554,"domContentLoadedEventEnd":1604,"domComplete":2550,"loadEventStart":2550,"loadEventEnd":2551,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1533.9000005722046},{"name":"bigPipe.sidebar-id.end","time":1534.7000007629395},{"name":"bigPipe.activity-panel-pipe-id.start","time":1534.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":1535.9000005722046},{"name":"activityTabFullyLoaded","time":1619.5}],"measures":[],"correlationId":"f9c00019378978","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":105,"dbReadsTimeInMs":11,"dbConnsTimeInMs":18,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I think that we should properly separate the statistics collection and the updates. If we do that, updating and accessing the statistics in dict_table_t and dict_index_t should be quick enough to be protected by dict_sys->mutex. Updating the persistent statistics tables will be holding it already.
Collecting that statistics can be protected by normal dict_index_t::lock and buf_block_t::lock. I do not think that multiple concurrent threads collecting statistics on the same index are going to be an issue.