From 991bfebe8fe6845b3a72e6b02608dcaa3441d917 Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 13 Apr 2021 14:18:04 +0400 Subject: [PATCH] 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. --- mysql-test/suite/json/r/json_table.result | 8 +++++ mysql-test/suite/json/t/json_table.test | 9 ++++++ sql/filesort.cc | 3 +- sql/json_table.cc | 37 ++++++++++++++--------- 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index 998dc84ca35..34f25f316d4 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -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 # diff --git a/mysql-test/suite/json/t/json_table.test b/mysql-test/suite/json/t/json_table.test index 636ba2ca2de..e5f2c26c67f 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -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 # diff --git a/sql/filesort.cc b/sql/filesort.cc index 0337325b544..8f74059cb0d 100644 --- a/sql/filesort.cc +++ b/sql/filesort.cc @@ -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), diff --git a/sql/json_table.cc b/sql/json_table.cc index 5302fbd94c3..2e890aa8c22 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -419,22 +419,32 @@ 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 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); + (*f)->move_field_offset(ptrdiff); /* Read the NULL flag: @@ -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); + (*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; }