Type:
Bug
Priority:
Critical
Resolution:
Fixed
Affects Version/s:
10.5.10 , 10.5.12 , 10.6.4 , 10.3(EOL) , 10.4(EOL) , 10.5 , 10.6
Wrong result, duplicate group by values and wrong aggregation "row"-data (row 1,2 and 5,6):
CREATE OR REPLACE TABLE test_kpi_date (
the_date date NOT NULL PRIMARY KEY
);
the_date org_type org_id dept_id cco_stk_ttl
2021-08-12 dis 10 ADVB 1 <- ?????
2021-08-12 dis 10 ADVB 4096 <- ?????
2021-08-12 dis 11 ADVB 2
2021-08-12 dis 12 ADVB <null>
2021-08-12 reg 1 ADVB 1 <- ?????
2021-08-12 reg 1 ADVB 4098 <- ?????
2021-08-12 dis 21 ADVB 96
2021-08-12 dis 22 ADVB 256
2021-08-12 dis 23 ADVB 512
2021-08-12 reg 2 ADVB 864
2021-08-12 nsc MMD ADVB 4963
generated with:
CREATE OR REPLACE TABLE test_kpi_date (
"id" int (11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
the_date date NOT NULL
);
result looks good:
the_date org_type org_id dept_id cco_stk_ttl
2021-08-12 dis 10 ADVB 4097
2021-08-12 dis 11 ADVB 2
2021-08-12 dis 12 ADVB <null>
2021-08-12 reg 1 ADVB 4099
2021-08-12 dis 21 ADVB 96
2021-08-12 dis 22 ADVB 256
2021-08-12 dis 23 ADVB 512
2021-08-12 reg 2 ADVB 864
2021-08-12 nsc MMD ADVB 4963
It looks like MDEV-25714 .
Test Data:
SET sql_mode = 'REAL_AS_FLOAT,PIPES_AS_CONCAT,ANSI_QUOTES,IGNORE_SPACE,ANSI,ONLY_FULL_GROUP_BY'
CREATE OR REPLACE TABLE test_kpi_date (
the_date date NOT NULL
, PRIMARY KEY ( "the_date" )
);
SELECT *
FROM test_kpi_date tkd
INSERT INTO test_kpi_date VALUES ( current_date ), ( current_date -1), ( current_date -2), ( current_date -3);
CREATE OR REPLACE TABLE test_org_district (
"id" int (11) NOT NULL AUTO_INCREMENT,
"nsc_id" char (5) NOT NULL ,
"dept_id" char (4) NOT NULL ,
"district_id" char (3) NOT NULL ,
"region_id" char (2) NOT NULL ,
PRIMARY KEY ( "id" ),
UNIQUE KEY "dept_district" ( "dept_id" , "district_id" ),
KEY "region_id" ( "dept_id" , "region_id" )
);
INSERT INTO test_org_district (nsc_id,dept_id,district_id,region_id) VALUES
( 'MMD' , 'ADVB' , '10' , '1' ),
( 'MMD' , 'ADVB' , '11' , '1' ),
( 'MMD' , 'ADVB' , '21' , '2' ),
( 'MMD' , 'ADVB' , '22' , '2' );
CREATE OR REPLACE TABLE "test_org_partner" (
"dept_id" char (4) CHARACTER SET utf8 NOT NULL ,
"ptn_id" char (5) CHARACTER SET utf8,
"district_id" char (3) CHARACTER SET utf8 NOT NULL DEFAULT '0' ,
"nsc_id" char (5) CHARACTER SET utf8 NOT NULL ,
PRIMARY KEY ( "ptn_id" , "dept_id" ),
KEY "dept_ptn" ( "dept_id" , "ptn_id" ),
KEY "dept_district_ptn" ( "dept_id" , "district_id" , "ptn_id" )
);
INSERT INTO test_org_partner (dept_id,ptn_id,district_id,nsc_id) VALUES
( 'ADVB' , '10001' , '10' , 'MMD' ),
( 'ADVB' , '10002' , '10' , 'MMD' ),
( 'ADVB' , '10003' , '10' , 'MMD' ),
( 'ADVB' , '11001' , '11' , 'MMD' ),
( 'ADVB' , '11002' , '11' , 'MMD' ),
( 'ADVB' , '10740' , '21' , 'MMD' ),
( 'ADVB' , '10741' , '21' , 'MMD' ),
( 'ADVB' , '10429' , '22' , 'MMD' ),
( 'ADVB' , '10771' , '23' , 'MMD' );
CREATE OR REPLACE TABLE "test_kpi_measure" (
"the_date" date DEFAULT NULL ,
"ptn_id" char (5) CHARACTER SET utf8 NOT NULL DEFAULT '' ,
"cco_stk_ttl" int (11) DEFAULT NULL ,
PRIMARY KEY ( "the_date" , "ptn_id" ),
KEY "ptn_id_idx" ( "ptn_id" )
);
INSERT INTO test_kpi_measure (the_date,ptn_id,cco_stk_ttl) VALUES
( current_date -1, '10001' ,4096),
( current_date -1, '10002' ,1),
( current_date -2, '10002' , null ),
( current_date -1, '11001' ,2),
( current_date -2, '11001' ,4),
( current_date -1, '11003' ,1024),
( current_date -2, '11003' ,2048),
( current_date -1, '10580' ,8),
( current_date -1, '10499' ,16),
( current_date -1, '10740' ,32),
( current_date -1, '10741' ,64),
( current_date -2, '10741' ,128),
( current_date -1, '10429' ,256),
( current_date -1, '10771' ,512);
SQL with wrong result:
SELECT org.the_date
, org.org_type
, org.org_id
, org.dept_id
, msr.`cco_stk_ttl`
FROM (
SELECT cal.the_date
, org.dept_id
, case when org.region_id <=> null then 'nsc'
when org.district_id <=> null then 'reg'
else 'dis'
end as org_type
, coalesce (org.district_id, org.region_id, 'MMD' ) as org_id
, org.district_id
, org.region_id
FROM test_kpi_date cal
CROSS JOIN test_org_district org
WHERE org.nsc_id = 'MMD' and org.dept_id IN ( 'ADVB' )
AND cal.the_date = CURRENT_DATE () - INTERVAL 1 DAY
GROUP BY cal.the_date, org.dept_id, org.region_id, org.district_id WITH ROLLUP
HAVING NOT (cal.the_date IS NULL OR org.dept_id IS NULL )
) org
LEFT JOIN (
SELECT sub.the_date
, dis.dept_id
, dis.region_id
, dis.district_id
, SUM (sub.cco_stk_ttl) as cco_stk_ttl
FROM test_kpi_measure sub
JOIN test_org_partner org ON org.ptn_id = sub.ptn_id
JOIN test_org_district dis ON dis.dept_id = org.dept_id AND dis.district_id = org.district_id
WHERE dis.nsc_id = 'MMD' and dis.dept_id IN ( 'ADVB' )
-- AND sub.the_date = CURRENT_DATE() - INTERVAL 1 DAY
GROUP BY sub.the_date, dis.dept_id, dis.region_id, dis.district_id WITH ROLLUP
) msr
ON msr.the_date = org.the_date
and msr.dept_id <=> org.dept_id
and msr.region_id <=> org.region_id
and msr.district_id <=> org.district_id
the result is correct if there is no index on the column the_date:
CREATE OR REPLACE TABLE test_kpi_date (
"id" int (11) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
the_date date NOT NULL
-- , PRIMARY KEY ("the_date")
-- , UNIQUE (the_date)
);
You can see, we try to use different definitions with the same behavior (wrong) when the_date get an index (PRIMARY/UNIQUE).
Without UNIQUE/PRIMARY Index on the_date it works fine.
relates to
MDEV-27496
Can Split Materialization work with WITH ROLLUP?
Open
{"report":{"fcp":1076,"ttfb":306,"pageVisibility":"visible","entityId":101850,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"cac7c6b8-dcd5-49a0-bf60-27c7be45d573","navigationType":0,"readyForUser":1284.2000000476837,"redirectCount":0,"resourceLoadedEnd":1074,"resourceLoadedStart":314.2000000476837,"resourceTiming":[{"duration":163.70000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":314.2000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":314.2000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":477.90000009536743,"responseStart":0,"secureConnectionStart":0},{"duration":163.70000004768372,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":314.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":314.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":478.2000000476837,"responseStart":0,"secureConnectionStart":0},{"duration":170.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":314.7000000476837,"connectEnd":314.7000000476837,"connectStart":314.7000000476837,"domainLookupEnd":314.7000000476837,"domainLookupStart":314.7000000476837,"fetchStart":314.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":314.7000000476837,"responseEnd":485.60000014305115,"responseStart":485.60000014305115,"secureConnectionStart":314.7000000476837},{"duration":331.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/2bf333562ca6724060a9d5f1535471f6/_/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":314.90000009536743,"connectEnd":314.90000009536743,"connectStart":314.90000009536743,"domainLookupEnd":314.90000009536743,"domainLookupStart":314.90000009536743,"fetchStart":314.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":314.90000009536743,"responseEnd":646.4000000953674,"responseStart":646.4000000953674,"secureConnectionStart":314.90000009536743},{"duration":335.2999999523163,"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":315.10000014305115,"connectEnd":315.10000014305115,"connectStart":315.10000014305115,"domainLookupEnd":315.10000014305115,"domainLookupStart":315.10000014305115,"fetchStart":315.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":315.10000014305115,"responseEnd":650.4000000953674,"responseStart":650.4000000953674,"secureConnectionStart":315.10000014305115},{"duration":335.69999980926514,"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":315.30000019073486,"connectEnd":315.30000019073486,"connectStart":315.30000019073486,"domainLookupEnd":315.30000019073486,"domainLookupStart":315.30000019073486,"fetchStart":315.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":315.30000019073486,"responseEnd":651,"responseStart":651,"secureConnectionStart":315.30000019073486},{"duration":335.80000019073486,"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":315.5,"connectEnd":315.5,"connectStart":315.5,"domainLookupEnd":315.5,"domainLookupStart":315.5,"fetchStart":315.5,"redirectEnd":0,"redirectStart":0,"requestStart":315.5,"responseEnd":651.3000001907349,"responseStart":651.3000001907349,"secureConnectionStart":315.5},{"duration":337.2000000476837,"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":315.7000000476837,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":315.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":652.9000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":336.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":315.80000019073486,"connectEnd":315.80000019073486,"connectStart":315.80000019073486,"domainLookupEnd":315.80000019073486,"domainLookupStart":315.80000019073486,"fetchStart":315.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":315.80000019073486,"responseEnd":651.9000000953674,"responseStart":651.9000000953674,"secureConnectionStart":315.80000019073486},{"duration":336.89999985694885,"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":316.10000014305115,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":316.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":653,"responseStart":0,"secureConnectionStart":0},{"duration":336.09999990463257,"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":316.30000019073486,"connectEnd":316.30000019073486,"connectStart":316.30000019073486,"domainLookupEnd":316.30000019073486,"domainLookupStart":316.30000019073486,"fetchStart":316.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":316.30000019073486,"responseEnd":652.4000000953674,"responseStart":652.4000000953674,"secureConnectionStart":316.30000019073486},{"duration":648.0999999046326,"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":414.10000014305115,"connectEnd":414.10000014305115,"connectStart":414.10000014305115,"domainLookupEnd":414.10000014305115,"domainLookupStart":414.10000014305115,"fetchStart":414.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":414.10000014305115,"responseEnd":1062.2000000476837,"responseStart":1062.2000000476837,"secureConnectionStart":414.10000014305115},{"duration":629.5999999046326,"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":442.10000014305115,"connectEnd":442.10000014305115,"connectStart":442.10000014305115,"domainLookupEnd":442.10000014305115,"domainLookupStart":442.10000014305115,"fetchStart":442.10000014305115,"redirectEnd":0,"redirectStart":0,"requestStart":442.10000014305115,"responseEnd":1071.7000000476837,"responseStart":1071.7000000476837,"secureConnectionStart":442.10000014305115},{"duration":266.2999999523163,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":637.7000000476837,"connectEnd":637.7000000476837,"connectStart":637.7000000476837,"domainLookupEnd":637.7000000476837,"domainLookupStart":637.7000000476837,"fetchStart":637.7000000476837,"redirectEnd":0,"redirectStart":0,"requestStart":637.7000000476837,"responseEnd":904,"responseStart":904,"secureConnectionStart":637.7000000476837},{"duration":139.59999990463257,"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","startTime":934.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":934.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1074,"responseStart":0,"secureConnectionStart":0},{"duration":437.59999990463257,"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","startTime":935.4000000953674,"connectEnd":935.4000000953674,"connectStart":935.4000000953674,"domainLookupEnd":935.4000000953674,"domainLookupStart":935.4000000953674,"fetchStart":935.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":935.4000000953674,"responseEnd":1373,"responseStart":1373,"secureConnectionStart":935.4000000953674},{"duration":442.7000000476837,"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","startTime":935.9000000953674,"connectEnd":935.9000000953674,"connectStart":935.9000000953674,"domainLookupEnd":935.9000000953674,"domainLookupStart":935.9000000953674,"fetchStart":935.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":935.9000000953674,"responseEnd":1378.6000001430511,"responseStart":1378.6000001430511,"secureConnectionStart":935.9000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":55,"responseStart":306,"responseEnd":442,"domLoading":312,"domInteractive":1360,"domContentLoadedEventStart":1360,"domContentLoadedEventEnd":1423,"domComplete":1779,"loadEventStart":1779,"loadEventEnd":1779,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1322.7000000476837},{"name":"bigPipe.sidebar-id.end","time":1323.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1323.7000000476837},{"name":"bigPipe.activity-panel-pipe-id.end","time":1325.7000000476837},{"name":"activityTabFullyLoaded","time":1447.6000001430511}],"measures":[],"correlationId":"3539a2e2e17c36","effectiveType":"4g","downlink":9.9,"rtt":0,"serverDuration":124,"dbReadsTimeInMs":14,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Takeaways from yesterday call: