This is based on a report from a user.
Index lookups become very slow after a bulk delete operation.
Steps to reproduce with a totally synthetic dataset:
create table ten(a int);
|
insert into ten values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
create table one_k(a int);
|
insert into one_k select A.a + B.a* 10 + C.a * 100 from ten A, ten B, ten C;
|
create table t1 (
|
pk bigint primary key,
|
a bigint,
|
filler varchar(32),
|
key(a)
|
)engine=rocksdb;
|
|
set rocksdb_max_row_locks=1000*1000*1024;
|
insert into t1 select
|
A.a+ 1000*B.a, A.a+ 1000*B.a, A.a+ 1000*B.a
|
from
|
one_k A, one_k B;
|
set global rocksdb_force_flush_memtable_now=1;
|
The query (originally it was a join):
explain
|
select * from t1
|
where
|
a in (
|
100,101,102,103,104,105,106,107,108,109,
|
110,111,112,113,114,115,116,117,118,119,
|
120,121,122,123,124,125,126,127,128,129,
|
130,131,132,133,134,135,136,137,138,139,
|
140,141,142,143,144,145,146,147,148,149,
|
150,151,152,153,154,155,156,157,158,159,
|
160,161,162,163,164,165,166,167,168,169,
|
170,171,172,173,174,175,176,177,178,179,
|
180,181,182,183,184,185,186,187,188,189,
|
190,191,192,193,194,195,196,197,198,199,200);
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
|
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
|
| 1 | SIMPLE | t1 | range | a | a | 9 | NULL | 293 | Using index condition |
|
+------+-------------+-------+-------+---------------+------+---------+------+------+-----------------------+
|
The query itself returns 100 rows in 0.01 sec.
Now, let's do the same in the transaction:
begin;
|
delete from t1 where a between 100 and 100+99000;
|
# Query OK, 99001 rows affected (0.67 sec)
|
delete from t1 where a between 99000 and 200000;
|
# Query OK, 100900 rows affected (0.73 sec)
|
delete from t1 where a between 20000 and 300000;
|
# Query OK, 100000 rows affected (4.11 sec)
|
Re-running the query:
explain
|
select * from t1
|
where
|
a in (
|
100,101,102,103,104,105,106,107,108,109,
|
110,111,112,113,114,115,116,117,118,119,
|
120,121,122,123,124,125,126,127,128,129,
|
130,131,132,133,134,135,136,137,138,139,
|
140,141,142,143,144,145,146,147,148,149,
|
150,151,152,153,154,155,156,157,158,159,
|
160,161,162,163,164,165,166,167,168,169,
|
170,171,172,173,174,175,176,177,178,179,
|
180,181,182,183,184,185,186,187,188,189,
|
190,191,192,193,194,195,196,197,198,199,200);
|
The EXPLAIN is the same, but the query now takes 1.25 sec.
(this is a reduced testcase. In the original report, the join query couldn't finish at all)
{"report":{"fcp":1393.1000001430511,"ttfb":425.90000009536743,"pageVisibility":"visible","entityId":76539,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"ae7dab7a-7d2c-4e95-aa69-adfb6a1039bd","navigationType":0,"readyForUser":1481.2999999523163,"redirectCount":0,"resourceLoadedEnd":1722.9000000953674,"resourceLoadedStart":430.7999999523163,"resourceTiming":[{"duration":486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":430.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":430.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":916.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":486.09999990463257,"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":431.10000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":431.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":917.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":500.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":431.2000000476837,"connectEnd":431.2000000476837,"connectStart":431.2000000476837,"domainLookupEnd":431.2000000476837,"domainLookupStart":431.2000000476837,"fetchStart":431.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":431.2000000476837,"responseEnd":932,"responseStart":932,"secureConnectionStart":431.2000000476837},{"duration":545.4000000953674,"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":431.5,"connectEnd":431.5,"connectStart":431.5,"domainLookupEnd":431.5,"domainLookupStart":431.5,"fetchStart":431.5,"redirectEnd":0,"redirectStart":0,"requestStart":431.5,"responseEnd":976.9000000953674,"responseStart":976.9000000953674,"secureConnectionStart":431.5},{"duration":550,"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":431.60000014305115,"connectEnd":431.60000014305115,"connectStart":431.60000014305115,"domainLookupEnd":431.60000014305115,"domainLookupStart":431.60000014305115,"fetchStart":431.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":431.60000014305115,"responseEnd":981.6000001430511,"responseStart":981.6000001430511,"secureConnectionStart":431.60000014305115},{"duration":550.2000000476837,"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":431.7999999523163,"connectEnd":431.7999999523163,"connectStart":431.7999999523163,"domainLookupEnd":431.7999999523163,"domainLookupStart":431.7999999523163,"fetchStart":431.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":431.7999999523163,"responseEnd":982,"responseStart":982,"secureConnectionStart":431.7999999523163},{"duration":550.5,"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":431.90000009536743,"connectEnd":431.90000009536743,"connectStart":431.90000009536743,"domainLookupEnd":431.90000009536743,"domainLookupStart":431.90000009536743,"fetchStart":431.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":431.90000009536743,"responseEnd":982.4000000953674,"responseStart":982.4000000953674,"secureConnectionStart":431.90000009536743},{"duration":645,"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":432.10000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":432.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1077.1000001430511,"responseStart":0,"secureConnectionStart":0},{"duration":550.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":432.2999999523163,"connectEnd":432.2999999523163,"connectStart":432.2999999523163,"domainLookupEnd":432.2999999523163,"domainLookupStart":432.2999999523163,"fetchStart":432.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":432.2999999523163,"responseEnd":982.7999999523163,"responseStart":982.7999999523163,"secureConnectionStart":432.2999999523163},{"duration":644.8999998569489,"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":432.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":432.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1077.2999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":550.7999999523163,"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":432.60000014305115,"connectEnd":432.60000014305115,"connectStart":432.60000014305115,"domainLookupEnd":432.60000014305115,"domainLookupStart":432.60000014305115,"fetchStart":432.60000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":432.60000014305115,"responseEnd":983.4000000953674,"responseStart":983.4000000953674,"secureConnectionStart":432.60000014305115},{"duration":733.2999999523163,"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":438.90000009536743,"connectEnd":438.90000009536743,"connectStart":438.90000009536743,"domainLookupEnd":438.90000009536743,"domainLookupStart":438.90000009536743,"fetchStart":438.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":438.90000009536743,"responseEnd":1172.2000000476837,"responseStart":1172.2000000476837,"secureConnectionStart":438.90000009536743},{"duration":1257.7000000476837,"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":438.90000009536743,"connectEnd":438.90000009536743,"connectStart":438.90000009536743,"domainLookupEnd":438.90000009536743,"domainLookupStart":438.90000009536743,"fetchStart":438.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":438.90000009536743,"responseEnd":1696.6000001430511,"responseStart":1696.6000001430511,"secureConnectionStart":438.90000009536743},{"duration":184.60000014305115,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1106.5,"connectEnd":1106.5,"connectStart":1106.5,"domainLookupEnd":1106.5,"domainLookupStart":1106.5,"fetchStart":1106.5,"redirectEnd":0,"redirectStart":0,"requestStart":1106.5,"responseEnd":1291.1000001430511,"responseStart":1291.1000001430511,"secureConnectionStart":1106.5},{"duration":374,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1348.9000000953674,"connectEnd":1348.9000000953674,"connectStart":1348.9000000953674,"domainLookupEnd":1348.9000000953674,"domainLookupStart":1348.9000000953674,"fetchStart":1348.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1348.9000000953674,"responseEnd":1722.9000000953674,"responseStart":1722.9000000953674,"secureConnectionStart":1348.9000000953674},{"duration":428.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1387,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1387,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1815.5,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":169,"domainLookupEnd":213,"connectStart":213,"connectEnd":233,"secureConnectionStart":222,"requestStart":235,"responseStart":426,"responseEnd":435,"domLoading":429,"domInteractive":1762,"domContentLoadedEventStart":1762,"domContentLoadedEventEnd":1812,"domComplete":2199,"loadEventStart":2199,"loadEventEnd":2199,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1734.6000001430511},{"name":"bigPipe.sidebar-id.end","time":1735.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1735.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1738},{"name":"activityTabFullyLoaded","time":1829.2999999523163}],"measures":[],"correlationId":"4fad52ffb3c497","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":11,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Excerpt from perf report:
| myrocks::ha_rocksdb::read_range_first
| myrocks::ha_rocksdb::index_read_map_impl
| myrocks::ha_rocksdb::read_key_exact
| myrocks::ha_rocksdb::read_key_exact
| rocksdb::BaseDeltaIterator::Seek
| rocksdb::BaseDeltaIterator::UpdateCurrent
| |
| |--56.68%--?? (inlined)
| | |
| | |--55.69%--rocksdb::BaseDeltaIterator::UpdateCurrent
| | |
| | --0.99%--?? (inlined)
| | |
| | --0.74%--rocksdb::BaseDeltaIterator::UpdateCurrent
| |
| --10.38%--rocksdb::BaseDeltaIterator::UpdateCurrent
|
|--17.05%--rocksdb::BaseDeltaIterator::UpdateCurrent
| |
| |--14.82%--rocksdb::BaseDeltaIterator::UpdateCurrent
| | |
| | --13.34%--rocksdb::ReadableWriteBatch::GetEntryFromDataOffset
| | |
| | |--8.15%--rocksdb::ReadRecordFromWriteBatch
| | | |
| | | |--4.94%--rocksdb::ReadRecordFromWriteBatch
| | | |