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)
NULL
set sql_mode=@save_sql_mode;
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
#
......@@ -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;
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 # End of 10.6 tests
--echo #
......@@ -480,7 +480,8 @@ SORT_INFO *filesort(THD *thd, TABLE *table, Filesort *filesort,
thd->killed == ABORT_QUERY ? "" :
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",
ER_THD(thd, ER_FILSORT_ABORT),
......
......@@ -419,21 +419,31 @@ int ha_json_table::rnd_next(uchar *buf)
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;
Json_table_column *jc;
List_iterator_fast<Json_table_column> jc_i(m_jt->m_columns);
my_ptrdiff_t ptrdiff= buf - table->record[0];
Abort_on_warning_instant_set ao_set(table->in_use, FALSE);
while ((jc= jc_i++))
while (!error && (jc= jc_i++))
{
bool is_null_value;
uint int_pos= 0; /* just to make compilers happy. */
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;
}
if (ptrdiff)
(*f)->move_field_offset(ptrdiff);
/*
......@@ -507,16 +517,15 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
{
if (not_found)
{
if (jc->m_on_empty.respond(jc, *f, ER_JSON_TABLE_ERROR_ON_FIELD))
goto error_return;
error= jc->m_on_empty.respond(jc, *f, ER_JSON_TABLE_ERROR_ON_FIELD);
}
else
{
if (!json_value_scalar(&je) ||
store_json_in_field(*f, &je))
{
if (jc->m_on_error.respond(jc, *f, ER_JSON_TABLE_SCALAR_EXPECTED))
goto error_return;
error= jc->m_on_error.respond(jc, *f,
ER_JSON_TABLE_SCALAR_EXPECTED);
}
else
{
......@@ -530,8 +539,8 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
!json_find_path(&je, &jc->m_path, &cur_step,
array_counters)))
{
if (jc->m_on_error.respond(jc, *f, ER_JSON_TABLE_MULTIPLE_MATCHES))
goto error_return;
error= jc->m_on_error.respond(jc, *f,
ER_JSON_TABLE_MULTIPLE_MATCHES);
}
}
}
......@@ -540,16 +549,16 @@ int ha_json_table::fill_column_values(uchar * buf, uchar *pos)
}
};
}
if (ptrdiff)
(*f)->move_field_offset(-ptrdiff);
cont_loop:
f++;
if (pos)
pos+= 4;
}
return 0;
error_return:
return 1;
dbug_tmp_restore_column_map(&table->write_set, orig_map);
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