The function btr_cur_t::search_leaf() that was refactored in MDEV-30400 is executing redundant page lookups when it would suffice to upgrade an already held index root/leaf page latch to exclusive.
monty noticed this while working on MDEV-34571.
I can reproduce the anomaly with the following test case:
--source include/have_innodb.inc
|
|
SET GLOBAL innodb_max_purge_lag_wait=0;
|
CREATE TEMPORARY TABLE t1(a SMALLINT PRIMARY KEY) ENGINE=InnoDB;
|
BEGIN;
|
SET @read0=
|
(SELECT CAST(variable_value AS INTEGER) FROM information_schema.global_status
|
WHERE variable_name = 'innodb_buffer_pool_read_requests');
|
INSERT INTO t1 VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
SET @read1=
|
(SELECT CAST(variable_value AS INTEGER) FROM information_schema.global_status
|
WHERE variable_name = 'innodb_buffer_pool_read_requests');
|
INSERT INTO t1 VALUES (10),(11),(12),(13),(14),(15),(16),(17),(18),(19);
|
SET @read2=
|
(SELECT CAST(variable_value AS INTEGER) FROM information_schema.global_status
|
WHERE variable_name = 'innodb_buffer_pool_read_requests');
|
COMMIT;
|
|
DROP TABLE t1;
|
SELECT @read1-@read0, @read2-@read1;
|
Without my fix, the last SELECT would report 33 and 34. With my fix, the numbers would reduce by 10, corresponding to the number of inserted rows. The remaining numbers (23 and 24) roughly correspond to writing one undo log record and one index record for each row.
We could do significantly better if we retained the mini-transaction open between individual row operations (MDEV-16232).
{"report":{"fcp":2029.7000002861023,"ttfb":420.90000009536743,"pageVisibility":"visible","entityId":130402,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"29a52e8c-f317-44e5-b586-2aeee02d11c0","navigationType":0,"readyForUser":2141.7000002861023,"redirectCount":0,"resourceLoadedEnd":2896,"resourceLoadedStart":436,"resourceTiming":[{"duration":1022.2000002861023,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":436,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":436,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1458.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":1022.4000000953674,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":436.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":436.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1458.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":1082.0999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":436.5,"connectEnd":436.5,"connectStart":436.5,"domainLookupEnd":436.5,"domainLookupStart":436.5,"fetchStart":436.5,"redirectEnd":0,"redirectStart":0,"requestStart":436.5,"responseEnd":1518.5999999046326,"responseStart":1518.5999999046326,"secureConnectionStart":436.5},{"duration":1141.5999999046326,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/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&whisper-enabled=true","startTime":436.7000002861023,"connectEnd":436.7000002861023,"connectStart":436.7000002861023,"domainLookupEnd":436.7000002861023,"domainLookupStart":436.7000002861023,"fetchStart":436.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":436.7000002861023,"responseEnd":1578.3000001907349,"responseStart":1578.3000001907349,"secureConnectionStart":436.7000002861023},{"duration":1184.4000000953674,"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":436.90000009536743,"connectEnd":436.90000009536743,"connectStart":436.90000009536743,"domainLookupEnd":436.90000009536743,"domainLookupStart":436.90000009536743,"fetchStart":436.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":436.90000009536743,"responseEnd":1621.3000001907349,"responseStart":1621.3000001907349,"secureConnectionStart":436.90000009536743},{"duration":1189.2999997138977,"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":437.2000002861023,"connectEnd":437.2000002861023,"connectStart":437.2000002861023,"domainLookupEnd":437.2000002861023,"domainLookupStart":437.2000002861023,"fetchStart":437.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":437.2000002861023,"responseEnd":1626.5,"responseStart":1626.5,"secureConnectionStart":437.2000002861023},{"duration":1189.6999998092651,"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":437.40000009536743,"connectEnd":437.40000009536743,"connectStart":437.40000009536743,"domainLookupEnd":437.40000009536743,"domainLookupStart":437.40000009536743,"fetchStart":437.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":437.40000009536743,"responseEnd":1627.0999999046326,"responseStart":1627.0999999046326,"secureConnectionStart":437.40000009536743},{"duration":1249.9000000953674,"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":437.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":437.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1687.5,"responseStart":0,"secureConnectionStart":0},{"duration":1189.8999996185303,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":437.7000002861023,"connectEnd":437.7000002861023,"connectStart":437.7000002861023,"domainLookupEnd":437.7000002861023,"domainLookupStart":437.7000002861023,"fetchStart":437.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":437.7000002861023,"responseEnd":1627.5999999046326,"responseStart":1627.5999999046326,"secureConnectionStart":437.7000002861023},{"duration":1249.6999998092651,"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":437.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":437.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1687.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":1190,"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":438.09999990463257,"connectEnd":438.09999990463257,"connectStart":438.09999990463257,"domainLookupEnd":438.09999990463257,"domainLookupStart":438.09999990463257,"fetchStart":438.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":438.09999990463257,"responseEnd":1628.0999999046326,"responseStart":1628.0999999046326,"secureConnectionStart":438.09999990463257},{"duration":2151.5,"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":444.30000019073486,"connectEnd":444.30000019073486,"connectStart":444.30000019073486,"domainLookupEnd":444.30000019073486,"domainLookupStart":444.30000019073486,"fetchStart":444.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":444.30000019073486,"responseEnd":2595.800000190735,"responseStart":2595.800000190735,"secureConnectionStart":444.30000019073486},{"duration":2451.699999809265,"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":444.30000019073486,"connectEnd":444.30000019073486,"connectStart":444.30000019073486,"domainLookupEnd":444.30000019073486,"domainLookupStart":444.30000019073486,"fetchStart":444.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":444.30000019073486,"responseEnd":2896,"responseStart":2896,"secureConnectionStart":444.30000019073486},{"duration":894.9000000953674,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1701.5999999046326,"connectEnd":1701.5999999046326,"connectStart":1701.5999999046326,"domainLookupEnd":1701.5999999046326,"domainLookupStart":1701.5999999046326,"fetchStart":1701.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1701.5999999046326,"responseEnd":2596.5,"responseStart":2596.5,"secureConnectionStart":1701.5999999046326},{"duration":902.3999996185303,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":2021.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":2021.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":2923.5999999046326,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":252,"responseStart":421,"responseEnd":437,"domLoading":433,"domInteractive":2927,"domContentLoadedEventStart":2927,"domContentLoadedEventEnd":2980,"domComplete":5255,"loadEventStart":5255,"loadEventEnd":5257,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2903.7000002861023},{"name":"bigPipe.sidebar-id.end","time":2904.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2904.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":2907.2000002861023},{"name":"activityTabFullyLoaded","time":2984.2000002861023}],"measures":[],"correlationId":"6d09327f766e57","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":23,"dbConnsTimeInMs":32,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}