I have 2 tables : galeries (id, name) and pictures (id, name, galery_id which is a FK to galeries).
If I want to select all galeries and, for each, randomly select one of the related pictures, I do this request :
SELECT g.id AS gallery_id,
|
g.nas AS gallery_name,
|
p.id AS picture_id,
|
p.name AS picture_name
|
FROM
|
(
|
SELECT gal.id,
|
gal.name,
|
(
|
SELECT pi.id
|
FROM pictures pi
|
WHERE pi.gallery_id = gal.id
|
ORDER BY RAND()
|
LIMIT 1
|
) AS p_random
|
FROM galleries gal
|
) g
|
LEFT JOIN pictures p
|
ON p.id = g.p_random
|
ORDER BY gallery_name ASC
|
In MySQL, this request works godd : I have a picture randomly selected, and I have all information (like the name). But, in MariaDB, no. RAND() and g.p_random are not equals !
If I modify my request like this :
SELECT g.id AS gallery_id,
|
g.nas AS gallery_name,
|
p.id AS picture_id,
|
p.name AS picture_name,
|
g.p_random AS r1,
|
g.p_random AS r2,
|
g.p_random AS r3
|
FROM
|
(
|
SELECT gal.id,
|
gal.name,
|
(
|
SELECT pi.id
|
FROM pictures pi
|
WHERE pi.gallery_id = gal.id
|
ORDER BY RAND()
|
LIMIT 1
|
) AS p_random
|
FROM galleries gal
|
) g
|
LEFT JOIN pictures p
|
ON p.id = g.p_random
|
ORDER BY gallery_name ASC
|
r1, r2 and r3 have the same value in MySQL, but not in MariaDB.
|
Is it a bug or is it a normal behavior ?
- relates to
-
MDEV-23066
RAND() evaluated and filtered twice with subquery
-
-
Confirmed
{"report":{"fcp":1150.6999999284744,"ttfb":260.10000002384186,"pageVisibility":"visible","entityId":27700,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"4c71637f-f287-42d4-8d1e-8b545fc43d6a","navigationType":0,"readyForUser":1251.3999999761581,"redirectCount":0,"resourceLoadedEnd":1289.1999999284744,"resourceLoadedStart":266,"resourceTiming":[{"duration":304.7999999523163,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":266,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":266,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":570.7999999523163,"responseStart":0,"secureConnectionStart":0},{"duration":304.8000000715256,"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":266.2999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":266.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":571.1000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":365.7999999523163,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":266.5,"connectEnd":266.5,"connectStart":266.5,"domainLookupEnd":266.5,"domainLookupStart":266.5,"fetchStart":266.5,"redirectEnd":0,"redirectStart":0,"requestStart":266.5,"responseEnd":632.2999999523163,"responseStart":632.2999999523163,"secureConnectionStart":266.5},{"duration":423.90000009536743,"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":266.6999999284744,"connectEnd":266.6999999284744,"connectStart":266.6999999284744,"domainLookupEnd":266.6999999284744,"domainLookupStart":266.6999999284744,"fetchStart":266.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":266.6999999284744,"responseEnd":690.6000000238419,"responseStart":690.6000000238419,"secureConnectionStart":266.6999999284744},{"duration":427.39999997615814,"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":267,"connectEnd":267,"connectStart":267,"domainLookupEnd":267,"domainLookupStart":267,"fetchStart":267,"redirectEnd":0,"redirectStart":0,"requestStart":267,"responseEnd":694.3999999761581,"responseStart":694.3999999761581,"secureConnectionStart":267},{"duration":427.89999997615814,"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":267.10000002384186,"connectEnd":267.10000002384186,"connectStart":267.10000002384186,"domainLookupEnd":267.10000002384186,"domainLookupStart":267.10000002384186,"fetchStart":267.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":267.10000002384186,"responseEnd":695,"responseStart":695,"secureConnectionStart":267.10000002384186},{"duration":429,"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":267.2999999523163,"connectEnd":267.2999999523163,"connectStart":267.2999999523163,"domainLookupEnd":267.2999999523163,"domainLookupStart":267.2999999523163,"fetchStart":267.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":267.2999999523163,"responseEnd":696.2999999523163,"responseStart":696.2999999523163,"secureConnectionStart":267.2999999523163},{"duration":509,"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":267.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":267.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":776.5,"responseStart":0,"secureConnectionStart":0},{"duration":429.8000000715256,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":267.6999999284744,"connectEnd":267.6999999284744,"connectStart":267.6999999284744,"domainLookupEnd":267.6999999284744,"domainLookupStart":267.6999999284744,"fetchStart":267.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":267.6999999284744,"responseEnd":697.5,"responseStart":697.5,"secureConnectionStart":267.6999999284744},{"duration":508.89999997615814,"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":267.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":267.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":776.6999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":431,"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":268,"connectEnd":268,"connectStart":268,"domainLookupEnd":268,"domainLookupStart":268,"fetchStart":268,"redirectEnd":0,"redirectStart":0,"requestStart":268,"responseEnd":699,"responseStart":699,"secureConnectionStart":268},{"duration":628.6000000238419,"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":273.1999999284744,"connectEnd":273.1999999284744,"connectStart":273.1999999284744,"domainLookupEnd":273.1999999284744,"domainLookupStart":273.1999999284744,"fetchStart":273.1999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":273.1999999284744,"responseEnd":901.7999999523163,"responseStart":901.7999999523163,"secureConnectionStart":273.1999999284744},{"duration":886.8000000715256,"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":273.2999999523163,"connectEnd":273.2999999523163,"connectStart":273.2999999523163,"domainLookupEnd":273.2999999523163,"domainLookupStart":273.2999999523163,"fetchStart":273.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":273.2999999523163,"responseEnd":1160.1000000238419,"responseStart":1160.1000000238419,"secureConnectionStart":273.2999999523163},{"duration":114.10000002384186,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":788.7999999523163,"connectEnd":788.7999999523163,"connectStart":788.7999999523163,"domainLookupEnd":788.7999999523163,"domainLookupStart":788.7999999523163,"fetchStart":788.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":788.7999999523163,"responseEnd":902.8999999761581,"responseStart":902.8999999761581,"secureConnectionStart":788.7999999523163},{"duration":222.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2bu7/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":1064.8999999761581,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1064.8999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1287,"responseStart":0,"secureConnectionStart":0},{"duration":223.19999992847443,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2bu7/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":1066,"connectEnd":1066,"connectStart":1066,"domainLookupEnd":1066,"domainLookupStart":1066,"fetchStart":1066,"redirectEnd":0,"redirectStart":0,"requestStart":1066,"responseEnd":1289.1999999284744,"responseStart":1289.1999999284744,"secureConnectionStart":1066},{"duration":292.2000000476837,"initiatorType":"script","name":"https://jira.mariadb.org/s/f51ef5507eea4c158f257c66c93b2a3f-CDN/lu2bu7/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":1066.3999999761581,"connectEnd":1066.3999999761581,"connectStart":1066.3999999761581,"domainLookupEnd":1066.3999999761581,"domainLookupStart":1066.3999999761581,"fetchStart":1066.3999999761581,"redirectEnd":0,"redirectStart":0,"requestStart":1066.3999999761581,"responseEnd":1358.6000000238419,"responseStart":1358.6000000238419,"secureConnectionStart":1066.3999999761581}],"fetchStart":1,"domainLookupStart":1,"domainLookupEnd":1,"connectStart":1,"connectEnd":1,"requestStart":83,"responseStart":260,"responseEnd":267,"domLoading":264,"domInteractive":1317,"domContentLoadedEventStart":1317,"domContentLoadedEventEnd":1360,"domComplete":1831,"loadEventStart":1831,"loadEventEnd":1832,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1301.7999999523163},{"name":"bigPipe.sidebar-id.end","time":1302.6999999284744},{"name":"bigPipe.activity-panel-pipe-id.start","time":1302.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.end","time":1304.2999999523163},{"name":"activityTabFullyLoaded","time":1382.6000000238419}],"measures":[],"correlationId":"759af929c2721a","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":111,"dbReadsTimeInMs":13,"dbConnsTimeInMs":21,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
This is a bug if different r1,r2,r3 is a bug in following example:
create table t1 (a int);
insert into t1 values (1),(2);
create view v1 (a,r) as select a,rand() from t1;
select a, r as r1, r as r2, r as r3 from v1;
drop view v1;
drop table t1;