diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 0909ce86899..8e22ba59531 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -505,5 +505,16 @@ hex(a) b 626172 2 SET @@character_set_connection= @old_character_set_connection; # +# MDEV-25183 JSON_TABLE: CREATE VIEW involving NESTED PATH ends up with invalid frm +# +CREATE VIEW v AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(NESTED PATH '$**.*' COLUMNS(a FOR ORDINALITY), b VARCHAR(8) PATH '$')) AS jt; +SHOW CREATE VIEW v; +View Create View character_set_client collation_connection +v CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `jt`.`a` AS `a`,`jt`.`b` AS `b` from JSON_TABLE('{}', '$' COLUMNS (NESTED PATH '$**.*' COLUMNS (`a` FOR ORDINALITY), `b` varchar(8) PATH '$')) `jt` latin1 latin1_swedish_ci +SELECT * FROM v; +a b +NULL NULL +DROP VIEW v; +# # 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 efb3ee527a8..b1cea033fd9 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -387,6 +387,14 @@ SET @@character_set_connection= utf8; select hex(a), b from json_table('["foo","bar"]','$[*]' columns (a char(3) path '$', b for ordinality)) t; SET @@character_set_connection= @old_character_set_connection; +--echo # +--echo # MDEV-25183 JSON_TABLE: CREATE VIEW involving NESTED PATH ends up with invalid frm +--echo # +CREATE VIEW v AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(NESTED PATH '$**.*' COLUMNS(a FOR ORDINALITY), b VARCHAR(8) PATH '$')) AS jt; +SHOW CREATE VIEW v; +SELECT * FROM v; +DROP VIEW v; + --echo # --echo # End of 10.6 tests --echo # diff --git a/sql/json_table.cc b/sql/json_table.cc index 1146288a61a..0d0e3f203fc 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -1220,7 +1220,8 @@ int Json_table_nested_path::print(THD *thd, Field ***f, String *str, if (str->append("COLUMNS (")) return 1; - do + /* loop while jc belongs to the current or nested paths. */ + while(jc && (jc->m_nest == c_path || jc->m_nest == c_nested)) { if (first_column) first_column= FALSE; @@ -1231,23 +1232,21 @@ int Json_table_nested_path::print(THD *thd, Field ***f, String *str, { if (jc->print(thd, *f, str)) return 1; - if (!(jc= it++)) - goto exit_ok; - ++(*f); + if ((jc= it++)) + ++(*f); } - else if (jc->m_nest == c_nested) + else { + DBUG_ASSERT(jc->m_nest == c_nested); if (str->append("NESTED PATH ") || print_path(str, &jc->m_nest->m_path) || + str->append(' ') || c_nested->print(thd, f, str, it, &jc)) return 1; c_nested= c_nested->m_next_nested; } - else - break; - } while(jc); + } -exit_ok: if (str->append(")")) return 1;