When EITS is enabled, ALTER TABLE ... ANALYZE PARTITION reads (and locks) all rows in the InnoDB table, even for a tiny partition. As a result, for huge tables it may work for hours and days and does not server the purpose. This does NOT happen without engine-independent persistent statistics enabled.
Consider this table:
MariaDB [test]> show create table tp\G
|
*************************** 1. row ***************************
|
Table: tp
|
Create Table: CREATE TABLE `tp` (
|
`id` int(11) DEFAULT NULL,
|
`c1` int(11) DEFAULT NULL
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1
|
PARTITION BY RANGE (`id`)
|
(PARTITION `p0` VALUES LESS THAN (10) ENGINE = InnoDB,
|
PARTITION `p1` VALUES LESS THAN MAXVALUE ENGINE = InnoDB)
|
1 row in set (0,00 sec)
|
|
MariaDB [test]> show table status like 'tp'\G
|
*************************** 1. row ***************************
|
Name: tp
|
Engine: InnoDB
|
Version: 10
|
Row_format: Dynamic
|
Rows: 9731209
|
Avg_row_length: 32
|
Data_length: 318619648
|
Max_data_length: 0
|
Index_length: 0
|
Data_free: 5242880
|
Auto_increment: NULL
|
Create_time: 2020-01-10 17:45:50
|
Update_time: 2020-01-14 10:39:57
|
Check_time: NULL
|
Collation: latin1_swedish_ci
|
Checksum: NULL
|
Create_options: partitioned
|
Comment:
|
1 row in set (0,02 sec)
|
This is how long it takes to get statistics for the partition with just 9 rows:
MariaDB [test]> set session use_stat_tables='preferably';
|
Query OK, 0 rows affected (0,00 sec)
|
|
MariaDB [test]> alter table tp analyze partition p0;
|
+---------+---------+----------+-----------------------------------------+
|
| Table | Op | Msg_type | Msg_text |
|
+---------+---------+----------+-----------------------------------------+
|
| test.tp | analyze | status | Engine-independent statistics collected |
|
| test.tp | analyze | status | OK |
|
+---------+---------+----------+-----------------------------------------+
|
2 rows in set (17,33 sec)
|
|
MariaDB [test]> select count(*) from tp;
|
+----------+
|
| count(*) |
|
+----------+
|
| 10000000 |
|
+----------+
|
1 row in set (5,89 sec)
|
|
MariaDB [test]> select count(*) from tp partition(p0);
|
+----------+
|
| count(*) |
|
+----------+
|
| 9 |
|
+----------+
|
1 row in set (0,00 sec)
|
In the INNODB STATUS output taken when this query runs we see:
...
|
---TRANSACTION 421521529651464, ACTIVE 10 sec fetching rows
|
mysql tables in use 2, locked 2
|
12335 lock struct(s), heap size 2105552, 6374971 row lock(s)
|
MySQL thread id 10, OS thread handle 140046871947008, query id 59 localhost root
|
alter table tp analyze partition p0
|
...
|
So, the statement that should access single partition with just 9 rows reads and locks all rows in the table. As a result it is totally useless, One can just run ANALYZE for the entire table with the same "costs".
{"report":{"fcp":906.7000002861023,"ttfb":252.40000009536743,"pageVisibility":"visible","entityId":82289,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"0cc6be85-7103-431f-a392-245988fdbaba","navigationType":0,"readyForUser":990.9000000953674,"redirectCount":0,"resourceLoadedEnd":1142.8000001907349,"resourceLoadedStart":259.40000009536743,"resourceTiming":[{"duration":159.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":259.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":259.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":418.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":159.2999997138977,"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":259.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":259.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":419,"responseStart":0,"secureConnectionStart":0},{"duration":168.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":259.90000009536743,"connectEnd":259.90000009536743,"connectStart":259.90000009536743,"domainLookupEnd":259.90000009536743,"domainLookupStart":259.90000009536743,"fetchStart":259.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":259.90000009536743,"responseEnd":428.40000009536743,"responseStart":428.40000009536743,"secureConnectionStart":259.90000009536743},{"duration":246.30000019073486,"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":260,"connectEnd":260,"connectStart":260,"domainLookupEnd":260,"domainLookupStart":260,"fetchStart":260,"redirectEnd":0,"redirectStart":0,"requestStart":260,"responseEnd":506.30000019073486,"responseStart":506.30000019073486,"secureConnectionStart":260},{"duration":250.5,"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":260.30000019073486,"connectEnd":260.30000019073486,"connectStart":260.30000019073486,"domainLookupEnd":260.30000019073486,"domainLookupStart":260.30000019073486,"fetchStart":260.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":260.30000019073486,"responseEnd":510.80000019073486,"responseStart":510.80000019073486,"secureConnectionStart":260.30000019073486},{"duration":250.80000019073486,"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":260.5,"connectEnd":260.5,"connectStart":260.5,"domainLookupEnd":260.5,"domainLookupStart":260.5,"fetchStart":260.5,"redirectEnd":0,"redirectStart":0,"requestStart":260.5,"responseEnd":511.30000019073486,"responseStart":511.30000019073486,"secureConnectionStart":260.5},{"duration":251.19999980926514,"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":260.6000003814697,"connectEnd":260.6000003814697,"connectStart":260.6000003814697,"domainLookupEnd":260.6000003814697,"domainLookupStart":260.6000003814697,"fetchStart":260.6000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":260.6000003814697,"responseEnd":511.80000019073486,"responseStart":511.80000019073486,"secureConnectionStart":260.6000003814697},{"duration":316.90000009536743,"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":260.80000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":260.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":577.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":251.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":261,"connectEnd":261,"connectStart":261,"domainLookupEnd":261,"domainLookupStart":261,"fetchStart":261,"redirectEnd":0,"redirectStart":0,"requestStart":261,"responseEnd":512.3000001907349,"responseStart":512.3000001907349,"secureConnectionStart":261},{"duration":316.69999980926514,"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":261.1000003814697,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":261.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":577.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":251.5,"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":261.30000019073486,"connectEnd":261.30000019073486,"connectStart":261.30000019073486,"domainLookupEnd":261.30000019073486,"domainLookupStart":261.30000019073486,"fetchStart":261.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":261.30000019073486,"responseEnd":512.8000001907349,"responseStart":512.8000001907349,"secureConnectionStart":261.30000019073486},{"duration":875,"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":262.1000003814697,"connectEnd":262.1000003814697,"connectStart":262.1000003814697,"domainLookupEnd":262.1000003814697,"domainLookupStart":262.1000003814697,"fetchStart":262.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":262.1000003814697,"responseEnd":1137.1000003814697,"responseStart":1137.1000003814697,"secureConnectionStart":262.1000003814697},{"duration":880.6999998092651,"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":262.1000003814697,"connectEnd":262.1000003814697,"connectStart":262.1000003814697,"domainLookupEnd":262.1000003814697,"domainLookupStart":262.1000003814697,"fetchStart":262.1000003814697,"redirectEnd":0,"redirectStart":0,"requestStart":262.1000003814697,"responseEnd":1142.8000001907349,"responseStart":1142.8000001907349,"secureConnectionStart":262.1000003814697},{"duration":546.2999997138977,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":591.7000002861023,"connectEnd":591.7000002861023,"connectStart":591.7000002861023,"domainLookupEnd":591.7000002861023,"domainLookupStart":591.7000002861023,"fetchStart":591.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":591.7000002861023,"responseEnd":1138,"responseStart":1138,"secureConnectionStart":591.7000002861023},{"duration":264.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":899.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":899.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1163.7000002861023,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":84,"responseStart":252,"responseEnd":253,"domLoading":257,"domInteractive":1221,"domContentLoadedEventStart":1221,"domContentLoadedEventEnd":1272,"domComplete":2614,"loadEventStart":2614,"loadEventEnd":2616,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1164.7000002861023},{"name":"bigPipe.sidebar-id.end","time":1165.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1165.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":1168.7000002861023},{"name":"activityTabFullyLoaded","time":1281.1000003814697}],"measures":[],"correlationId":"2129dd36113e92","effectiveType":"4g","downlink":9.6,"rtt":0,"serverDuration":96,"dbReadsTimeInMs":9,"dbConnsTimeInMs":16,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}