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":1299.7999997138977,"ttfb":292.59999990463257,"pageVisibility":"visible","entityId":125979,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":0.5,"journeyId":"efab6d23-1089-42e4-85bf-b8d26d7a260a","navigationType":0,"readyForUser":1407.9000000953674,"redirectCount":0,"resourceLoadedEnd":1933.1999998092651,"resourceLoadedStart":311.69999980926514,"resourceTiming":[{"duration":261.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":311.69999980926514,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":311.69999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":573.5,"responseStart":0,"secureConnectionStart":0},{"duration":261.7999997138977,"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":312,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":312,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":573.7999997138977,"responseStart":0,"secureConnectionStart":0},{"duration":270.59999990463257,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":312.90000009536743,"connectEnd":312.90000009536743,"connectStart":312.90000009536743,"domainLookupEnd":312.90000009536743,"domainLookupStart":312.90000009536743,"fetchStart":312.90000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":312.90000009536743,"responseEnd":583.5,"responseStart":583.5,"secureConnectionStart":312.90000009536743},{"duration":356.5,"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":313.09999990463257,"connectEnd":313.09999990463257,"connectStart":313.09999990463257,"domainLookupEnd":313.09999990463257,"domainLookupStart":313.09999990463257,"fetchStart":313.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":313.09999990463257,"responseEnd":669.5999999046326,"responseStart":669.5999999046326,"secureConnectionStart":313.09999990463257},{"duration":360.7000002861023,"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":313.2999997138977,"connectEnd":313.2999997138977,"connectStart":313.2999997138977,"domainLookupEnd":313.2999997138977,"domainLookupStart":313.2999997138977,"fetchStart":313.2999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":313.2999997138977,"responseEnd":674,"responseStart":673.9000000953674,"secureConnectionStart":313.2999997138977},{"duration":383.7999997138977,"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":313.40000009536743,"connectEnd":313.40000009536743,"connectStart":313.40000009536743,"domainLookupEnd":313.40000009536743,"domainLookupStart":313.40000009536743,"fetchStart":313.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":313.40000009536743,"responseEnd":697.1999998092651,"responseStart":697.1999998092651,"secureConnectionStart":313.40000009536743},{"duration":692.9000000953674,"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":337.7999997138977,"connectEnd":337.7999997138977,"connectStart":337.7999997138977,"domainLookupEnd":337.7999997138977,"domainLookupStart":337.7999997138977,"fetchStart":337.7999997138977,"redirectEnd":0,"redirectStart":0,"requestStart":337.7999997138977,"responseEnd":1030.6999998092651,"responseStart":1030.6999998092651,"secureConnectionStart":337.7999997138977},{"duration":840.9000000953674,"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":338.09999990463257,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":338.09999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1179,"responseStart":0,"secureConnectionStart":0},{"duration":695,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":338.19999980926514,"connectEnd":338.19999980926514,"connectStart":338.19999980926514,"domainLookupEnd":338.19999980926514,"domainLookupStart":338.19999980926514,"fetchStart":338.19999980926514,"redirectEnd":0,"redirectStart":0,"requestStart":338.19999980926514,"responseEnd":1033.1999998092651,"responseStart":1033.1999998092651,"secureConnectionStart":338.19999980926514},{"duration":840.7999997138977,"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":338.40000009536743,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":338.40000009536743,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1179.1999998092651,"responseStart":0,"secureConnectionStart":0},{"duration":696.6999998092651,"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":338.59999990463257,"connectEnd":338.59999990463257,"connectStart":338.59999990463257,"domainLookupEnd":338.59999990463257,"domainLookupStart":338.59999990463257,"fetchStart":338.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":338.59999990463257,"responseEnd":1035.2999997138977,"responseStart":1035.2999997138977,"secureConnectionStart":338.59999990463257},{"duration":1591.7999997138977,"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":340.5,"connectEnd":340.5,"connectStart":340.5,"domainLookupEnd":340.5,"domainLookupStart":340.5,"fetchStart":340.5,"redirectEnd":0,"redirectStart":0,"requestStart":340.5,"responseEnd":1932.2999997138977,"responseStart":1932.2999997138977,"secureConnectionStart":340.5},{"duration":1592.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":340.59999990463257,"connectEnd":340.59999990463257,"connectStart":340.59999990463257,"domainLookupEnd":340.59999990463257,"domainLookupStart":340.59999990463257,"fetchStart":340.59999990463257,"redirectEnd":0,"redirectStart":0,"requestStart":340.59999990463257,"responseEnd":1933.1999998092651,"responseStart":1933.1999998092651,"secureConnectionStart":340.59999990463257},{"duration":867.1999998092651,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":813,"connectEnd":813,"connectStart":813,"domainLookupEnd":813,"domainLookupStart":813,"fetchStart":813,"redirectEnd":0,"redirectStart":0,"requestStart":813,"responseEnd":1680.1999998092651,"responseStart":1680.1999998092651,"secureConnectionStart":813},{"duration":694.9000000953674,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":1291.6999998092651,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":1291.6999998092651,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":1986.5999999046326,"responseStart":0,"secureConnectionStart":0},{"duration":455.3999996185303,"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":1684.4000000953674,"connectEnd":1684.4000000953674,"connectStart":1684.4000000953674,"domainLookupEnd":1684.4000000953674,"domainLookupStart":1684.4000000953674,"fetchStart":1684.4000000953674,"redirectEnd":0,"redirectStart":0,"requestStart":1684.4000000953674,"responseEnd":2139.7999997138977,"responseStart":2139.7999997138977,"secureConnectionStart":1684.4000000953674}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":71,"responseStart":292,"responseEnd":358,"domLoading":310,"domInteractive":1995,"domContentLoadedEventStart":1995,"domContentLoadedEventEnd":2134,"domComplete":2578,"loadEventStart":2578,"loadEventEnd":2579,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":1942.0999999046326},{"name":"bigPipe.sidebar-id.end","time":1942.9000000953674},{"name":"bigPipe.activity-panel-pipe-id.start","time":1943},{"name":"bigPipe.activity-panel-pipe-id.end","time":1958.9000000953674},{"name":"activityTabFullyLoaded","time":2168.4000000953674}],"measures":[],"correlationId":"a5dcd9d722e385","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":142,"dbReadsTimeInMs":11,"dbConnsTimeInMs":21,"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.