Type:
Task
Priority:
Major
Resolution:
Unresolved
Fix Version/s:
None
Since MariaDB 10.2.2, InnoDB never holds any mutexes or RW-locks across handler API calls. (Until that version, btr_search_latch for the adaptive hash index could be held, and there was a special call handlerton::release_temporary_latches .)
During UPDATE operations, and also possibly during reads that perform range scans, it could help a lot to reuse the same InnoDB mini-transaction and to protect the current page with the page latch (buf_block_t::lock ) across calls:
Introduce row_prebuilt_t::mtr and keep it open.
Avoid mtr_t::commit() between row reads
Avoid storing & restoring btr_pcur_t position
If there is any possibility of a delay (such as, waiting for a row read from another table, or waiting for client connection I/O), then btr_pcur_store_position(); mtr.commit() will have to be called before the wait and mtr.start();btr_pcur_restore_position(); after it.
This change could remove any benefit of the row_prebuilt_t::fetch_cache (after 4 consecutive row reads, it’d prefetch 8 rows). Removing this cache would greatly reduce the InnoDB memory usage for partitioned tables.
Mini-transactions for single-row UPDATE /DELETE
Search and S-latch the PRIMARY KEY leaf page (get explicit transactional lock)
X-latch the PRIMARY KEY leaf page, update transaction directory page (rollback segment header page), allocate&initialize first undo log page of the transaction
Write undo log record
Modify the PRIMARY KEY index
(For each off-page column, use 1 mini-transaction per page written.)
(For each secondary index, modify the index.)
Commit the user transaction
There are 1 read-only mini-transaction and 4 read-write mini-transactions for a 1-row user transaction! (With MariaDB 10.3.5, only 3 read-write mini-transactions, because the first two writes were merged.)
We can actually use a single mini-transaction for all this. Only if there are secondary indexes or off-page columns, multiple mini-transactions will be needed:
Search and X-latch the PRIMARY KEY leaf page, update transaction directory page, allocate&initialize first undo log page, write undo log record, modify the PRIMARY KEY index (with implicit transactional locking)
(For each off-page column, use 1 mini-transaction per page written.)
(For each secondary index, modify the index.)
Commit the user transaction
If there are no off-page columns or secondary indexes, the user transaction commit can be merged to the same mini-transaction. (This is a special case for a single-row user transaction.)
The merging of the 'read' and 'write' steps under a single page lock would implement implicit locking for UPDATE and DELETE . When there is no locking conflict, this should greatly reduce the contention on lock_sys.mutex .
Using fewer mini-transactions for writes also means less communication with the redo log buffer, which should reduce contention in log_sys.mutex or whatever MDEV-14425 will be replacing it with.
Note: For any record modifications, we must always commit and restart the mini-transaction between rows, because we cannot move to another B-tree page after acquiring an undo page lock. Reads can reuse the same mini-transaction.
{"report":{"fcp":1836.8000001907349,"ttfb":744.9000000953674,"pageVisibility":"visible","entityId":67662,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"84b62d96-2f16-4b52-a191-d0cded727015","navigationType":0,"readyForUser":2006.3000001907349,"redirectCount":0,"resourceLoadedEnd":1469.7000002861023,"resourceLoadedStart":769,"resourceTiming":[{"duration":88.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":769,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":769,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":857.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":88.5,"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":769.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":769.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":857.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":479.7000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":769.5999999046326,"connectEnd":769.5999999046326,"connectStart":769.5999999046326,"domainLookupEnd":769.5999999046326,"domainLookupStart":769.5999999046326,"fetchStart":769.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":859.5,"responseEnd":1249.3000001907349,"responseStart":890.2000002861023,"secureConnectionStart":769.5999999046326},{"duration":700,"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":769.7000002861023,"connectEnd":769.7000002861023,"connectStart":769.7000002861023,"domainLookupEnd":769.7000002861023,"domainLookupStart":769.7000002861023,"fetchStart":769.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":859.3000001907349,"responseEnd":1469.7000002861023,"responseStart":878,"secureConnectionStart":769.7000002861023},{"duration":125.69999980926514,"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":769.8000001907349,"connectEnd":769.8000001907349,"connectStart":769.8000001907349,"domainLookupEnd":769.8000001907349,"domainLookupStart":769.8000001907349,"fetchStart":769.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":861.0999999046326,"responseEnd":895.5,"responseStart":891.9000000953674,"secureConnectionStart":769.8000001907349},{"duration":133.7000002861023,"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":770,"connectEnd":770,"connectStart":770,"domainLookupEnd":770,"domainLookupStart":770,"fetchStart":770,"redirectEnd":0,"redirectStart":0,"requestStart":868.4000000953674,"responseEnd":903.7000002861023,"responseStart":900,"secureConnectionStart":770},{"duration":133.09999990463257,"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":770.2000002861023,"connectEnd":770.2000002861023,"connectStart":770.2000002861023,"domainLookupEnd":770.2000002861023,"domainLookupStart":770.2000002861023,"fetchStart":770.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":867.9000000953674,"responseEnd":903.3000001907349,"responseStart":899.0999999046326,"secureConnectionStart":770.2000002861023},{"duration":90.40000009536743,"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":770.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":770.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":860.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":133.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":770.5,"connectEnd":770.5,"connectStart":770.5,"domainLookupEnd":770.5,"domainLookupStart":770.5,"fetchStart":770.5,"redirectEnd":0,"redirectStart":0,"requestStart":868.5999999046326,"responseEnd":904.4000000953674,"responseStart":900.9000000953674,"secureConnectionStart":770.5},{"duration":93.59999990463257,"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":770.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":770.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":864.3000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":134.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":770.9000000953674,"connectEnd":770.9000000953674,"connectStart":770.9000000953674,"domainLookupEnd":770.9000000953674,"domainLookupStart":770.9000000953674,"fetchStart":770.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":868.8000001907349,"responseEnd":905.4000000953674,"responseStart":901.9000000953674,"secureConnectionStart":770.9000000953674},{"duration":671.9000000953674,"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":794.5,"connectEnd":794.5,"connectStart":794.5,"domainLookupEnd":794.5,"domainLookupStart":794.5,"fetchStart":794.5,"redirectEnd":0,"redirectStart":0,"requestStart":949.3000001907349,"responseEnd":1466.4000000953674,"responseStart":1460.5999999046326,"secureConnectionStart":794.5},{"duration":661.0999999046326,"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":805.8000001907349,"connectEnd":805.8000001907349,"connectStart":805.8000001907349,"domainLookupEnd":805.8000001907349,"domainLookupStart":805.8000001907349,"fetchStart":805.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1030.0999999046326,"responseEnd":1466.9000000953674,"responseStart":1461.9000000953674,"secureConnectionStart":805.8000001907349},{"duration":253.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1420.4000000953674,"connectEnd":1420.4000000953674,"connectStart":1420.4000000953674,"domainLookupEnd":1420.4000000953674,"domainLookupStart":1420.4000000953674,"fetchStart":1420.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1638.8000001907349,"responseEnd":1674.2000002861023,"responseStart":1672.9000000953674,"secureConnectionStart":1420.4000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":209,"responseStart":745,"responseEnd":806,"domLoading":752,"domInteractive":2103,"domContentLoadedEventStart":2103,"domContentLoadedEventEnd":2205,"domComplete":4434,"loadEventStart":4434,"loadEventEnd":4435,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":2078.800000190735},{"name":"bigPipe.sidebar-id.end","time":2079.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.start","time":2079.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":2081},{"name":"activityTabFullyLoaded","time":2224}],"measures":[],"correlationId":"b70c123ccbb881","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":189,"dbReadsTimeInMs":81,"dbConnsTimeInMs":97,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}