Skip to content

Commit 6a5f86b

Browse files
author
Alexey Botchkov
committed
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.
1 parent 707d865 commit 6a5f86b

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

mysql-test/suite/json/r/json_table.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,5 +543,16 @@ CREATE TABLE t1 AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(a CHAR(16) PATH '$
543543
DROP TABLE t1;
544544
SET NAMES default;
545545
#
546+
# 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.
547+
#
548+
CREATE VIEW v AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(NESTED PATH '$' COLUMNS(NESTED PATH '$.*' COLUMNS(o FOR ORDINALITY)))) AS jt;
549+
SELECT * FROM v;
550+
o
551+
NULL
552+
SHOW CREATE VIEW v;
553+
View Create View character_set_client collation_connection
554+
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
555+
DROP VIEW v;
556+
#
546557
# End of 10.6 tests
547558
#

mysql-test/suite/json/t/json_table.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,15 @@ DROP TABLE t1;
421421
SET NAMES default;
422422

423423

424+
--echo #
425+
--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.
426+
--echo #
427+
428+
CREATE VIEW v AS SELECT * FROM JSON_TABLE('{}', '$' COLUMNS(NESTED PATH '$' COLUMNS(NESTED PATH '$.*' COLUMNS(o FOR ORDINALITY)))) AS jt;
429+
SELECT * FROM v;
430+
SHOW CREATE VIEW v;
431+
DROP VIEW v;
432+
424433
--echo #
425434
--echo # End of 10.6 tests
426435
--echo #

sql/json_table.cc

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,6 +1196,26 @@ void Table_function_json_table::get_estimates(ha_rows *out_rows,
11961196
}
11971197

11981198

1199+
/*
1200+
Check if a column belongs to the nested path
1201+
or a path that nested into it.
1202+
It only supposed to be used in the Json_table_nested_path::print, and
1203+
since the nested path should have at least one field we
1204+
don't have to loop through the m_next_nested.
1205+
*/
1206+
bool Json_table_nested_path::column_in_this_or_nested(
1207+
const Json_table_column *jc) const
1208+
{
1209+
const Json_table_nested_path *p;
1210+
for (p= this; p; p= p->m_nested)
1211+
{
1212+
if (jc->m_nest == p)
1213+
return TRUE;
1214+
}
1215+
return FALSE;
1216+
}
1217+
1218+
11991219
/*
12001220
Print the string representation of the Json_nested_path object.
12011221
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,
12231243
return 1;
12241244

12251245
/* loop while jc belongs to the current or nested paths. */
1226-
while(jc && (jc->m_nest == c_path || jc->m_nest == c_nested))
1246+
while(jc && (jc->m_nest == c_path ||
1247+
c_nested->column_in_this_or_nested(jc)))
12271248
{
12281249
if (first_column)
12291250
first_column= FALSE;
@@ -1239,7 +1260,7 @@ int Json_table_nested_path::print(THD *thd, Field ***f, String *str,
12391260
}
12401261
else
12411262
{
1242-
DBUG_ASSERT(jc->m_nest == c_nested);
1263+
DBUG_ASSERT(c_nested->column_in_this_or_nested(jc));
12431264
if (str->append("NESTED PATH ") ||
12441265
print_path(str, &jc->m_nest->m_path) ||
12451266
str->append(' ') ||

sql/json_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class Json_table_nested_path : public Sql_alloc
9797
/* The child NESTED PATH we're currently scanning */
9898
Json_table_nested_path *m_cur_nested;
9999

100+
bool column_in_this_or_nested(const Json_table_column *jc) const;
100101
friend class Table_function_json_table;
101102
};
102103

0 commit comments

Comments
 (0)