There appears to be a problem with the results returned from a query when DISTINCT, LEFT JOIN and a subquery which contains a constant value are combined.
I've boiled down the problem into a simple example of how it fails:
SELECT DISTINCT realtable.id AS realid, virtualtable.id AS virtualid, virtualtable.recordexists
|
FROM realtable
|
LEFT JOIN (SELECT realtable.id, "yes" AS recordexists FROM realtable) virtualtable
|
ON realtable.id = virtualtable.id
|
If you create a table called "realtable" with columns int "id" and string "data", insert two records (1, "yes") and (2, "yes") and run the query then you'll get:
realid, virtualid, recordexists
|
1, 1, null
|
2, 2, null
|
which is incorrect. The value "yes" should be returned in the recordexists column. Obviously the "virtual" records are being joined correctly to the "real" records, because the virtualid returns the correct value, but the constant "yes" is missing. If you remove DISTINCT, change LEFT JOIN to just JOIN, or change "yes" to realtable.data then you get the correct results:
realid, virtualid, recordexists
|
1, 1, yes
|
2, 2, yes
|
I also confirmed that this is NOT caused by using the same table in both the main and sub queries.
I've got a query structured like this which is working in Postgress and MySQL, and when delivered to a client who tried it in MariaDB it started failing. This could probably be considered a data loss bug.
{"report":{"fcp":929.1999998092651,"ttfb":232,"pageVisibility":"visible","entityId":53920,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"8b8f14eb-38f1-4ca3-a5c8-2d0ef073a274","navigationType":0,"readyForUser":1001.2999997138977,"redirectCount":0,"resourceLoadedEnd":1038.9000000953674,"resourceLoadedStart":238.2999997138977,"resourceTiming":[{"duration":186.90000009536743,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":238.2999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":238.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":425.19999980926514,"responseStart":0,"secureConnectionStart":0},{"duration":186.90000009536743,"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":238.59999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":238.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":425.5,"responseStart":0,"secureConnectionStart":0},{"duration":195.90000009536743,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":238.7999997138977,"connectEnd":238.7999997138977,"connectStart":238.7999997138977,"domainLookupEnd":238.7999997138977,"domainLookupStart":238.7999997138977,"fetchStart":238.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":238.7999997138977,"responseEnd":434.69999980926514,"responseStart":434.69999980926514,"secureConnectionStart":238.7999997138977},{"duration":255,"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":239,"connectEnd":239,"connectStart":239,"domainLookupEnd":239,"domainLookupStart":239,"fetchStart":239,"redirectEnd":0,"redirectStart":0,"requestStart":239,"responseEnd":494,"responseStart":494,"secureConnectionStart":239},{"duration":259.19999980926514,"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":239.09999990463257,"connectEnd":239.09999990463257,"connectStart":239.09999990463257,"domainLookupEnd":239.09999990463257,"domainLookupStart":239.09999990463257,"fetchStart":239.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":239.09999990463257,"responseEnd":498.2999997138977,"responseStart":498.2999997138977,"secureConnectionStart":239.09999990463257},{"duration":259.2999997138977,"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":239.5,"connectEnd":239.5,"connectStart":239.5,"domainLookupEnd":239.5,"domainLookupStart":239.5,"fetchStart":239.5,"redirectEnd":0,"redirectStart":0,"requestStart":239.5,"responseEnd":498.7999997138977,"responseStart":498.7999997138977,"secureConnectionStart":239.5},{"duration":259.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":239.59999990463257,"connectEnd":239.59999990463257,"connectStart":239.59999990463257,"domainLookupEnd":239.59999990463257,"domainLookupStart":239.59999990463257,"fetchStart":239.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":239.59999990463257,"responseEnd":499.40000009536743,"responseStart":499.40000009536743,"secureConnectionStart":239.59999990463257},{"duration":338.40000009536743,"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":239.7999997138977,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":578.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":260,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":240,"connectEnd":240,"connectStart":240,"domainLookupEnd":240,"domainLookupStart":240,"fetchStart":240,"redirectEnd":0,"redirectStart":0,"requestStart":240,"responseEnd":500,"responseStart":500,"secureConnectionStart":240},{"duration":338.30000019073486,"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":240.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":240.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":578.4000000953674,"responseStart":0,"secureConnectionStart":0},{"duration":260.40000009536743,"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":240.2999997138977,"connectEnd":240.2999997138977,"connectStart":240.2999997138977,"domainLookupEnd":240.2999997138977,"domainLookupStart":240.2999997138977,"fetchStart":240.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":240.2999997138977,"responseEnd":500.69999980926514,"responseStart":500.69999980926514,"secureConnectionStart":240.2999997138977},{"duration":388,"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":241.09999990463257,"connectEnd":241.09999990463257,"connectStart":241.09999990463257,"domainLookupEnd":241.09999990463257,"domainLookupStart":241.09999990463257,"fetchStart":241.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":241.09999990463257,"responseEnd":629.0999999046326,"responseStart":629.0999999046326,"secureConnectionStart":241.09999990463257},{"duration":407.30000019073486,"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":241.09999990463257,"connectEnd":241.09999990463257,"connectStart":241.09999990463257,"domainLookupEnd":241.09999990463257,"domainLookupStart":241.09999990463257,"fetchStart":241.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":241.09999990463257,"responseEnd":648.4000000953674,"responseStart":648.2999997138977,"secureConnectionStart":241.09999990463257},{"duration":36.69999980926514,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":607.9000000953674,"connectEnd":607.9000000953674,"connectStart":607.9000000953674,"domainLookupEnd":607.9000000953674,"domainLookupStart":607.9000000953674,"fetchStart":607.9000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":607.9000000953674,"responseEnd":644.5999999046326,"responseStart":644.5999999046326,"secureConnectionStart":607.9000000953674},{"duration":388.2000002861023,"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":650.6999998092651,"connectEnd":650.6999998092651,"connectStart":650.6999998092651,"domainLookupEnd":650.6999998092651,"domainLookupStart":650.6999998092651,"fetchStart":650.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":650.6999998092651,"responseEnd":1038.9000000953674,"responseStart":1038.9000000953674,"secureConnectionStart":650.6999998092651}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":84,"responseStart":232,"responseEnd":234,"domLoading":236,"domInteractive":1052,"domContentLoadedEventStart":1052,"domContentLoadedEventEnd":1091,"domComplete":2045,"loadEventStart":2045,"loadEventEnd":2046,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1033.5},{"name":"bigPipe.sidebar-id.end","time":1034.1999998092651},{"name":"bigPipe.activity-panel-pipe-id.start","time":1034.2999997138977},{"name":"bigPipe.activity-panel-pipe-id.end","time":1036.7999997138977},{"name":"activityTabFullyLoaded","time":1102.1999998092651}],"measures":[],"correlationId":"348a9816beffab","effectiveType":"4g","downlink":9.3,"rtt":0,"serverDuration":91,"dbReadsTimeInMs":9,"dbConnsTimeInMs":19,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}