Commit 6a5f86bf authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-25230 JSON_TABLE: CREATE VIEW with 2nd level NESTED PATH ends up with...

MDEV-25230 JSON_TABLE: CREATE VIEW with 2nd level NESTED PATH ends up with invalid frm, Assertion `m_status == DA_ERROR || m_status == DA_OK || m_status == DA_OK_BULK' failed.

Handle multiple NESTED paths.
parent 707d8653
......@@ -543,5 +543,16 @@ CREATE TABLE t1 AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(a CHAR(16) PATH '$
DROP TABLE t1;
SET NAMES default;
#
# MDEV-25230 SON_TABLE: CREATE VIEW with 2nd level NESTED PATH ends up with invalid frm, Assertion `m_status == DA_ERROR || m_status == DA_OK || m_status == DA_OK_BULK' failed.
#
CREATE VIEW v AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(NESTED PATH '$' COLUMNS(NESTED PATH '$.*' COLUMNS(o FOR ORDINALITY)))) AS jt;
SELECT * FROM v;
o
NULL
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`.`o` AS `o` from JSON_TABLE('{}', '$' COLUMNS (NESTED PATH '$.*' COLUMNS (NESTED PATH '$.*' COLUMNS (`o` FOR ORDINALITY)))) `jt` latin1 latin1_swedish_ci
DROP VIEW v;
#
# End of 10.6 tests
#
......@@ -421,6 +421,15 @@ DROP TABLE t1;
SET NAMES default;
--echo #
--echo # MDEV-25230 SON_TABLE: CREATE VIEW with 2nd level NESTED PATH ends up with invalid frm, Assertion `m_status == DA_ERROR || m_status == DA_OK || m_status == DA_OK_BULK' failed.
--echo #
CREATE VIEW v AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(NESTED PATH '$' COLUMNS(NESTED PATH '$.*' COLUMNS(o FOR ORDINALITY)))) AS jt;
SELECT * FROM v;
SHOW CREATE VIEW v;
DROP VIEW v;
--echo #
--echo # End of 10.6 tests
--echo #
......@@ -1196,6 +1196,26 @@ void Table_function_json_table::get_estimates(ha_rows *out_rows,
}
/*
Check if a column belongs to the nested path
or a path that nested into it.
It only supposed to be used in the Json_table_nested_path::print, and
since the nested path should have at least one field we
don't have to loop through the m_next_nested.
*/
bool Json_table_nested_path::column_in_this_or_nested(
const Json_table_column *jc) const
{
const Json_table_nested_path *p;
for (p= this; p; p= p->m_nested)
{
if (jc->m_nest == p)
return TRUE;
}
return FALSE;
}
/*
Print the string representation of the Json_nested_path object.
Which is the COLUMNS(...) part of the JSON_TABLE definition.
......@@ -1223,7 +1243,8 @@ int Json_table_nested_path::print(THD *thd, Field ***f, String *str,
return 1;
/* loop while jc belongs to the current or nested paths. */
while(jc && (jc->m_nest == c_path || jc->m_nest == c_nested))
while(jc && (jc->m_nest == c_path ||
c_nested->column_in_this_or_nested(jc)))
{
if (first_column)
first_column= FALSE;
......@@ -1239,7 +1260,7 @@ int Json_table_nested_path::print(THD *thd, Field ***f, String *str,
}
else
{
DBUG_ASSERT(jc->m_nest == c_nested);
DBUG_ASSERT(c_nested->column_in_this_or_nested(jc));
if (str->append("NESTED PATH ") ||
print_path(str, &jc->m_nest->m_path) ||
str->append(' ') ||
......
......@@ -97,6 +97,7 @@ class Json_table_nested_path : public Sql_alloc
/* The child NESTED PATH we're currently scanning */
Json_table_nested_path *m_cur_nested;
bool column_in_this_or_nested(const Json_table_column *jc) const;
friend class Table_function_json_table;
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment