Even after fix for MDEV-5112 (and MySQL Bug#69581), a query that runs index_merge intersection (union is probably affected too) over partitioned table, may return wrong query result.
Testcase:
create table t11 (
|
a int not null,
|
b int not null,
|
pk int not null,
|
primary key (pk),
|
key(a),
|
key(b)
|
) partition by hash(pk) partitions 10;
|
|
insert into t11 values (1,2,4); -- both
|
insert into t11 values (1,0,17); -- left
|
insert into t11 values (1,2,25); -- both
|
|
insert into t11 values (10,20,122);
|
insert into t11 values (10,20,123);
|
|
-- Now, fill in some data so that the optimizer choses index_merge
|
create table t12 (a int);
|
insert into t12 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
|
|
insert into t11 select 1,2, 200 + A.a + 10*B.a + 100*C.a from t12 A, t12 B, t12 C;
|
|
insert into t11 select 10+A.a + 10*B.a + 100*C.a + 1000*D.a,
|
10+A.a + 10*B.a + 100*C.a + 1000*D.a,
|
2000 + A.a + 10*B.a + 100*C.a + 1000*D.a
|
from t12 A, t12 B, t12 C ,t12 D;
|
|
-- This should show index_merge, using intersect
|
explain select * from t11 where a=1 and b=2 and pk between 1 and 999999 ;
|
-- 794 rows in output
|
select * from t11 where a=1 and b=2 and pk between 1 and 999 ;
|
-- 802 rows in output
|
select * from t11 ignore index(a,b) where a=1 and b=2 and pk between 1 and 999 ;
|
- relates to
-
MDEV-5821
Wrong result of SELECT query while two indexed colums are in WHERE section
-
-
Closed
{"report":{"fcp":1219.7999999523163,"ttfb":393.7000000476837,"pageVisibility":"visible","entityId":26113,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":32,"apdex":0.5,"journeyId":"6377eb91-0e79-4ece-b4d2-ec904e9789c2","navigationType":0,"readyForUser":1315.5,"redirectCount":0,"resourceLoadedEnd":1635.7000000476837,"resourceLoadedStart":401.5,"resourceTiming":[{"duration":126.09999990463257,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":401.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":401.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":527.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":126.29999995231628,"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":401.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":401.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":528.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":209.29999995231628,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":402,"connectEnd":402,"connectStart":402,"domainLookupEnd":402,"domainLookupStart":402,"fetchStart":402,"redirectEnd":0,"redirectStart":0,"requestStart":402,"responseEnd":611.2999999523163,"responseStart":611.2999999523163,"secureConnectionStart":402},{"duration":380.69999980926514,"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":402.2000000476837,"connectEnd":402.2000000476837,"connectStart":402.2000000476837,"domainLookupEnd":402.2000000476837,"domainLookupStart":402.2000000476837,"fetchStart":402.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":402.2000000476837,"responseEnd":782.8999998569489,"responseStart":782.8999998569489,"secureConnectionStart":402.2000000476837},{"duration":384.2000000476837,"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":402.39999985694885,"connectEnd":402.39999985694885,"connectStart":402.39999985694885,"domainLookupEnd":402.39999985694885,"domainLookupStart":402.39999985694885,"fetchStart":402.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":402.39999985694885,"responseEnd":786.5999999046326,"responseStart":786.5999999046326,"secureConnectionStart":402.39999985694885},{"duration":384.7999999523163,"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":402.7000000476837,"connectEnd":402.7000000476837,"connectStart":402.7000000476837,"domainLookupEnd":402.7000000476837,"domainLookupStart":402.7000000476837,"fetchStart":402.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":402.7000000476837,"responseEnd":787.5,"responseStart":787.5,"secureConnectionStart":402.7000000476837},{"duration":385.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":402.7999999523163,"connectEnd":402.7999999523163,"connectStart":402.7999999523163,"domainLookupEnd":402.7999999523163,"domainLookupStart":402.7999999523163,"fetchStart":402.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":402.7999999523163,"responseEnd":788.2999999523163,"responseStart":788.2999999523163,"secureConnectionStart":402.7999999523163},{"duration":424.10000014305115,"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":403.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":403.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":827.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":424.09999990463257,"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":403.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":403.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":827.3999998569489,"responseStart":0,"secureConnectionStart":0},{"duration":390.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":403.2999999523163,"connectEnd":403.2999999523163,"connectStart":403.2999999523163,"domainLookupEnd":403.2999999523163,"domainLookupStart":403.2999999523163,"fetchStart":403.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":403.2999999523163,"responseEnd":793.3999998569489,"responseStart":793.3999998569489,"secureConnectionStart":403.2999999523163},{"duration":391.2000000476837,"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":403.59999990463257,"connectEnd":403.59999990463257,"connectStart":403.59999990463257,"domainLookupEnd":403.59999990463257,"domainLookupStart":403.59999990463257,"fetchStart":403.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":403.59999990463257,"responseEnd":794.7999999523163,"responseStart":794.7999999523163,"secureConnectionStart":403.59999990463257},{"duration":1012.2000000476837,"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":424.39999985694885,"connectEnd":424.39999985694885,"connectStart":424.39999985694885,"domainLookupEnd":424.39999985694885,"domainLookupStart":424.39999985694885,"fetchStart":424.39999985694885,"redirectEnd":0,"redirectStart":0,"requestStart":424.39999985694885,"responseEnd":1436.5999999046326,"responseStart":1436.5999999046326,"secureConnectionStart":424.39999985694885},{"duration":1185.7999999523163,"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":424.5,"connectEnd":424.5,"connectStart":424.5,"domainLookupEnd":424.5,"domainLookupStart":424.5,"fetchStart":424.5,"redirectEnd":0,"redirectStart":0,"requestStart":424.5,"responseEnd":1610.2999999523163,"responseStart":1610.2999999523163,"secureConnectionStart":424.5},{"duration":582.0999999046326,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":855,"connectEnd":855,"connectStart":855,"domainLookupEnd":855,"domainLookupStart":855,"fetchStart":855,"redirectEnd":0,"redirectStart":0,"requestStart":855,"responseEnd":1437.0999999046326,"responseStart":1437,"secureConnectionStart":855},{"duration":561.5,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1204,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1204,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1765.5,"responseStart":0,"secureConnectionStart":0},{"duration":193,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":1442.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1442.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1635.7000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":169.20000004768372,"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":1443.8999998569489,"connectEnd":1443.8999998569489,"connectStart":1443.8999998569489,"domainLookupEnd":1443.8999998569489,"domainLookupStart":1443.8999998569489,"fetchStart":1443.8999998569489,"redirectEnd":0,"redirectStart":0,"requestStart":1443.8999998569489,"responseEnd":1613.0999999046326,"responseStart":1613.0999999046326,"secureConnectionStart":1443.8999998569489},{"duration":171,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":1444.5999999046326,"connectEnd":1444.5999999046326,"connectStart":1444.5999999046326,"domainLookupEnd":1444.5999999046326,"domainLookupStart":1444.5999999046326,"fetchStart":1444.5999999046326,"redirectEnd":0,"redirectStart":0,"requestStart":1444.5999999046326,"responseEnd":1615.5999999046326,"responseStart":1615.5999999046326,"secureConnectionStart":1444.5999999046326}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":227,"responseStart":394,"responseEnd":414,"domLoading":398,"domInteractive":1854,"domContentLoadedEventStart":1854,"domContentLoadedEventEnd":1901,"domComplete":2165,"loadEventStart":2165,"loadEventEnd":2166,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1783.3999998569489},{"name":"bigPipe.sidebar-id.end","time":1785.3999998569489},{"name":"bigPipe.activity-panel-pipe-id.start","time":1785.5999999046326},{"name":"bigPipe.activity-panel-pipe-id.end","time":1787.0999999046326},{"name":"activityTabFullyLoaded","time":1920.0999999046326}],"measures":[],"correlationId":"fea0835b8d65c7","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":104,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
== Ideas on how this could be fixed ==
Ordered index scans over ha_partition return records in the order of (key, extended_key_parts, ...).
There is no way to change that.
It could be nice to get index_merge to inform the storage engine that it needs the index scans to be rowid-ordered but not key-ordered, but this is a too big change for a GA version.