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":1237,"ttfb":378.09999990463257,"pageVisibility":"visible","entityId":101850,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"a9c0a2fe-714d-4561-9d75-22e707da688f","navigationType":0,"readyForUser":1405.0999999046326,"redirectCount":0,"resourceLoadedEnd":1082.5,"resourceLoadedStart":384.40000009536743,"resourceTiming":[{"duration":399.40000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":384.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":384.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":783.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":399.2999997138977,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":384.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":384.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":784,"responseStart":0,"secureConnectionStart":0},{"duration":408.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/e9b27a47da5fb0f74a35acd57e9847fb-CDN/lu2bv2/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":384.90000009536743,"connectEnd":384.90000009536743,"connectStart":384.90000009536743,"domainLookupEnd":384.90000009536743,"domainLookupStart":384.90000009536743,"fetchStart":384.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":384.90000009536743,"responseEnd":793.0999999046326,"responseStart":793.0999999046326,"secureConnectionStart":384.90000009536743},{"duration":433.2000002861023,"initiatorType":"script","name":"https://jira.mariadb.org/s/c32eb0da7ad9831253f8397e6cc26afd-CDN/lu2bv2/820016/12ta74/2380add21a9a1006587582385952de73/_/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":385.09999990463257,"connectEnd":385.09999990463257,"connectStart":385.09999990463257,"domainLookupEnd":385.09999990463257,"domainLookupStart":385.09999990463257,"fetchStart":385.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":385.09999990463257,"responseEnd":818.3000001907349,"responseStart":818.3000001907349,"secureConnectionStart":385.09999990463257},{"duration":436.7999997138977,"initiatorType":"script","name":"https://jira.mariadb.org/s/bc0bcb146314416123c992714ee00ff7-CDN/lu2bv2/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":385.30000019073486,"connectEnd":385.30000019073486,"connectStart":385.30000019073486,"domainLookupEnd":385.30000019073486,"domainLookupStart":385.30000019073486,"fetchStart":385.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":385.30000019073486,"responseEnd":822.0999999046326,"responseStart":822.0999999046326,"secureConnectionStart":385.30000019073486},{"duration":437.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":385.5,"connectEnd":385.5,"connectStart":385.5,"domainLookupEnd":385.5,"domainLookupStart":385.5,"fetchStart":385.5,"redirectEnd":0,"redirectStart":0,"requestStart":385.5,"responseEnd":822.5999999046326,"responseStart":822.5999999046326,"secureConnectionStart":385.5},{"duration":437.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":385.80000019073486,"connectEnd":385.80000019073486,"connectStart":385.80000019073486,"domainLookupEnd":385.80000019073486,"domainLookupStart":385.80000019073486,"fetchStart":385.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":385.80000019073486,"responseEnd":822.9000000953674,"responseStart":822.9000000953674,"secureConnectionStart":385.80000019073486},{"duration":438.19999980926514,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2bv2/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":385.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":385.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":824.0999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":437.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":386.09999990463257,"connectEnd":386.09999990463257,"connectStart":386.09999990463257,"domainLookupEnd":386.09999990463257,"domainLookupStart":386.09999990463257,"fetchStart":386.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":386.09999990463257,"responseEnd":823.4000000953674,"responseStart":823.4000000953674,"secureConnectionStart":386.09999990463257},{"duration":437.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2bv2/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":386.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":386.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":824.2000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":437.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/719848dd97ebe0663199f49a3936487a-CDN/lu2bv2/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":386.5,"connectEnd":386.5,"connectStart":386.5,"domainLookupEnd":386.5,"domainLookupStart":386.5,"fetchStart":386.5,"redirectEnd":0,"redirectStart":0,"requestStart":386.5,"responseEnd":824,"responseStart":824,"secureConnectionStart":386.5},{"duration":689.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":392.5,"connectEnd":392.5,"connectStart":392.5,"domainLookupEnd":392.5,"domainLookupStart":392.5,"fetchStart":392.5,"redirectEnd":0,"redirectStart":0,"requestStart":392.5,"responseEnd":1082,"responseStart":1082,"secureConnectionStart":392.5},{"duration":689.9000000953674,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bv2/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":392.59999990463257,"connectEnd":392.59999990463257,"connectStart":392.59999990463257,"domainLookupEnd":392.59999990463257,"domainLookupStart":392.59999990463257,"fetchStart":392.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":392.59999990463257,"responseEnd":1082.5,"responseStart":1082.4000000953674,"secureConnectionStart":392.59999990463257},{"duration":485.5,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":1029.8000001907349,"connectEnd":1029.8000001907349,"connectStart":1029.8000001907349,"domainLookupEnd":1029.8000001907349,"domainLookupStart":1029.8000001907349,"fetchStart":1029.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":1029.8000001907349,"responseEnd":1515.3000001907349,"responseStart":1515.3000001907349,"secureConnectionStart":1029.8000001907349},{"duration":352.2000002861023,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1213.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1213.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1565.7000002861023,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":127,"responseStart":378,"responseEnd":388,"domLoading":382,"domInteractive":1506,"domContentLoadedEventStart":1506,"domContentLoadedEventEnd":1555,"domComplete":2345,"loadEventStart":2345,"loadEventEnd":2346,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1475.5999999046326},{"name":"bigPipe.sidebar-id.end","time":1476.5},{"name":"bigPipe.activity-panel-pipe-id.start","time":1476.7000002861023},{"name":"bigPipe.activity-panel-pipe-id.end","time":1479.3000001907349},{"name":"activityTabFullyLoaded","time":1572.5}],"measures":[],"correlationId":"c351b6f37cb0a","effectiveType":"4g","downlink":9.7,"rtt":0,"serverDuration":144,"dbReadsTimeInMs":13,"dbConnsTimeInMs":22,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}