Skip to content

Commit a964080

Browse files
spetruniaAlexey Botchkov
authored andcommitted
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().
1 parent f82947e commit a964080

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,5 +803,16 @@ SELECT * FROM v;
803803
b
804804
DROP VIEW v;
805805
#
806+
# MDEV-25397: JSON_TABLE: Unexpected ER_MIX_OF_GROUP_FUNC_AND_FIELDS upon query with JOIN
807+
#
808+
set @save_sql_mode= @@sql_mode;
809+
SET sql_mode='ONLY_FULL_GROUP_BY';
810+
CREATE TABLE t1 (a TEXT);
811+
SELECT SUM(o) FROM t1 JOIN JSON_TABLE(t1.a, '$' COLUMNS(o FOR ORDINALITY)) jt;
812+
SUM(o)
813+
NULL
814+
set sql_mode=@save_sql_mode;
815+
drop table t1;
816+
#
806817
# End of 10.6 tests
807818
#

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,17 @@ SELECT * FROM v;
698698

699699
DROP VIEW v;
700700

701+
--echo #
702+
--echo # MDEV-25397: JSON_TABLE: Unexpected ER_MIX_OF_GROUP_FUNC_AND_FIELDS upon query with JOIN
703+
--echo #
704+
set @save_sql_mode= @@sql_mode;
705+
SET sql_mode='ONLY_FULL_GROUP_BY';
706+
CREATE TABLE t1 (a TEXT);
707+
SELECT SUM(o) FROM t1 JOIN JSON_TABLE(t1.a, '$' COLUMNS(o FOR ORDINALITY)) jt;
708+
709+
set sql_mode=@save_sql_mode;
710+
drop table t1;
711+
701712
--echo #
702713
--echo # End of 10.6 tests
703714
--echo #

sql/json_table.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,15 @@ int Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table,
10551055
// table function reference
10561056
m_context->ignored_tables= get_disallowed_table_deps(s_lex->join, t->map);
10571057

1058+
// Do the same what setup_without_group() does: do not count the referred
1059+
// fields in non_agg_field_used:
1060+
const bool saved_non_agg_field_used= s_lex->non_agg_field_used();
1061+
10581062
res= m_json->fix_fields_if_needed(thd, &m_json);
10591063

10601064
thd->lex->current_select->is_item_list_lookup= save_is_item_list_lookup;
1065+
s_lex->set_non_agg_field_used(saved_non_agg_field_used);
1066+
10611067
if (res)
10621068
return TRUE;
10631069
}

0 commit comments

Comments
 (0)