Skip to content

Commit b418b60

Browse files
MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
st_select_lex::update_correlated_cache() fails to take JSON_TABLE functions in subqueries into account. Reviewed by Sergei Petrunia (sergey@mariadb.com)
1 parent e56040f commit b418b60

8 files changed

+181
-0
lines changed

mysql-test/main/subselect.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7559,5 +7559,31 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
75597559
drop view v1;
75607560
drop table t1, t2, t3;
75617561
#
7562+
# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
7563+
# update_correlated_cache() fails to take JSON_TABLE functions in
7564+
# subqueries into account.
7565+
#
7566+
create table t1(c json);
7567+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
7568+
('[{"x":"10"},{"x":"20"}]'),
7569+
('[{"x":"100"},{"x":"200"}]');
7570+
select c,
7571+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7572+
AS jt)
7573+
from t1;
7574+
c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7575+
AS jt)
7576+
[{"x":"1"},{"x":"2"}] 3
7577+
[{"x":"10"},{"x":"20"}] 30
7578+
[{"x":"100"},{"x":"200"}] 300
7579+
explain select c,
7580+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7581+
AS jt)
7582+
from t1;
7583+
id select_type table type possible_keys key key_len ref rows Extra
7584+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
7585+
2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table
7586+
drop table t1;
7587+
#
75627588
# End of 10.6 tests
75637589
#

mysql-test/main/subselect.test

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6434,6 +6434,28 @@ insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3));
64346434
drop view v1;
64356435
drop table t1, t2, t3;
64366436

6437+
--echo #
6438+
--echo # MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
6439+
--echo # update_correlated_cache() fails to take JSON_TABLE functions in
6440+
--echo # subqueries into account.
6441+
--echo #
6442+
6443+
create table t1(c json);
6444+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
6445+
('[{"x":"10"},{"x":"20"}]'),
6446+
('[{"x":"100"},{"x":"200"}]');
6447+
select c,
6448+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
6449+
AS jt)
6450+
from t1;
6451+
6452+
explain select c,
6453+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
6454+
AS jt)
6455+
from t1;
6456+
6457+
drop table t1;
6458+
64376459
--echo #
64386460
--echo # End of 10.6 tests
64396461
--echo #

mysql-test/main/subselect_no_exists_to_in.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7559,6 +7559,32 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
75597559
drop view v1;
75607560
drop table t1, t2, t3;
75617561
#
7562+
# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
7563+
# update_correlated_cache() fails to take JSON_TABLE functions in
7564+
# subqueries into account.
7565+
#
7566+
create table t1(c json);
7567+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
7568+
('[{"x":"10"},{"x":"20"}]'),
7569+
('[{"x":"100"},{"x":"200"}]');
7570+
select c,
7571+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7572+
AS jt)
7573+
from t1;
7574+
c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7575+
AS jt)
7576+
[{"x":"1"},{"x":"2"}] 3
7577+
[{"x":"10"},{"x":"20"}] 30
7578+
[{"x":"100"},{"x":"200"}] 300
7579+
explain select c,
7580+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7581+
AS jt)
7582+
from t1;
7583+
id select_type table type possible_keys key key_len ref rows Extra
7584+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
7585+
2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table
7586+
drop table t1;
7587+
#
75627588
# End of 10.6 tests
75637589
#
75647590
set optimizer_switch=default;

mysql-test/main/subselect_no_mat.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7552,6 +7552,32 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
75527552
drop view v1;
75537553
drop table t1, t2, t3;
75547554
#
7555+
# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
7556+
# update_correlated_cache() fails to take JSON_TABLE functions in
7557+
# subqueries into account.
7558+
#
7559+
create table t1(c json);
7560+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
7561+
('[{"x":"10"},{"x":"20"}]'),
7562+
('[{"x":"100"},{"x":"200"}]');
7563+
select c,
7564+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7565+
AS jt)
7566+
from t1;
7567+
c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7568+
AS jt)
7569+
[{"x":"1"},{"x":"2"}] 3
7570+
[{"x":"10"},{"x":"20"}] 30
7571+
[{"x":"100"},{"x":"200"}] 300
7572+
explain select c,
7573+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7574+
AS jt)
7575+
from t1;
7576+
id select_type table type possible_keys key key_len ref rows Extra
7577+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
7578+
2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table
7579+
drop table t1;
7580+
#
75557581
# End of 10.6 tests
75567582
#
75577583
set optimizer_switch=default;

mysql-test/main/subselect_no_opts.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7550,6 +7550,32 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
75507550
drop view v1;
75517551
drop table t1, t2, t3;
75527552
#
7553+
# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
7554+
# update_correlated_cache() fails to take JSON_TABLE functions in
7555+
# subqueries into account.
7556+
#
7557+
create table t1(c json);
7558+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
7559+
('[{"x":"10"},{"x":"20"}]'),
7560+
('[{"x":"100"},{"x":"200"}]');
7561+
select c,
7562+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7563+
AS jt)
7564+
from t1;
7565+
c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7566+
AS jt)
7567+
[{"x":"1"},{"x":"2"}] 3
7568+
[{"x":"10"},{"x":"20"}] 30
7569+
[{"x":"100"},{"x":"200"}] 300
7570+
explain select c,
7571+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7572+
AS jt)
7573+
from t1;
7574+
id select_type table type possible_keys key key_len ref rows Extra
7575+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
7576+
2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table
7577+
drop table t1;
7578+
#
75537579
# End of 10.6 tests
75547580
#
75557581
set @optimizer_switch_for_subselect_test=null;

mysql-test/main/subselect_no_scache.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7565,6 +7565,32 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
75657565
drop view v1;
75667566
drop table t1, t2, t3;
75677567
#
7568+
# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
7569+
# update_correlated_cache() fails to take JSON_TABLE functions in
7570+
# subqueries into account.
7571+
#
7572+
create table t1(c json);
7573+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
7574+
('[{"x":"10"},{"x":"20"}]'),
7575+
('[{"x":"100"},{"x":"200"}]');
7576+
select c,
7577+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7578+
AS jt)
7579+
from t1;
7580+
c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7581+
AS jt)
7582+
[{"x":"1"},{"x":"2"}] 3
7583+
[{"x":"10"},{"x":"20"}] 30
7584+
[{"x":"100"},{"x":"200"}] 300
7585+
explain select c,
7586+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7587+
AS jt)
7588+
from t1;
7589+
id select_type table type possible_keys key key_len ref rows Extra
7590+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
7591+
2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table
7592+
drop table t1;
7593+
#
75687594
# End of 10.6 tests
75697595
#
75707596
set optimizer_switch=default;

mysql-test/main/subselect_no_semijoin.result

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7550,6 +7550,32 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e'
75507550
drop view v1;
75517551
drop table t1, t2, t3;
75527552
#
7553+
# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated
7554+
# update_correlated_cache() fails to take JSON_TABLE functions in
7555+
# subqueries into account.
7556+
#
7557+
create table t1(c json);
7558+
insert into t1 values ('[{"x":"1"},{"x":"2"}]'),
7559+
('[{"x":"10"},{"x":"20"}]'),
7560+
('[{"x":"100"},{"x":"200"}]');
7561+
select c,
7562+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7563+
AS jt)
7564+
from t1;
7565+
c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7566+
AS jt)
7567+
[{"x":"1"},{"x":"2"}] 3
7568+
[{"x":"10"},{"x":"20"}] 30
7569+
[{"x":"100"},{"x":"200"}] 300
7570+
explain select c,
7571+
(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x"))
7572+
AS jt)
7573+
from t1;
7574+
id select_type table type possible_keys key key_len ref rows Extra
7575+
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
7576+
2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table
7577+
drop table t1;
7578+
#
75537579
# End of 10.6 tests
75547580
#
75557581
#

sql/sql_lex.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5501,6 +5501,9 @@ void st_select_lex::update_correlated_cache()
55015501

55025502
while ((tl= ti++))
55035503
{
5504+
if (tl->table_function)
5505+
is_correlated|= MY_TEST(tl->table_function->used_tables() &
5506+
OUTER_REF_TABLE_BIT);
55045507
// is_correlated|= tl->is_with_table_recursive_reference();
55055508
if (tl->on_expr)
55065509
is_correlated|= MY_TEST(tl->on_expr->used_tables() & OUTER_REF_TABLE_BIT);

0 commit comments

Comments
 (0)