diff options
author | Sergei Petrunia <psergey@askmonty.org> | 2021-04-13 12:34:14 +0300 |
---|---|---|
committer | Alexey Botchkov <holyfoot@askmonty.org> | 2021-04-21 10:21:47 +0400 |
commit | a96408092c38800c2befadaec64bc8ab71fe4b41 (patch) | |
tree | 41cc5dc78112923660337c0402b7d61d726a1313 | |
parent | f82947e48d689bcc175c21bea2aa6458934682d0 (diff) | |
download | mariadb-git-a96408092c38800c2befadaec64bc8ab71fe4b41.tar.gz |
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().
-rw-r--r-- | mysql-test/suite/json/r/json_table.result | 11 | ||||
-rw-r--r-- | mysql-test/suite/json/t/json_table.test | 11 | ||||
-rw-r--r-- | sql/json_table.cc | 6 |
3 files changed, 28 insertions, 0 deletions
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 @@ -699,5 +699,16 @@ 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; } |