Current handler::records() is not fully usable as InnoDB could roll back the statement on some cases and you may not continue after that, it should be int records(ha_rows *n_rows) and server should check as these errors will abort the current query:
case HA_ERR_LOCK_DEADLOCK:
case HA_ERR_LOCK_TABLE_FULL:
case HA_ERR_LOCK_WAIT_TIMEOUT:
case HA_ERR_QUERY_INTERRUPTED:
see commit 40ec5373c0 on 5.7
{"report":{"fcp":922.2999992370605,"ttfb":266.8999996185303,"pageVisibility":"visible","entityId":56847,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"857265dc-c39f-45ab-a612-79a448850852","navigationType":0,"readyForUser":1047,"redirectCount":0,"resourceLoadedEnd":645.7999992370605,"resourceLoadedStart":292.5999994277954,"resourceTiming":[{"duration":79.5,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":292.5999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":292.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":372.0999994277954,"responseStart":0,"secureConnectionStart":0},{"duration":79.39999961853027,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":293,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":293,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":372.3999996185303,"responseStart":0,"secureConnectionStart":0},{"duration":253.69999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":293.19999980926514,"connectEnd":373.8999996185303,"connectStart":373.8999996185303,"domainLookupEnd":373.8999996185303,"domainLookupStart":373.8999996185303,"fetchStart":293.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":374.0999994277954,"responseEnd":546.8999996185303,"responseStart":386.5,"secureConnectionStart":373.8999996185303},{"duration":352.0999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/099b33461394b8015fc36c0a4b96e19f-CDN/lu2bu7/820016/12ta74/8679b4946efa1a0bb029a3a22206fb5d/_/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":293.69999980926514,"connectEnd":293.69999980926514,"connectStart":293.69999980926514,"domainLookupEnd":293.69999980926514,"domainLookupStart":293.69999980926514,"fetchStart":293.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":375.0999994277954,"responseEnd":645.7999992370605,"responseStart":391.5,"secureConnectionStart":293.69999980926514},{"duration":96,"initiatorType":"script","name":"https://jira.mariadb.org/s/94c15bff32baef80f4096a08aceae8bc-CDN/lu2bu7/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":293.8999996185303,"connectEnd":293.8999996185303,"connectStart":293.8999996185303,"domainLookupEnd":293.8999996185303,"domainLookupStart":293.8999996185303,"fetchStart":293.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":375.5,"responseEnd":389.8999996185303,"responseStart":389.0999994277954,"secureConnectionStart":293.8999996185303},{"duration":98.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":294.3999996185303,"connectEnd":294.3999996185303,"connectStart":294.3999996185303,"domainLookupEnd":294.3999996185303,"domainLookupStart":294.3999996185303,"fetchStart":294.3999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":376.0999994277954,"responseEnd":392.69999980926514,"responseStart":390.79999923706055,"secureConnectionStart":294.3999996185303},{"duration":112.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":294.5999994277954,"connectEnd":294.5999994277954,"connectStart":294.5999994277954,"domainLookupEnd":294.5999994277954,"domainLookupStart":294.5999994277954,"fetchStart":294.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":378.19999980926514,"responseEnd":407.0999994277954,"responseStart":402.8999996185303,"secureConnectionStart":294.5999994277954},{"duration":82,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bu7/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":294.79999923706055,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":294.79999923706055,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":376.79999923706055,"responseStart":0,"secureConnectionStart":0},{"duration":112.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":295,"connectEnd":295,"connectStart":295,"domainLookupEnd":295,"domainLookupStart":295,"fetchStart":295,"redirectEnd":0,"redirectStart":0,"requestStart":379.29999923706055,"responseEnd":407.3999996185303,"responseStart":403.5999994277954,"secureConnectionStart":295},{"duration":83.40000057220459,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bu7/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":295.0999994277954,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":295.0999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":378.5,"responseStart":0,"secureConnectionStart":0},{"duration":112.59999942779541,"initiatorType":"script","name":"https://jira.mariadb.org/s/3339d87fa2538a859872f2df449bf8d0-CDN/lu2bu7/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":295.19999980926514,"connectEnd":295.19999980926514,"connectStart":295.19999980926514,"domainLookupEnd":295.19999980926514,"domainLookupStart":295.19999980926514,"fetchStart":295.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":381.69999980926514,"responseEnd":407.79999923706055,"responseStart":404.29999923706055,"secureConnectionStart":295.19999980926514},{"duration":298,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":297.5999994277954,"connectEnd":297.5999994277954,"connectStart":297.5999994277954,"domainLookupEnd":297.5999994277954,"domainLookupStart":297.5999994277954,"fetchStart":297.5999994277954,"redirectEnd":0,"redirectStart":0,"requestStart":477.5,"responseEnd":595.5999994277954,"responseStart":592,"secureConnectionStart":297.5999994277954},{"duration":302.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":297.69999980926514,"connectEnd":297.69999980926514,"connectStart":297.69999980926514,"domainLookupEnd":297.69999980926514,"domainLookupStart":297.69999980926514,"fetchStart":297.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":566.5,"responseEnd":599.8999996185303,"responseStart":597.6999998092651,"secureConnectionStart":297.69999980926514},{"duration":149,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":677.8999996185303,"connectEnd":677.8999996185303,"connectStart":677.8999996185303,"domainLookupEnd":677.8999996185303,"domainLookupStart":677.8999996185303,"fetchStart":677.8999996185303,"redirectEnd":0,"redirectStart":0,"requestStart":790.8999996185303,"responseEnd":826.8999996185303,"responseStart":826.1999998092651,"secureConnectionStart":677.8999996185303}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":81,"responseStart":267,"responseEnd":297,"domLoading":270,"domInteractive":1098,"domContentLoadedEventStart":1098,"domContentLoadedEventEnd":1142,"domComplete":2262,"loadEventStart":2262,"loadEventEnd":2263,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1080.8999996185303},{"name":"bigPipe.sidebar-id.end","time":1081.6999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1081.7999992370605},{"name":"bigPipe.activity-panel-pipe-id.end","time":1082.7999992370605},{"name":"activityTabFullyLoaded","time":1155.6999998092651}],"measures":[],"correlationId":"a8f98c5f47202","effectiveType":"4g","downlink":9.4,"rtt":0,"serverDuration":122,"dbReadsTimeInMs":16,"dbConnsTimeInMs":27,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Oracle removed this in MySQL 5.7.18, because it is hard-wired to use the clustered index.
Sometimes using a secondary index could be a bad idea, because we do not have a hidden DB_TRX_ID column in the secondary indexes. For delete-marked records or for secondary index pages where PAGE_MAX_TRX_ID is too new, a lookup for a matching clustered index record must be performed (random lookups to the clustered index and optionally to undo log records). This is why it was hard-wired to use the clustered index in the first place.
See also my old blog post that mentions InnoDB secondary indexes.