Note (Code 1276): Field or reference 'test.t1.x' of SELECT #2 was resolved in SELECT #1
Note (Code 1003): /* select#1 */ select `test`.`t1`.`x` AS `x`,(/* select#2 */ select sum(`jt`.`x`) from JSON_TABLE(`test`.`t1`.`x`, '$[*]' COLUMNS (`x` int(11) PATH '$.x')) `jt`) AS `(SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt)` from `test`.`t1`
Alice Sherepa
added a comment - Thank you for the report!
I repeated on 10.6-10.11:
MariaDB [test]> create table t1(x json);
Query OK, 0 rows affected (0,039 sec)
MariaDB [test]> insert into t1 values ('[{"x":"1"},{"x":"2"}]'),('[{"x":"10"},{"x":"20"}]'),('[{"x":"100"},{"x":"200"}]');
Query OK, 3 rows affected (0,003 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB [test]> select *, (SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt) from t1;
+---------------------------+-----------------------------------------------------------------------------+
| x | (SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt) |
+---------------------------+-----------------------------------------------------------------------------+
| [{"x":"1"},{"x":"2"}] | 3 |
| [{"x":"10"},{"x":"20"}] | 3 |
| [{"x":"100"},{"x":"200"}] | 3 |
+---------------------------+-----------------------------------------------------------------------------+
3 rows in set (0,000 sec)
MariaDB [test]> explain extended select *, (SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt) from t1;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | |
| 2 | SUBQUERY | jt | ALL | NULL | NULL | NULL | NULL | 40 | 100.00 | Table function: json_table |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------------------+
2 rows in set, 2 warnings (0,000 sec)
Note (Code 1276): Field or reference 'test.t1.x' of SELECT #2 was resolved in SELECT #1
Note (Code 1003): /* select#1 */ select `test`.`t1`.`x` AS `x`,(/* select#2 */ select sum(`jt`.`x`) from JSON_TABLE(`test`.`t1`.`x`, '$[*]' COLUMNS (`x` int(11) PATH '$.x')) `jt`) AS `(SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt)` from `test`.`t1`
I have the same issue as this with MariaDb 10.6, i have worked around it by creating a custom function containing the json_table command that is used in place of the subquery and then passing the JSON column to the function which returns some value
clint chenery
added a comment - I have the same issue as this with MariaDb 10.6, i have worked around it by creating a custom function containing the json_table command that is used in place of the subquery and then passing the JSON column to the function which returns some value
The subquery uses JSON_TABLE and its first parameter JSON_TABLE(t2_json is a reference to outside the subquery:
SELECT ...
t2_json,
(SELECTSUM(x2)
FROM
JSON_TABLE(t2_json, '$[*]' COLUMNS ( x2 int PATH '$' )) t3
) t2_json_sum
But EXPLAIN output in the first comment shows type=SUBQUERY, which means the optimizer thinks the subquery is not correlated.
Could the cause be that the code that collects subquery's outside references doesn't check table function's parameters? And the fix would be to check them?
Sergei Petrunia
added a comment - - edited The subquery uses JSON_TABLE and its first parameter JSON_TABLE(t2_json is a reference to outside the subquery:
SELECT ...
t2_json,
( SELECT SUM (x2)
FROM
JSON_TABLE(t2_json, '$[*]' COLUMNS ( x2 int PATH '$' )) t3
) t2_json_sum
But EXPLAIN output in the first comment shows type=SUBQUERY , which means the optimizer thinks the subquery is not correlated.
Could the cause be that the code that collects subquery's outside references doesn't check table function's parameters? And the fix would be to check them?
MariaDB [test]> SELECT events.event_title, event_distances FROM events WHERE EXISTS ( SELECT 1 FROM JSON_TABLE(event_distances, '$[*]' COLUMNS (distance_value FLOAT PATH '$.value')) AS distances WHERE distances.distance_value BETWEEN 20 AND 22 ) ORDER BY events.event_id ASC;
I've got a very similar (same) issue:
if you want to "join" JSON-Array's this is not very handy, but should work as follows:
CREATETABLE `tbl` (
`ID` smallint(5) unsigned NOTNULL AUTO_INCREMENT,
`Tankkarten` json DEFAULTNULL
);
SELECT t.ID, t.js,
(SELECT group_concat(jt.item SEPARATOR "\n" )
FROM JSON_TABLE(t.js, "$[*]" COLUMNS (item tinytext PATH "$")) jt ) AS tk
FROM tbl t
LIMIT 50
but the first value is repeated for every row
Marc
added a comment - I've got a very similar (same) issue:
if you want to "join" JSON-Array's this is not very handy, but should work as follows:
CREATE TABLE `tbl` (
`ID` smallint (5) unsigned NOT NULL AUTO_INCREMENT,
`Tankkarten` json DEFAULT NULL
);
SELECT t.ID, t.js,
( SELECT group_concat(jt.item SEPARATOR "\n" )
FROM JSON_TABLE(t.js, "$[*]" COLUMNS (item tinytext PATH "$" )) jt ) AS tk
FROM tbl t
LIMIT 50
but the first value is repeated for every row
MariaDB [test]> explain extended select a, b, ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t ) from (select 1 a, 2 b union all select 3 a, 4 b) as t order by a;
Note (Code 1276): Field or reference 't.a' of SELECT #2 was resolved in SELECT #1
Note (Code 1276): Field or reference 't.b' of SELECT #2 was resolved in SELECT #1
Note (Code 1003): /* select#1 */ select `t`.`a` AS `a`,`t`.`b` AS `b`,(/* select#2 */ select json_arrayagg(`t`.`i`) from JSON_TABLE(json_array(`t`.`a`,`t`.`b`), '$[*]' COLUMNS (`i` int(11) PATH '$')) `t`) AS `( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t )` from (/* select#3 */ select 1 AS `a`,2 AS `b` union all /* select#4 */ select 3 AS `a`,4 AS `b`) `t` order by `t`.`a`
MariaDB [test]> select a, b, ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$') ) t where rand() is not null ) from (select 1 a, 2 b union all select 3 a, 4 b) as t order by a;
Alice Sherepa
added a comment - from MDEV-34284
MariaDB [test]> select a, b, (
-> select json_arrayagg(i)
-> from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t
-> )
-> from (select 1 a, 2 b union all select 3 a, 4 b) as t
-> order by a;
+---+---+------------------------------------------------------------------------------------------------------+
| a | b | (
select json_arrayagg(i)
from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t
) |
+---+---+------------------------------------------------------------------------------------------------------+
| 1 | 2 | [1,2] |
| 3 | 4 | [1,2] |
+---+---+------------------------------------------------------------------------------------------------------+
2 rows in set (0,001 sec)
MariaDB [test]> explain extended select a, b, ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t ) from (select 1 a, 2 b union all select 3 a, 4 b) as t order by a;
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------+
| 1 | PRIMARY | <derived3> | ALL | NULL | NULL | NULL | NULL | 2 | 100.00 | Using filesort |
| 3 | DERIVED | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
| 4 | UNION | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | No tables used |
| 2 | SUBQUERY | t | ALL | NULL | NULL | NULL | NULL | 40 | 100.00 | Table function: json_table |
+------+-------------+------------+------+---------------+------+---------+------+------+----------+----------------------------+
4 rows in set, 3 warnings (0,001 sec)
Note (Code 1276): Field or reference 't.a' of SELECT #2 was resolved in SELECT #1
Note (Code 1276): Field or reference 't.b' of SELECT #2 was resolved in SELECT #1
Note (Code 1003): /* select#1 */ select `t`.`a` AS `a`,`t`.`b` AS `b`,(/* select#2 */ select json_arrayagg(`t`.`i`) from JSON_TABLE(json_array(`t`.`a`,`t`.`b`), '$[*]' COLUMNS (`i` int(11) PATH '$')) `t`) AS `( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$')) t )` from (/* select#3 */ select 1 AS `a`,2 AS `b` union all /* select#4 */ select 3 AS `a`,4 AS `b`) `t` order by `t`.`a`
MariaDB [test]> select a, b, ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$') ) t where rand() is not null ) from (select 1 a, 2 b union all select 3 a, 4 b) as t order by a;
+---+---+--------------------------------------------------------------------------------------------------------------------------------+
| a | b | ( select json_arrayagg(i) from json_table(json_array(a, b), '$[*]' columns (i int path '$') ) t where rand() is not null ) |
+---+---+--------------------------------------------------------------------------------------------------------------------------------+
| 1 | 2 | [1,2] |
| 3 | 4 | [3,4] |
+---+---+--------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0,001 sec)
psergei was almost right. Outside references are correctly gathered, but then the attribute st_select_lex::is_correlated is reset from the correct value (true, set during name resolution) back to false during the optimization phase by st_select_lex::update_correlated_cache().
The fix is to update st_select_lex::update_correlated_cache() to look for a json_table function in it's TABLE_LIST and set the appropriate flag if it is correlated.
Rex Johnston
added a comment - - edited psergei was almost right. Outside references are correctly gathered, but then the attribute st_select_lex::is_correlated is reset from the correct value (true, set during name resolution) back to false during the optimization phase by st_select_lex::update_correlated_cache() .
The fix is to update st_select_lex::update_correlated_cache() to look for a json_table function in it's TABLE_LIST and set the appropriate flag if it is correlated.
for the release notes: usage of columns from outer table references within json_table() will likely cause incorrect results.
Rex Johnston
added a comment - for the release notes: usage of columns from outer table references within json_table() will likely cause incorrect results.
People
Rex Johnston
Thomas G. Jensen
Votes:
3Vote for this issue
Watchers:
9Start watching this issue
Dates
Created:
Updated:
Resolved:
Git Integration
Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.
{"report":{"fcp":814.3999999761581,"ttfb":267.6999999284744,"pageVisibility":"visible","entityId":119115,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"9aabb323-a90a-48eb-8c45-8ff07a955d5e","navigationType":0,"readyForUser":935.7999999523163,"redirectCount":0,"resourceLoadedEnd":977.3999999761581,"resourceLoadedStart":274.5,"resourceTiming":[{"duration":86.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":274.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":274.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":360.60000002384186,"responseStart":0,"secureConnectionStart":0},{"duration":86.20000004768372,"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":274.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":274.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":361,"responseStart":0,"secureConnectionStart":0},{"duration":94.10000002384186,"initiatorType":"script","name":"https://jira.mariadb.org/s/fbf975c0cce4b1abf04784eeae9ba1f4-CDN/lu2bu7/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":275,"connectEnd":275,"connectStart":275,"domainLookupEnd":275,"domainLookupStart":275,"fetchStart":275,"redirectEnd":0,"redirectStart":0,"requestStart":275,"responseEnd":369.10000002384186,"responseStart":369.10000002384186,"secureConnectionStart":275},{"duration":163.70000004768372,"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":275.1999999284744,"connectEnd":275.1999999284744,"connectStart":275.1999999284744,"domainLookupEnd":275.1999999284744,"domainLookupStart":275.1999999284744,"fetchStart":275.1999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":275.1999999284744,"responseEnd":438.89999997615814,"responseStart":438.89999997615814,"secureConnectionStart":275.1999999284744},{"duration":167.10000002384186,"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":275.39999997615814,"connectEnd":275.39999997615814,"connectStart":275.39999997615814,"domainLookupEnd":275.39999997615814,"domainLookupStart":275.39999997615814,"fetchStart":275.39999997615814,"redirectEnd":0,"redirectStart":0,"requestStart":275.39999997615814,"responseEnd":442.5,"responseStart":442.5,"secureConnectionStart":275.39999997615814},{"duration":167.10000002384186,"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":275.6999999284744,"connectEnd":275.6999999284744,"connectStart":275.6999999284744,"domainLookupEnd":275.6999999284744,"domainLookupStart":275.6999999284744,"fetchStart":275.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":275.6999999284744,"responseEnd":442.7999999523163,"responseStart":442.7999999523163,"secureConnectionStart":275.6999999284744},{"duration":167.5,"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":275.6999999284744,"connectEnd":275.6999999284744,"connectStart":275.6999999284744,"domainLookupEnd":275.6999999284744,"domainLookupStart":275.6999999284744,"fetchStart":275.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":275.6999999284744,"responseEnd":443.1999999284744,"responseStart":443.10000002384186,"secureConnectionStart":275.6999999284744},{"duration":231.69999992847443,"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":276,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":276,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":507.6999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":167.5,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":276.10000002384186,"connectEnd":276.10000002384186,"connectStart":276.10000002384186,"domainLookupEnd":276.10000002384186,"domainLookupStart":276.10000002384186,"fetchStart":276.10000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":276.10000002384186,"responseEnd":443.60000002384186,"responseStart":443.60000002384186,"secureConnectionStart":276.10000002384186},{"duration":231.70000004768372,"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":276.1999999284744,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":276.1999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":507.89999997615814,"responseStart":0,"secureConnectionStart":0},{"duration":167.60000002384186,"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":276.5,"connectEnd":276.5,"connectStart":276.5,"domainLookupEnd":276.5,"domainLookupStart":276.5,"fetchStart":276.5,"redirectEnd":0,"redirectStart":0,"requestStart":276.5,"responseEnd":444.10000002384186,"responseStart":444.10000002384186,"secureConnectionStart":276.5},{"duration":413.6999999284744,"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":277.60000002384186,"connectEnd":277.60000002384186,"connectStart":277.60000002384186,"domainLookupEnd":277.60000002384186,"domainLookupStart":277.60000002384186,"fetchStart":277.60000002384186,"redirectEnd":0,"redirectStart":0,"requestStart":277.60000002384186,"responseEnd":691.2999999523163,"responseStart":691.2999999523163,"secureConnectionStart":277.60000002384186},{"duration":413.90000009536743,"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":277.6999999284744,"connectEnd":277.6999999284744,"connectStart":277.6999999284744,"domainLookupEnd":277.6999999284744,"domainLookupStart":277.6999999284744,"fetchStart":277.6999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":277.6999999284744,"responseEnd":691.6000000238419,"responseStart":691.6000000238419,"secureConnectionStart":277.6999999284744},{"duration":265.2999999523163,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":535,"connectEnd":535,"connectStart":535,"domainLookupEnd":535,"domainLookupStart":535,"fetchStart":535,"redirectEnd":0,"redirectStart":0,"requestStart":535,"responseEnd":800.2999999523163,"responseStart":800.2999999523163,"secureConnectionStart":535},{"duration":163.39999997615814,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":808.7999999523163,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":808.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":972.1999999284744,"responseStart":0,"secureConnectionStart":0},{"duration":134.39999997615814,"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":831,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":831,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":965.3999999761581,"responseStart":0,"secureConnectionStart":0},{"duration":134.10000002384186,"initiatorType":"link","name":"https://jira.mariadb.org/s/50bc9be5bfead1a25e72c1a9338c94f6-CDN/lu2bu7/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/css/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true","startTime":831.5,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":831.5,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":965.6000000238419,"responseStart":0,"secureConnectionStart":0},{"duration":133.30000007152557,"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":832.2999999523163,"connectEnd":832.2999999523163,"connectStart":832.2999999523163,"domainLookupEnd":832.2999999523163,"domainLookupStart":832.2999999523163,"fetchStart":832.2999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":832.2999999523163,"responseEnd":965.6000000238419,"responseStart":965.6000000238419,"secureConnectionStart":832.2999999523163},{"duration":144.20000004768372,"initiatorType":"script","name":"https://jira.mariadb.org/s/86ee9bbc76cd1bcd8556fcdcf46241c9-CDN/lu2bu7/820016/12ta74/e108c7645258ccb43280ed3404e3e949/_/download/contextbatch/js/com.atlassian.jira.plugins.jira-development-integration-plugin:0,-_super,-jira.view.issue,-jira.global,-jira.general,-jira.browse.project,-project.issue.navigator,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true","startTime":833.1999999284744,"connectEnd":833.1999999284744,"connectStart":833.1999999284744,"domainLookupEnd":833.1999999284744,"domainLookupStart":833.1999999284744,"fetchStart":833.1999999284744,"redirectEnd":0,"redirectStart":0,"requestStart":833.1999999284744,"responseEnd":977.3999999761581,"responseStart":977.3999999761581,"secureConnectionStart":833.1999999284744},{"duration":143.30000007152557,"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":832.7999999523163,"connectEnd":832.7999999523163,"connectStart":832.7999999523163,"domainLookupEnd":832.7999999523163,"domainLookupStart":832.7999999523163,"fetchStart":832.7999999523163,"redirectEnd":0,"redirectStart":0,"requestStart":832.7999999523163,"responseEnd":976.1000000238419,"responseStart":976,"secureConnectionStart":832.7999999523163}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":94,"responseStart":268,"responseEnd":271,"domLoading":271,"domInteractive":1022,"domContentLoadedEventStart":1022,"domContentLoadedEventEnd":1083,"domComplete":1227,"loadEventStart":1228,"loadEventEnd":1228,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":976},{"name":"bigPipe.sidebar-id.end","time":976.7999999523163},{"name":"bigPipe.activity-panel-pipe-id.start","time":977},{"name":"bigPipe.activity-panel-pipe-id.end","time":982.6999999284744},{"name":"activityTabFullyLoaded","time":1104.6000000238419}],"measures":[],"correlationId":"4e776835bbd3c8","effectiveType":"4g","downlink":10,"rtt":0,"serverDuration":111,"dbReadsTimeInMs":9,"dbConnsTimeInMs":17,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
Thank you for the report!
I repeated on 10.6-10.11:
MariaDB [test]> create table t1(x json);
Query OK, 0 rows affected (0,039 sec)
MariaDB [test]> insert into t1 values ('[{"x":"1"},{"x":"2"}]'),('[{"x":"10"},{"x":"20"}]'),('[{"x":"100"},{"x":"200"}]');
Query OK, 3 rows affected (0,003 sec)
Records: 3 Duplicates: 0 Warnings: 0
MariaDB [test]> select *, (SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt) from t1;
+---------------------------+-----------------------------------------------------------------------------+
| x | (SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt) |
+---------------------------+-----------------------------------------------------------------------------+
| [{"x":"1"},{"x":"2"}] | 3 |
| [{"x":"10"},{"x":"20"}] | 3 |
| [{"x":"100"},{"x":"200"}] | 3 |
+---------------------------+-----------------------------------------------------------------------------+
3 rows in set (0,000 sec)
MariaDB [test]> explain extended select *, (SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt) from t1;
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------------------+
| 1 | PRIMARY | t1 | ALL | NULL | NULL | NULL | NULL | 3 | 100.00 | |
| 2 | SUBQUERY | jt | ALL | NULL | NULL | NULL | NULL | 40 | 100.00 | Table function: json_table |
+------+-------------+-------+------+---------------+------+---------+------+------+----------+----------------------------+
2 rows in set, 2 warnings (0,000 sec)
Note (Code 1276): Field or reference 'test.t1.x' of SELECT #2 was resolved in SELECT #1
Note (Code 1003): /* select#1 */ select `test`.`t1`.`x` AS `x`,(/* select#2 */ select sum(`jt`.`x`) from JSON_TABLE(`test`.`t1`.`x`, '$[*]' COLUMNS (`x` int(11) PATH '$.x')) `jt`) AS `(SELECT sum(x) FROM json_table(x, '$[*]' columns( x int path '$.x')) AS jt)` from `test`.`t1`