When compiling/running relatively simple queries that construct JSON objects it seems like the query engine is re-computing function calls instead of using the actual value when extracting JSON data.
For example, given the query:
WITH RECURSIVE iter AS
|
(
|
SELECT 1 AS 'i'
|
UNION
|
SELECT i + 1
|
FROM iter
|
WHERE i < 10
|
),
|
json_data AS
|
(
|
SELECT
|
JSON_OBJECT(
|
'UUID', UUID()
|
) AS 'Data'
|
FROM iter
|
)
|
SELECT
|
JSON_EXTRACT(jd.`Data`, '$.UUID') AS 'Extracted',
|
jd.`Data`
|
FROM json_data jd
|
you would expect the `Extracted` value to be the same as the value that was computed in the `Data` JSON_OBJECT, but it is actually different.
With this query I was able to get the same results for iter generating numbers up to 1,000,000, although in another query that consisted of more joins then I did not see this behavior; in that case the extracted UUID was the same as the originally computed UUID.
- relates to
-
MDEV-32637
Implement native UUID7 function
-
-
Closed
{"report":{"fcp":747,"ttfb":229.5,"pageVisibility":"visible","entityId":125979,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"84de0386-c02b-4de3-aa9d-1ab5df17204f","navigationType":0,"readyForUser":831.9000000953674,"redirectCount":0,"resourceLoadedEnd":496.40000009536743,"resourceLoadedStart":238.90000009536743,"resourceTiming":[{"duration":7.599999904632568,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":238.90000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":238.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":246.5,"responseStart":0,"secureConnectionStart":0},{"duration":8.799999713897705,"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":239.2000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":239.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":248,"responseStart":0,"secureConnectionStart":0},{"duration":116.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":239.40000009536743,"connectEnd":249,"connectStart":249,"domainLookupEnd":249,"domainLookupStart":249,"fetchStart":239.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":249.2000002861023,"responseEnd":355.5,"responseStart":264,"secureConnectionStart":249},{"duration":226.40000009536743,"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":240,"connectEnd":240,"connectStart":240,"domainLookupEnd":240,"domainLookupStart":240,"fetchStart":240,"redirectEnd":0,"redirectStart":0,"requestStart":250.80000019073486,"responseEnd":466.40000009536743,"responseStart":268.6000003814697,"secureConnectionStart":240},{"duration":30.09999990463257,"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":240.2000002861023,"connectEnd":240.2000002861023,"connectStart":240.2000002861023,"domainLookupEnd":240.2000002861023,"domainLookupStart":240.2000002861023,"fetchStart":240.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":252,"responseEnd":270.30000019073486,"responseStart":266.5,"secureConnectionStart":240.2000002861023},{"duration":40.700000286102295,"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":240.40000009536743,"connectEnd":240.40000009536743,"connectStart":240.40000009536743,"domainLookupEnd":240.40000009536743,"domainLookupStart":240.40000009536743,"fetchStart":240.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":254.90000009536743,"responseEnd":281.1000003814697,"responseStart":277.7000002861023,"secureConnectionStart":240.40000009536743},{"duration":40.799999713897705,"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":240.60000038146973,"connectEnd":240.60000038146973,"connectStart":240.60000038146973,"domainLookupEnd":240.60000038146973,"domainLookupStart":240.60000038146973,"fetchStart":240.60000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":255.10000038146973,"responseEnd":281.40000009536743,"responseStart":278.30000019073486,"secureConnectionStart":240.60000038146973},{"duration":13,"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":240.7000002861023,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":240.7000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":253.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":41.09999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":240.80000019073486,"connectEnd":240.80000019073486,"connectStart":240.80000019073486,"domainLookupEnd":240.80000019073486,"domainLookupStart":240.80000019073486,"fetchStart":240.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":255.90000009536743,"responseEnd":281.90000009536743,"responseStart":279.1000003814697,"secureConnectionStart":240.80000019073486},{"duration":13.800000190734863,"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":241,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":241,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":254.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":44.5,"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":241.2000002861023,"connectEnd":241.2000002861023,"connectStart":241.2000002861023,"domainLookupEnd":241.2000002861023,"domainLookupStart":241.2000002861023,"fetchStart":241.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":260.6000003814697,"responseEnd":285.7000002861023,"responseStart":282.80000019073486,"secureConnectionStart":241.2000002861023},{"duration":253.19999980926514,"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":243.2000002861023,"connectEnd":243.2000002861023,"connectStart":243.2000002861023,"domainLookupEnd":243.2000002861023,"domainLookupStart":243.2000002861023,"fetchStart":243.2000002861023,"redirectEnd":0,"redirectStart":0,"requestStart":270,"responseEnd":496.40000009536743,"responseStart":493.7000002861023,"secureConnectionStart":243.2000002861023},{"duration":248.2000002861023,"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":247,"connectEnd":247,"connectStart":247,"domainLookupEnd":247,"domainLookupStart":247,"fetchStart":247,"redirectEnd":0,"redirectStart":0,"requestStart":271.30000019073486,"responseEnd":495.2000002861023,"responseStart":490.6000003814697,"secureConnectionStart":247},{"duration":163.80000019073486,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":503.5,"connectEnd":503.5,"connectStart":503.5,"domainLookupEnd":503.5,"domainLookupStart":503.5,"fetchStart":503.5,"redirectEnd":0,"redirectStart":0,"requestStart":630.2000002861023,"responseEnd":667.3000001907349,"responseStart":666.6000003814697,"secureConnectionStart":503.5},{"duration":201.30000019073486,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":740.4000000953674,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":740.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":941.7000002861023,"responseStart":0,"secureConnectionStart":0},{"duration":227.59999990463257,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":746.8000001907349,"connectEnd":746.8000001907349,"connectStart":746.8000001907349,"domainLookupEnd":746.8000001907349,"domainLookupStart":746.8000001907349,"fetchStart":746.8000001907349,"redirectEnd":0,"redirectStart":0,"requestStart":937.5,"responseEnd":974.4000000953674,"responseStart":970.2000002861023,"secureConnectionStart":746.8000001907349}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":31,"responseStart":229,"responseEnd":246,"domLoading":232,"domInteractive":943,"domContentLoadedEventStart":944,"domContentLoadedEventEnd":1003,"domComplete":1524,"loadEventStart":1525,"loadEventEnd":1525,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":910.5},{"name":"bigPipe.sidebar-id.end","time":911.3000001907349},{"name":"bigPipe.activity-panel-pipe-id.start","time":911.4000000953674},{"name":"bigPipe.activity-panel-pipe-id.end","time":914.7000002861023},{"name":"activityTabFullyLoaded","time":1027.4000000953674}],"measures":[],"correlationId":"e1d0b50257a006","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":111,"dbReadsTimeInMs":12,"dbConnsTimeInMs":20,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
The issue here has nothing to do with JSON_EXTRACT(), rather query materialization.
If you force the optimizer to materialize the cte, rather than merge it, you will get consistent results. For example
(
JSON_OBJECT(
)
jd.`Data`
will produce consistent UUIDs, but if the CTE can be merged into the parent query, then you will get 2 calls to UUID() rather than one, which is expected to produce 2 different values.
I'm not sure this is a bug.