From e644e130b0f8236826b372d81f7fb214ba0a3e5f Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 16 Jul 2024 12:43:53 +0300 Subject: [PATCH] MDEV-30623: Fix the testcase - Fix view-protocol: long expressions in SELECT list should have "expr AS column_name". - Also, moved the test from subselect*test to suite/json/t/json_table.test. --- mysql-test/main/subselect.result | 26 ------------------- mysql-test/main/subselect.test | 22 ---------------- .../main/subselect_no_exists_to_in.result | 26 ------------------- mysql-test/main/subselect_no_mat.result | 26 ------------------- mysql-test/main/subselect_no_opts.result | 26 ------------------- mysql-test/main/subselect_no_scache.result | 26 ------------------- mysql-test/main/subselect_no_semijoin.result | 26 ------------------- mysql-test/suite/json/r/json_table.result | 25 ++++++++++++++++++ mysql-test/suite/json/t/json_table.test | 22 ++++++++++++++++ 9 files changed, 47 insertions(+), 178 deletions(-) diff --git a/mysql-test/main/subselect.result b/mysql-test/main/subselect.result index 3b5954754d2..9fbf36e3d6e 100644 --- a/mysql-test/main/subselect.result +++ b/mysql-test/main/subselect.result @@ -7559,31 +7559,5 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e' drop view v1; drop table t1, t2, t3; # -# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated -# update_correlated_cache() fails to take JSON_TABLE functions in -# subqueries into account. -# -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), -('[{"x":"10"},{"x":"20"}]'), -('[{"x":"100"},{"x":"200"}]'); -select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -[{"x":"1"},{"x":"2"}] 3 -[{"x":"10"},{"x":"20"}] 30 -[{"x":"100"},{"x":"200"}] 300 -explain select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table -drop table t1; -# # End of 10.6 tests # diff --git a/mysql-test/main/subselect.test b/mysql-test/main/subselect.test index eca5af78eb7..badf55ca958 100644 --- a/mysql-test/main/subselect.test +++ b/mysql-test/main/subselect.test @@ -6434,28 +6434,6 @@ insert into t2 select (('e','e') IN (SELECT v1.id, v1.id FROM v1 JOIN t3)); drop view v1; drop table t1, t2, t3; ---echo # ---echo # MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated ---echo # update_correlated_cache() fails to take JSON_TABLE functions in ---echo # subqueries into account. ---echo # - -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), - ('[{"x":"10"},{"x":"20"}]'), - ('[{"x":"100"},{"x":"200"}]'); -select c, - (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) - AS jt) - from t1; - -explain select c, - (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) - AS jt) - from t1; - -drop table t1; - --echo # --echo # End of 10.6 tests --echo # diff --git a/mysql-test/main/subselect_no_exists_to_in.result b/mysql-test/main/subselect_no_exists_to_in.result index 806e2f67c63..0fdd573b339 100644 --- a/mysql-test/main/subselect_no_exists_to_in.result +++ b/mysql-test/main/subselect_no_exists_to_in.result @@ -7559,32 +7559,6 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e' drop view v1; drop table t1, t2, t3; # -# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated -# update_correlated_cache() fails to take JSON_TABLE functions in -# subqueries into account. -# -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), -('[{"x":"10"},{"x":"20"}]'), -('[{"x":"100"},{"x":"200"}]'); -select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -[{"x":"1"},{"x":"2"}] 3 -[{"x":"10"},{"x":"20"}] 30 -[{"x":"100"},{"x":"200"}] 300 -explain select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table -drop table t1; -# # End of 10.6 tests # set optimizer_switch=default; diff --git a/mysql-test/main/subselect_no_mat.result b/mysql-test/main/subselect_no_mat.result index cef26709fd3..5183d50cd49 100644 --- a/mysql-test/main/subselect_no_mat.result +++ b/mysql-test/main/subselect_no_mat.result @@ -7552,32 +7552,6 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e' drop view v1; drop table t1, t2, t3; # -# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated -# update_correlated_cache() fails to take JSON_TABLE functions in -# subqueries into account. -# -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), -('[{"x":"10"},{"x":"20"}]'), -('[{"x":"100"},{"x":"200"}]'); -select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -[{"x":"1"},{"x":"2"}] 3 -[{"x":"10"},{"x":"20"}] 30 -[{"x":"100"},{"x":"200"}] 300 -explain select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table -drop table t1; -# # End of 10.6 tests # set optimizer_switch=default; diff --git a/mysql-test/main/subselect_no_opts.result b/mysql-test/main/subselect_no_opts.result index 7ef17b14791..603958d2815 100644 --- a/mysql-test/main/subselect_no_opts.result +++ b/mysql-test/main/subselect_no_opts.result @@ -7550,32 +7550,6 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e' drop view v1; drop table t1, t2, t3; # -# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated -# update_correlated_cache() fails to take JSON_TABLE functions in -# subqueries into account. -# -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), -('[{"x":"10"},{"x":"20"}]'), -('[{"x":"100"},{"x":"200"}]'); -select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -[{"x":"1"},{"x":"2"}] 3 -[{"x":"10"},{"x":"20"}] 30 -[{"x":"100"},{"x":"200"}] 300 -explain select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table -drop table t1; -# # End of 10.6 tests # set @optimizer_switch_for_subselect_test=null; diff --git a/mysql-test/main/subselect_no_scache.result b/mysql-test/main/subselect_no_scache.result index 9bbaf51fe33..67d738a8a78 100644 --- a/mysql-test/main/subselect_no_scache.result +++ b/mysql-test/main/subselect_no_scache.result @@ -7565,32 +7565,6 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e' drop view v1; drop table t1, t2, t3; # -# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated -# update_correlated_cache() fails to take JSON_TABLE functions in -# subqueries into account. -# -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), -('[{"x":"10"},{"x":"20"}]'), -('[{"x":"100"},{"x":"200"}]'); -select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -[{"x":"1"},{"x":"2"}] 3 -[{"x":"10"},{"x":"20"}] 30 -[{"x":"100"},{"x":"200"}] 300 -explain select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table -drop table t1; -# # End of 10.6 tests # set optimizer_switch=default; diff --git a/mysql-test/main/subselect_no_semijoin.result b/mysql-test/main/subselect_no_semijoin.result index 7269ad94df7..0ec32e0fbf8 100644 --- a/mysql-test/main/subselect_no_semijoin.result +++ b/mysql-test/main/subselect_no_semijoin.result @@ -7550,32 +7550,6 @@ Warning 1292 Truncated incorrect DECIMAL value: 'e' drop view v1; drop table t1, t2, t3; # -# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated -# update_correlated_cache() fails to take JSON_TABLE functions in -# subqueries into account. -# -create table t1(c json); -insert into t1 values ('[{"x":"1"},{"x":"2"}]'), -('[{"x":"10"},{"x":"20"}]'), -('[{"x":"100"},{"x":"200"}]'); -select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -c (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -[{"x":"1"},{"x":"2"}] 3 -[{"x":"10"},{"x":"20"}] 30 -[{"x":"100"},{"x":"200"}] 300 -explain select c, -(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) -AS jt) -from t1; -id select_type table type possible_keys key key_len ref rows Extra -1 PRIMARY t1 ALL NULL NULL NULL NULL 3 -2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table -drop table t1; -# # End of 10.6 tests # # diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index b9cc09fdd97..20e1a4b1225 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -1011,5 +1011,30 @@ Jeans SELECT 1 FROM JSON_TABLE (row(1,2), '$' COLUMNS (o FOR ORDINALITY)) AS j; ERROR 21000: Operand should contain 1 column(s) # +# MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated +# update_correlated_cache() fails to take JSON_TABLE functions in +# subqueries into account. +# +create table t1(c json); +insert into t1 values ('[{"x":"1"},{"x":"2"}]'), +('[{"x":"10"},{"x":"20"}]'), +('[{"x":"100"},{"x":"200"}]'); +select c, +(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) +AS jt) as SUBQ +from t1; +c SUBQ +[{"x":"1"},{"x":"2"}] 3 +[{"x":"10"},{"x":"20"}] 30 +[{"x":"100"},{"x":"200"}] 300 +explain select c, +(SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) +AS jt) as SUBQ +from t1; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 3 +2 DEPENDENT SUBQUERY jt ALL NULL NULL NULL NULL 40 Table function: json_table +drop table t1; +# # End of 10.6 tests # diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index ec330046f25..580a8507c8f 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -871,6 +871,28 @@ SELECT * FROM json_table('[{"name":"Jeans"}]', '$[*]' --error ER_OPERAND_COLUMNS SELECT 1 FROM JSON_TABLE (row(1,2), '$' COLUMNS (o FOR ORDINALITY)) AS j; +--echo # +--echo # MDEV-30623 JSON_TABLE in subquery not correctly marked as correlated +--echo # update_correlated_cache() fails to take JSON_TABLE functions in +--echo # subqueries into account. +--echo # + +create table t1(c json); +insert into t1 values ('[{"x":"1"},{"x":"2"}]'), + ('[{"x":"10"},{"x":"20"}]'), + ('[{"x":"100"},{"x":"200"}]'); +select c, + (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) + AS jt) as SUBQ + from t1; + +explain select c, + (SELECT sum(x) FROM json_table(c, "$[*]" columns( x int path "$.x")) + AS jt) as SUBQ + from t1; + +drop table t1; + --echo # --echo # End of 10.6 tests --echo #