revision-id: 5cae53b4bde6b5736633a34eee5e509c0637f99e (mariadb-10.5.2-582-g5cae53b4bde) parent(s): eab2d0bb7ea31e2b4d468516c44d84c3e7768fab author: Sergei Petrunia committer: Sergei Petrunia timestamp: 2021-04-13 12:34:14 +0300 message: MDEV-25397: JSON_TABLE: Unexpected ER_MIX_OF_GROUP_FUNC_AND_FIELDS When doing name resolution, do the same what WHERE/ON clauses do: they don't count in select_lex->non_agg_field_used(). --- mysql-test/suite/json/r/json_table.result | 11 +++++++++++ mysql-test/suite/json/t/json_table.test | 11 +++++++++++ sql/json_table.cc | 6 ++++++ 3 files changed, 28 insertions(+) diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 619aeea985e..998dc84ca35 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -803,5 +803,16 @@ SELECT * FROM v; b DROP VIEW v; # +# MDEV-25397: JSON_TABLE: Unexpected ER_MIX_OF_GROUP_FUNC_AND_FIELDS upon query with JOIN +# +set @save_sql_mode= @@sql_mode; +SET sql_mode='ONLY_FULL_GROUP_BY'; +CREATE TABLE t1 (a TEXT); +SELECT SUM(o) FROM t1 JOIN JSON_TABLE(t1.a, '$' COLUMNS(o FOR ORDINALITY)) jt; +SUM(o) +NULL +set sql_mode=@save_sql_mode; +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 9b31ddeb3b6..636ba2ca2de 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -698,6 +698,17 @@ SELECT * FROM v; DROP VIEW v; +--echo # +--echo # MDEV-25397: JSON_TABLE: Unexpected ER_MIX_OF_GROUP_FUNC_AND_FIELDS upon query with JOIN +--echo # +set @save_sql_mode= @@sql_mode; +SET sql_mode='ONLY_FULL_GROUP_BY'; +CREATE TABLE t1 (a TEXT); +SELECT SUM(o) FROM t1 JOIN JSON_TABLE(t1.a, '$' COLUMNS(o FOR ORDINALITY)) jt; + +set sql_mode=@save_sql_mode; +drop table t1; + --echo # --echo # End of 10.6 tests --echo # diff --git a/sql/json_table.cc b/sql/json_table.cc index fe76f9c44f0..000af50c391 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -1055,9 +1055,15 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table, // table function reference m_context->ignored_tables= get_disallowed_table_deps(s_lex->join, t->map); + // Do the same what setup_without_group() does: do not count the referred + // fields in non_agg_field_used: + const bool saved_non_agg_field_used= s_lex->non_agg_field_used(); + res= m_json->fix_fields_if_needed(thd, &m_json); thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup; + s_lex->set_non_agg_field_used(saved_non_agg_field_used); + if (res) return TRUE; }