Commit 991bfebe authored by Alexey Botchkov's avatar Alexey Botchkov

MDEV-25379 JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list.

If a field is not in the read set - read it in the local buffer anyway to check for errors.
parent 1eda21be
...@@ -813,6 +813,14 @@ SUM(o) ...@@ -813,6 +813,14 @@ SUM(o)
NULL NULL
set sql_mode=@save_sql_mode; set sql_mode=@save_sql_mode;
drop table t1; drop table t1;
# MDEV-25379 JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list.
#
SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
ERROR HY000: Field 'a' can't be set for JSON_TABLE 'jt'.
# #
# End of 10.6 tests # End of 10.6 tests
# #
...@@ -709,6 +709,15 @@ SELECT SUM(o) FROM t1 JOIN JSON_TABLE(t1.a, '$' COLUMNS(o FOR ORDINALITY)) jt; ...@@ -709,6 +709,15 @@ SELECT SUM(o) FROM t1 JOIN JSON_TABLE(t1.a, '$' COLUMNS(o FOR ORDINALITY)) jt;
set sql_mode=@save_sql_mode; set sql_mode=@save_sql_mode;
drop table t1; drop table t1;
--echo # MDEV-25379 JSON_TABLE: ERROR ON clauses are ignored if a column is not on select list.
--echo #
--error ER_JSON_TABLE_ERROR_ON_FIELD
SELECT * FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
--error ER_JSON_TABLE_ERROR_ON_FIELD
SELECT o FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
--error ER_JSON_TABLE_ERROR_ON_FIELD
SELECT COUNT(*) FROM JSON_TABLE ('{}', '$' COLUMNS(a INT PATH '$.*' ERROR ON EMPTY, o FOR ORDINALITY)) AS jt;
--echo # --echo #
--echo # End of 10.6 tests --echo # End of 10.6 tests
--echo # --echo #
...@@ -480,7 +480,8 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort, ...@@ -480,7 +480,8 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
thd->killed == ABORT_QUERY ? "" : thd->killed == ABORT_QUERY ? "" :
thd->get_stmt_da()->message()); thd->get_stmt_da()->message());
if (global_system_variables.log_warnings > 1) if ((thd->killed == ABORT_QUERY || kill_errno) &&
global_system_variables.log_warnings > 1)
{ {
sql_print_warning("%s, host: %s, user: %s, thread: %lu, query: %-.4096s", sql_print_warning("%s, host: %s, user: %s, thread: %lu, query: %-.4096s",
ER_THD(thd, ER_FILSORT_ABORT), ER_THD(thd, ER_FILSORT_ABORT),
......
...@@ -419,22 +419,32 @@ int ha_json_table::rnd_next(uchar *buf) ...@@ -419,22 +419,32 @@ int ha_json_table::rnd_next(uchar *buf)
int ha_json_table::fill_column_values(uchar * buf, uchar *pos) int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
{ {
MY_BITMAP *orig_map= dbug_tmp_use_all_columns(table, &table->write_set);
int error= 0;
Field **f= table->field; Field **f= table->field;
Json_table_column *jc; Json_table_column *jc;
List_iterator_fast<Json_table_column> jc_i(m_jt->m_columns); List_iterator_fast<Json_table_column> jc_i(m_jt->m_columns);
my_ptrdiff_t ptrdiff= buf - table->record[0]; my_ptrdiff_t ptrdiff= buf - table->record[0];
Abort_on_warning_instant_set ao_set(table->in_use, FALSE); Abort_on_warning_instant_set ao_set(table->in_use, FALSE);
while ((jc= jc_i++)) while (!error && (jc= jc_i++))
{ {
bool is_null_value; bool is_null_value;
uint int_pos= 0; /* just to make compilers happy. */ uint int_pos= 0; /* just to make compilers happy. */
if (!bitmap_is_set(table->read_set, (*f)->field_index)) if (!bitmap_is_set(table->read_set, (*f)->field_index))
{
/*
If the RESPONSE_ERROR is set for the column, we have
to unpack it even if it's not in the read_set - to check
for possible errors.
*/
if (jc->m_on_empty.m_response != Json_table_column::RESPONSE_ERROR &&
jc->m_on_error.m_response != Json_table_column::RESPONSE_ERROR)
goto cont_loop; goto cont_loop;
}
if (ptrdiff) (*f)->move_field_offset(ptrdiff);
(*f)->move_field_offset(ptrdiff);
/* /*
Read the NULL flag: Read the NULL flag:
...@@ -507,16 +517,15 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos) ...@@ -507,16 +517,15 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
{ {
if (not_found) if (not_found)
{ {
if (jc->m_on_empty.respond(jc, *f, ER_JSON_TABLE_ERROR_ON_FIELD)) error= jc->m_on_empty.respond(jc, *f, ER_JSON_TABLE_ERROR_ON_FIELD);
goto error_return;
} }
else else
{ {
if (!json_value_scalar(&je) || if (!json_value_scalar(&je) ||
store_json_in_field(*f, &je)) store_json_in_field(*f, &je))
{ {
if (jc->m_on_error.respond(jc, *f, ER_JSON_TABLE_SCALAR_EXPECTED)) error= jc->m_on_error.respond(jc, *f,
goto error_return; ER_JSON_TABLE_SCALAR_EXPECTED);
} }
else else
{ {
...@@ -530,8 +539,8 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos) ...@@ -530,8 +539,8 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
!json_find_path(&je, &jc->m_path, &cur_step, !json_find_path(&je, &jc->m_path, &cur_step,
array_counters))) array_counters)))
{ {
if (jc->m_on_error.respond(jc, *f, ER_JSON_TABLE_MULTIPLE_MATCHES)) error= jc->m_on_error.respond(jc, *f,
goto error_return; ER_JSON_TABLE_MULTIPLE_MATCHES);
} }
} }
} }
...@@ -540,16 +549,16 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos) ...@@ -540,16 +549,16 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
} }
}; };
} }
if (ptrdiff) (*f)->move_field_offset(-ptrdiff);
(*f)->move_field_offset(-ptrdiff);
cont_loop: cont_loop:
f++; f++;
if (pos) if (pos)
pos+= 4; pos+= 4;
} }
return 0;
error_return: dbug_tmp_restore_column_map(&table->write_set, orig_map);
return 1; return error;
} }
......
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