Commit 5a9a80a2 authored by Rucha Deodhar's avatar Rucha Deodhar

MDEV-28480: Assertion `0' failed in Item_row::illegal_method_call on

SELECT FROM JSON_TABLE

Analysis: When fix_fields_if_needed() is called, it doesnt check if operands
are valid because check_cols() is not called. So it doesn't error out and
eventually crashes.
Fix: Use fix_fields_if_needed_for_scalar() instead of
fix_fields_if_needed(). It filters the scalar and returns the error if
it occurs.
parent 1feccb50
...@@ -1005,5 +1005,11 @@ name VARCHAR(10) CHARACTER SET latin1 COLLATE DEFAULT PATH '$.name' ...@@ -1005,5 +1005,11 @@ name VARCHAR(10) CHARACTER SET latin1 COLLATE DEFAULT PATH '$.name'
name name
Jeans Jeans
# #
# MDEV-28480: Assertion `0' failed in Item_row::illegal_method_call
# on SELECT FROM JSON_TABLE
#
SELECT 1 FROM JSON_TABLE (row(1,2), '$' COLUMNS (o FOR ORDINALITY)) AS j;
ERROR 21000: Operand should contain 1 column(s)
#
# End of 10.6 tests # End of 10.6 tests
# #
...@@ -863,6 +863,14 @@ SELECT * FROM json_table('[{"name":"Jeans"}]', '$[*]' ...@@ -863,6 +863,14 @@ SELECT * FROM json_table('[{"name":"Jeans"}]', '$[*]'
) AS jt; ) AS jt;
--echo #
--echo # MDEV-28480: Assertion `0' failed in Item_row::illegal_method_call
--echo # on SELECT FROM JSON_TABLE
--echo #
--error ER_OPERAND_COLUMNS
SELECT 1 FROM JSON_TABLE (row(1,2), '$' COLUMNS (o FOR ORDINALITY)) AS j;
--echo # --echo #
--echo # End of 10.6 tests --echo # End of 10.6 tests
--echo # --echo #
...@@ -1143,6 +1143,11 @@ class Item :public Value_source, ...@@ -1143,6 +1143,11 @@ class Item :public Value_source,
{ {
return fixed() ? false : fix_fields(thd, ref); return fixed() ? false : fix_fields(thd, ref);
} }
/*
fix_fields_if_needed_for_scalar() is used where we need to filter items
that can't be scalars and want to return error for it.
*/
bool fix_fields_if_needed_for_scalar(THD *thd, Item **ref) bool fix_fields_if_needed_for_scalar(THD *thd, Item **ref)
{ {
return fix_fields_if_needed(thd, ref) || check_cols(1); return fix_fields_if_needed(thd, ref) || check_cols(1);
......
...@@ -1171,7 +1171,7 @@ bool Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table, ...@@ -1171,7 +1171,7 @@ bool Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table,
// fields in non_agg_field_used: // fields in non_agg_field_used:
const bool saved_non_agg_field_used= s_lex->non_agg_field_used(); const bool saved_non_agg_field_used= s_lex->non_agg_field_used();
bool res= m_json->fix_fields_if_needed(thd, &m_json); bool res= m_json->fix_fields_if_needed_for_scalar(thd, &m_json);
s_lex->is_item_list_lookup= save_is_item_list_lookup; s_lex->is_item_list_lookup= save_is_item_list_lookup;
s_lex->set_non_agg_field_used(saved_non_agg_field_used); s_lex->set_non_agg_field_used(saved_non_agg_field_used);
......
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