It is expected that the range estimates that InnoDB returns from records_in_range call are not exact. Returning about 2x more or 2x less than actual value is considered to be still ok.
However, we are observing a 4.8x difference on a fairly large table. Unfortunately, the table is at the customer site and cannot be provided here.
I filed MDEV-21895 for a task of refactoring ha_innobase::records_in_range() to address the problems that I am aware of. It might be possible to do something in earlier versions, especially if a repeatable test case can be provided.
Note that there are also some strange things around handler::stats.records in handler::info(), as noted in MDEV-20169. That might also affect some query plans.
Marko Mäkelä
added a comment - I filed MDEV-21895 for a task of refactoring ha_innobase::records_in_range() to address the problems that I am aware of. It might be possible to do something in earlier versions, especially if a repeatable test case can be provided.
Note that there are also some strange things around handler::stats.records in handler::info() , as noted in MDEV-20169 . That might also affect some query plans.
Related to this, BTR_ESTIMATE and btr_cur_t::path_arr should be removed. They are only being used in the function btr_estimate_n_rows_in_range_low(). That function had better implement a specialized version of btr_cur_search_to_nth_level() to gather the path information.
Marko Mäkelä
added a comment - Related to this, BTR_ESTIMATE and btr_cur_t::path_arr should be removed. They are only being used in the function btr_estimate_n_rows_in_range_low() . That function had better implement a specialized version of btr_cur_search_to_nth_level() to gather the path information.
performed well in RQG testing. The crashes observed happen on the main trees too.
Matthias Leich
added a comment -
origin/bb-10.6-MDEV-21136-records_in_range-experimental be4adf01a474a434ba3140f0449e45828d75cdb7 2022-07-01T17:56:47+03:00
performed well in RQG testing. The crashes observed happen on the main trees too.
vlad.lesin, what are p1 and p2 there? Do I get it right that the slides describe locking for records_in_range(p1, p2) ?
Looking at slides #18 and #19... so, for records_in_range('aaa', 'zzz') the code will obtain latches for all pages that hold values between 'aaa' and 'zzz' ? Even if that is thousands of pages?
Sergei Petrunia
added a comment - vlad.lesin , what are p1 and p2 there? Do I get it right that the slides describe locking for records_in_range(p1, p2) ?
Looking at slides #18 and #19... so, for records_in_range('aaa', 'zzz') the code will obtain latches for all pages that hold values between 'aaa' and 'zzz' ? Even if that is thousands of pages?
> what are p1 and p2 there?
p1 and p2 are cursors, which are used to find 'aaa' and 'zzz' leaves in b-tree.
> Looking at slides #18 and #19... so, for records_in_range('aaa', 'zzz') the code will obtain latches for all pages that hold values between 'aaa' and 'zzz' ? Even if that is thousands of pages?
No, there is some limit on pages count(9 pages) for per-level walking, if the right page is not reached and the the limit was exceeded, the number of rows is estimated approximately by some formula, otherwise the estimation is exact. See btr_estimate_n_rows_in_range_on_level(), it has quite detailed description.
And, as you can see on the slides, the latches are released when we leave some page. The maximum amount of latched pages(red rectangles in the slides) at the same time is 4.
Vladislav Lesin
added a comment - - edited psergei ,
> what are p1 and p2 there?
p1 and p2 are cursors, which are used to find 'aaa' and 'zzz' leaves in b-tree.
> Looking at slides #18 and #19... so, for records_in_range('aaa', 'zzz') the code will obtain latches for all pages that hold values between 'aaa' and 'zzz' ? Even if that is thousands of pages?
No, there is some limit on pages count(9 pages) for per-level walking, if the right page is not reached and the the limit was exceeded, the number of rows is estimated approximately by some formula, otherwise the estimation is exact. See btr_estimate_n_rows_in_range_on_level(), it has quite detailed description.
And, as you can see on the slides, the latches are released when we leave some page. The maximum amount of latched pages(red rectangles in the slides) at the same time is 4.
People
Vladislav Lesin
Sergei Petrunia
Votes:
1Vote for this issue
Watchers:
7Start 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":1299.3000001907349,"ttfb":478.40000009536743,"pageVisibility":"visible","entityId":80674,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"f795f995-be1a-41d7-a433-c03c1abc0090","navigationType":0,"readyForUser":1403.4000000953674,"redirectCount":0,"resourceLoadedEnd":1716.7000002861023,"resourceLoadedStart":487.90000009536743,"resourceTiming":[{"duration":154.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":487.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":487.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":642.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":154.89999961853027,"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":488.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":488.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":643.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":221,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":488.40000009536743,"connectEnd":488.40000009536743,"connectStart":488.40000009536743,"domainLookupEnd":488.40000009536743,"domainLookupStart":488.40000009536743,"fetchStart":488.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":488.40000009536743,"responseEnd":709.4000000953674,"responseStart":709.4000000953674,"secureConnectionStart":488.40000009536743},{"duration":422.80000019073486,"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":488.59999990463257,"connectEnd":488.59999990463257,"connectStart":488.59999990463257,"domainLookupEnd":488.59999990463257,"domainLookupStart":488.59999990463257,"fetchStart":488.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":488.59999990463257,"responseEnd":911.4000000953674,"responseStart":911.4000000953674,"secureConnectionStart":488.59999990463257},{"duration":427.59999990463257,"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":488.80000019073486,"connectEnd":488.80000019073486,"connectStart":488.80000019073486,"domainLookupEnd":488.80000019073486,"domainLookupStart":488.80000019073486,"fetchStart":488.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":488.80000019073486,"responseEnd":916.4000000953674,"responseStart":916.4000000953674,"secureConnectionStart":488.80000019073486},{"duration":428.09999990463257,"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":489,"connectEnd":489,"connectStart":489,"domainLookupEnd":489,"domainLookupStart":489,"fetchStart":489,"redirectEnd":0,"redirectStart":0,"requestStart":489,"responseEnd":917.0999999046326,"responseStart":917.0999999046326,"secureConnectionStart":489},{"duration":428.2999997138977,"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":489.2000002861023,"connectEnd":489.2000002861023,"connectStart":489.2000002861023,"domainLookupEnd":489.2000002861023,"domainLookupStart":489.2000002861023,"fetchStart":489.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":489.2000002861023,"responseEnd":917.5,"responseStart":917.5,"secureConnectionStart":489.2000002861023},{"duration":431.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":489.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":489.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":921.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":431.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":489.40000009536743,"connectEnd":489.40000009536743,"connectStart":489.40000009536743,"domainLookupEnd":489.40000009536743,"domainLookupStart":489.40000009536743,"fetchStart":489.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":489.40000009536743,"responseEnd":921.0999999046326,"responseStart":921,"secureConnectionStart":489.40000009536743},{"duration":432.7999997138977,"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":489.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":489.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":922.5,"responseStart":0,"secureConnectionStart":0},{"duration":432,"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":489.80000019073486,"connectEnd":489.80000019073486,"connectStart":489.80000019073486,"domainLookupEnd":489.80000019073486,"domainLookupStart":489.80000019073486,"fetchStart":489.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":489.80000019073486,"responseEnd":921.8000001907349,"responseStart":921.8000001907349,"secureConnectionStart":489.80000019073486},{"duration":873.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":491.30000019073486,"connectEnd":491.30000019073486,"connectStart":491.30000019073486,"domainLookupEnd":491.30000019073486,"domainLookupStart":491.30000019073486,"fetchStart":491.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":491.30000019073486,"responseEnd":1364.8000001907349,"responseStart":1364.8000001907349,"secureConnectionStart":491.30000019073486},{"duration":1222.4000000953674,"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":494.30000019073486,"connectEnd":494.30000019073486,"connectStart":494.30000019073486,"domainLookupEnd":494.30000019073486,"domainLookupStart":494.30000019073486,"fetchStart":494.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":494.30000019073486,"responseEnd":1716.7000002861023,"responseStart":1716.7000002861023,"secureConnectionStart":494.30000019073486},{"duration":488.40000009536743,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":874.8000001907349,"connectEnd":874.8000001907349,"connectStart":874.8000001907349,"domainLookupEnd":874.8000001907349,"domainLookupStart":874.8000001907349,"fetchStart":874.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":874.8000001907349,"responseEnd":1363.2000002861023,"responseStart":1363.2000002861023,"secureConnectionStart":874.8000001907349},{"duration":447.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1290.3000001907349,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1290.3000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1737.8000001907349,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":316,"responseStart":478,"responseEnd":489,"domLoading":483,"domInteractive":1794,"domContentLoadedEventStart":1794,"domContentLoadedEventEnd":1851,"domComplete":2392,"loadEventStart":2392,"loadEventEnd":2392,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1740},{"name":"bigPipe.sidebar-id.end","time":1741},{"name":"bigPipe.activity-panel-pipe-id.start","time":1741.0999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1743.0999999046326},{"name":"activityTabFullyLoaded","time":1871.8000001907349}],"measures":[],"correlationId":"c3d669abe15e8c","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":108,"dbReadsTimeInMs":18,"dbConnsTimeInMs":27,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
I filed MDEV-21895 for a task of refactoring ha_innobase::records_in_range() to address the problems that I am aware of. It might be possible to do something in earlier versions, especially if a repeatable test case can be provided.
Note that there are also some strange things around handler::stats.records in handler::info(), as noted in
MDEV-20169. That might also affect some query plans.