From 4fec99a2ba6034592d273d918402540d3d4fe772 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 11 Oct 2022 04:22:05 -0700 Subject: [PATCH 1/6] MDEV-29102 system_time_zone is incorrect on Windows when TZ is set MDEV-19243 introduced a regression on Windows. In (supposedly rare) case, where environment variable TZ was set, @@system_time_zone no longer derives from TZ. Instead, it incorrecty refers to system default time zone, eventhough UTC time conversion takes TZ into account. The fix is to restore TZ-aware handling (timezone name derives from tzname), if TZ is set. --- sql/mysqld.cc | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 6e68876537f..8c70a0d3145 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4303,14 +4303,24 @@ static int init_common_variables() if (ignore_db_dirs_init()) exit(1); -#ifdef _WIN32 - get_win_tzname(system_time_zone, sizeof(system_time_zone)); -#elif defined(HAVE_TZNAME) struct tm tm_tmp; - localtime_r(&server_start_time,&tm_tmp); - const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]; - strmake_buf(system_time_zone, tz_name); -#endif /* HAVE_TZNAME */ + localtime_r(&server_start_time, &tm_tmp); + +#ifdef HAVE_TZNAME +#ifdef _WIN32 + /* + If env.variable TZ is set, derive timezone name from it. + Otherwise, use IANA tz name from get_win_tzname. + */ + if (!getenv("TZ")) + get_win_tzname(system_time_zone, sizeof(system_time_zone)); + else +#endif + { + const char *tz_name= tzname[tm_tmp.tm_isdst != 0 ? 1 : 0]; + strmake_buf(system_time_zone, tz_name); + } +#endif /* We set SYSTEM time zone as reasonable default and From 3cd2c1e8b6fa8435e634360c2ff63f5d645b65dc Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Wed, 17 Aug 2022 18:46:04 +0300 Subject: [PATCH 2/6] MDEV-29299 SELECT from table with vcol index reports warning As of now innodb does not store trx_id for each record in secondary index. The idea behind is following: let us store only per-page max_trx_id, and delete-mark the records when they are deleted/updated. If the read starts, it rememders the lowest id of currently active transaction. Innodb refers to it as trx->read_view->m_up_limit_id. See also ReadView::open. When the page is fetched, its max_trx_id is compared to m_up_limit_id. If the value is lower, and the secondary index record is not delete-marked, then this page is just safe to read as is. Else, a clustered index could be needed ato access. See page_get_max_trx_id call in row_search_mvcc, and the corresponding switch (row_search_idx_cond_check(...)) below. Virtual columns are required to be updated in case if the record was delete-marked. The motivation behind it is documented in Row_sel_get_clust_rec_for_mysql::operator() near row_sel_sec_rec_is_for_clust_rec call. This was basically a description why virtual column computation can normally happen during SELECT, and, generally, a vcol index access. Sometimes stats tables are updated by innodb. This starts a new transaction, and it can happen that it didn't finish to the moment of SELECT execution, forcing virtual columns recomputation. If the result was a something that normally outputs a warning, like division by zero, then it could be outputted in a racy manner. The solution is to suppress the warnings when a column is computed for the described purpose. ignore_wrnings argument is added innobase_get_computed_value. Currently, it is only true for a call from row_sel_sec_rec_is_for_clust_rec. --- .../suite/gcol/r/innodb_virtual_index.result | 31 +++++++++++++++++++ .../suite/gcol/t/innodb_virtual_index.test | 29 +++++++++++++++++ sql/sql_class.h | 15 +++++++++ sql/table.cc | 14 ++++++++- sql/table.h | 2 +- storage/innobase/handler/ha_innodb.cc | 7 +++-- storage/innobase/include/row0mysql.h | 9 ++++-- storage/innobase/row/row0sel.cc | 3 +- storage/mroonga/mrn_mysql_compat.h | 2 +- storage/myisam/ha_myisam.cc | 2 +- 10 files changed, 104 insertions(+), 10 deletions(-) diff --git a/mysql-test/suite/gcol/r/innodb_virtual_index.result b/mysql-test/suite/gcol/r/innodb_virtual_index.result index e63d47391c9..d5ad08cd4bf 100644 --- a/mysql-test/suite/gcol/r/innodb_virtual_index.result +++ b/mysql-test/suite/gcol/r/innodb_virtual_index.result @@ -1,3 +1,4 @@ +SET default_storage_engine= innodb; SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency; SET GLOBAL innodb_purge_rseg_truncate_frequency = 1; # @@ -310,3 +311,33 @@ ALTER TABLE t1 ADD KEY (b), ALGORITHM=INPLACE; # Cleanup DROP TABLE t1; # End of 10.2 tests +# +# MDEV-29299 SELECT from table with vcol index reports warning +# +CREATE TABLE t(fld1 INT NOT NULL, +fld2 INT AS (100/fld1) VIRTUAL, +KEY(fld1), KEY(fld2)); +CREATE TABLE t_odd(id int); +INSERT INTO t(fld1) VALUES(1), (2); +connect stop_purge,localhost,root; +START TRANSACTION WITH CONSISTENT SNAPSHOT; +INSERT INTO t_odd VALUES(10000); +connection default; +UPDATE IGNORE t SET fld1= 3 WHERE fld1= 2; +UPDATE IGNORE t SET fld1= 4 WHERE fld1= 3; +UPDATE IGNORE t SET fld1= 0 WHERE fld1= 4; +Warnings: +Warning 1365 Division by 0 +SELECT fld2 FROM t FORCE INDEX(fld2); +fld2 +NULL +100 +SELECT fld2 FROM t FORCE INDEX(fld1); +fld2 +100 +NULL +Warnings: +Warning 1365 Division by 0 +disconnect stop_purge; +DROP TABLE t, t_odd; +# End of 10.3 tests diff --git a/mysql-test/suite/gcol/t/innodb_virtual_index.test b/mysql-test/suite/gcol/t/innodb_virtual_index.test index 46ffadcdd8c..10a7ac51562 100644 --- a/mysql-test/suite/gcol/t/innodb_virtual_index.test +++ b/mysql-test/suite/gcol/t/innodb_virtual_index.test @@ -1,6 +1,8 @@ --source include/have_innodb.inc --source include/have_sequence.inc +SET default_storage_engine= innodb; + # Ensure that the history list length will actually be decremented by purge. SET @saved_frequency = @@GLOBAL.innodb_purge_rseg_truncate_frequency; SET GLOBAL innodb_purge_rseg_truncate_frequency = 1; @@ -334,3 +336,30 @@ DROP TABLE t1; --echo # End of 10.2 tests +--echo # +--echo # MDEV-29299 SELECT from table with vcol index reports warning +--echo # + +CREATE TABLE t(fld1 INT NOT NULL, + fld2 INT AS (100/fld1) VIRTUAL, + KEY(fld1), KEY(fld2)); +CREATE TABLE t_odd(id int); +INSERT INTO t(fld1) VALUES(1), (2); + +--connect stop_purge,localhost,root +# This prevents purge for records in t +START TRANSACTION WITH CONSISTENT SNAPSHOT; +INSERT INTO t_odd VALUES(10000); + +--connection default +UPDATE IGNORE t SET fld1= 3 WHERE fld1= 2; +UPDATE IGNORE t SET fld1= 4 WHERE fld1= 3; +UPDATE IGNORE t SET fld1= 0 WHERE fld1= 4; +SELECT fld2 FROM t FORCE INDEX(fld2); +SELECT fld2 FROM t FORCE INDEX(fld1); + +--disconnect stop_purge +DROP TABLE t, t_odd; + + +--echo # End of 10.3 tests diff --git a/sql/sql_class.h b/sql/sql_class.h index 7e06f0b0903..4d1f5b40db5 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -1856,6 +1856,21 @@ private: }; +struct Suppress_warnings_error_handler : public Internal_error_handler +{ + bool handle_condition(THD *thd, + uint sql_errno, + const char *sqlstate, + Sql_condition::enum_warning_level *level, + const char *msg, + Sql_condition **cond_hdl) + { + return *level == Sql_condition::WARN_LEVEL_WARN; + } +}; + + + /** Tables that were locked with LOCK TABLES statement. diff --git a/sql/table.cc b/sql/table.cc index 5d91026963a..65b429a1b5a 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8155,12 +8155,22 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode) DBUG_RETURN(in_use->is_error()); } -int TABLE::update_virtual_field(Field *vf) +/* + Calculate the virtual field value for a specified field. + @param vf A field to calculate + @param ignore_warnings Ignore calculation warnings. This usually + means that a calculation is internal and is + not expected to fail. +*/ +int TABLE::update_virtual_field(Field *vf, bool ignore_warnings) { DBUG_ENTER("TABLE::update_virtual_field"); Query_arena backup_arena; Counting_error_handler count_errors; + Suppress_warnings_error_handler warning_handler; in_use->push_internal_handler(&count_errors); + if (ignore_warnings) + in_use->push_internal_handler(&warning_handler); /* TODO: this may impose memory leak until table flush. See comment in @@ -8172,6 +8182,8 @@ int TABLE::update_virtual_field(Field *vf) vf->vcol_info->expr->save_in_field(vf, 0); in_use->restore_active_arena(expr_arena, &backup_arena); in_use->pop_internal_handler(); + if (ignore_warnings) + in_use->pop_internal_handler(); DBUG_RETURN(count_errors.errors); } diff --git a/sql/table.h b/sql/table.h index 1eb09f119ed..577c11c37ee 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1610,7 +1610,7 @@ public: uint actual_n_key_parts(KEY *keyinfo); ulong actual_key_flags(KEY *keyinfo); - int update_virtual_field(Field *vf); + int update_virtual_field(Field *vf, bool ignore_warnings); int update_virtual_fields(handler *h, enum_vcol_update_mode update_mode); int update_default_fields(bool ignore_errors); void evaluate_update_default_function(); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 9ce1915b2cd..0fe60ccabe6 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -21138,7 +21138,8 @@ innobase_get_computed_value( TABLE* mysql_table, byte* mysql_rec, const dict_table_t* old_table, - const upd_t* update) + const upd_t* update, + bool ignore_warnings) { byte rec_buf2[REC_VERSION_56_MAX_INDEX_COL_LEN]; byte* buf; @@ -21236,7 +21237,9 @@ innobase_get_computed_value( MY_BITMAP *old_write_set = dbug_tmp_use_all_columns(mysql_table, &mysql_table->write_set); MY_BITMAP *old_read_set = dbug_tmp_use_all_columns(mysql_table, &mysql_table->read_set); - ret = mysql_table->update_virtual_field(mysql_table->field[col->m_col.ind]); + ret = mysql_table->update_virtual_field( + mysql_table->field[col->m_col.ind], + ignore_warnings); dbug_tmp_restore_column_map(&mysql_table->read_set, old_read_set); dbug_tmp_restore_column_map(&mysql_table->write_set, old_write_set); diff --git a/storage/innobase/include/row0mysql.h b/storage/innobase/include/row0mysql.h index 3e5a7a77333..07f0f56093c 100644 --- a/storage/innobase/include/row0mysql.h +++ b/storage/innobase/include/row0mysql.h @@ -916,7 +916,9 @@ void innobase_report_computed_value_failed(dtuple_t *row); @param[in] old_table during ALTER TABLE, this is the old table or NULL. @param[in] update update vector for the parent row -@param[in] foreign foreign key information +@param[in] ignore_warnings ignore warnings during calculation. Usually + means that a calculation is internal and + should have no side effects. @return the field filled with computed value */ dfield_t* innobase_get_computed_value( @@ -929,8 +931,9 @@ innobase_get_computed_value( THD* thd, TABLE* mysql_table, byte* mysql_rec, - const dict_table_t* old_table, - const upd_t* update); + const dict_table_t* old_table=NULL, + const upd_t* update=NULL, + bool ignore_warnings=false); /** Get the computed value by supplying the base column values. @param[in,out] table the table whose virtual column diff --git a/storage/innobase/row/row0sel.cc b/storage/innobase/row/row0sel.cc index d9b517309c6..ff0f9d47892 100644 --- a/storage/innobase/row/row0sel.cc +++ b/storage/innobase/row/row0sel.cc @@ -329,7 +329,8 @@ row_sel_sec_rec_is_for_clust_rec( &heap, NULL, NULL, thr_get_trx(thr)->mysql_thd, thr->prebuilt->m_mysql_table, - record, NULL, NULL); + record, NULL, NULL, + true); if (vfield == NULL) { innobase_report_computed_value_failed(row); diff --git a/storage/mroonga/mrn_mysql_compat.h b/storage/mroonga/mrn_mysql_compat.h index bdb15637e31..ae1feffb6b8 100644 --- a/storage/mroonga/mrn_mysql_compat.h +++ b/storage/mroonga/mrn_mysql_compat.h @@ -481,7 +481,7 @@ #ifdef MRN_MARIADB_P # if (MYSQL_VERSION_ID >= 100203) # define MRN_GENERATED_COLUMNS_UPDATE_VIRTUAL_FIELD(table, field) \ - (table->update_virtual_field(field)) + (table->update_virtual_field(field,false)) # else # define MRN_GENERATED_COLUMNS_UPDATE_VIRTUAL_FIELD(table, field) \ (field->vcol_info->expr_item->save_in_field(field, 0)) diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index d43ba828957..dfb2cc86ec1 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -681,7 +681,7 @@ static int compute_vcols(MI_INFO *info, uchar *record, int keynum) { Field *f= table->field[kp->fieldnr - 1]; if (f->vcol_info) - table->update_virtual_field(f); + table->update_virtual_field(f, false); } return 0; } From 128356b4b1cf3c8289ac1ba7e69a44d42e06e40c Mon Sep 17 00:00:00 2001 From: Nikita Malyavin Date: Mon, 10 Oct 2022 19:41:09 +0300 Subject: [PATCH 3/6] MDEV-29753 An error is wrongly reported during INSERT with vcol index See also commits aa8a31da and 64678c for a Bug #22990029 fix. In this scenario INSERT chose to check if delete unmarking is available for a just deleted record. To build an update vector, it needed to calculate the vcols as well. Since this INSERT was not IGNORE-flagged, recalculation failed. Solutiuon: temporarily set abort_on_warning=true, while calculating the column for delete-unmarked insert. --- .../suite/gcol/r/innodb_virtual_index.result | 34 ++++++++++++++++++- .../suite/gcol/t/innodb_virtual_index.test | 21 +++++++++++- sql/table.cc | 17 ++++++++-- storage/innobase/include/row0upd.h | 5 ++- storage/innobase/row/row0ins.cc | 2 +- storage/innobase/row/row0log.cc | 2 +- storage/innobase/row/row0upd.cc | 3 +- 7 files changed, 75 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/gcol/r/innodb_virtual_index.result b/mysql-test/suite/gcol/r/innodb_virtual_index.result index d5ad08cd4bf..b0c29da2f22 100644 --- a/mysql-test/suite/gcol/r/innodb_virtual_index.result +++ b/mysql-test/suite/gcol/r/innodb_virtual_index.result @@ -249,12 +249,15 @@ ENGINE=InnoDB; INSERT IGNORE INTO t1 (a,b) VALUES(1,20190132); Warnings: Warning 1265 Data truncated for column 'vb' at row 1 +SELECT * FROM t1; +a b vb +1 20190132 0000-00-00 BEGIN; DELETE FROM t1; INSERT INTO t1 (a,b) VALUES(1,20190123); -ERROR 22007: Incorrect date value: '20190132' for column `test`.`t1`.`vb` at row 1 SELECT * FROM t1; a b vb +1 20190123 2019-01-23 ROLLBACK; SELECT * FROM t1; a b vb @@ -340,4 +343,33 @@ Warnings: Warning 1365 Division by 0 disconnect stop_purge; DROP TABLE t, t_odd; +# +# MDEV-29753 An error is wrongly reported during INSERT with vcol index +# See also Bug #22990029 +# +CREATE TABLE t(pk INT PRIMARY KEY, +fld1 INT NOT NULL, +fld2 INT AS (100/fld1) VIRTUAL, +KEY(fld1), KEY(fld2)); +INSERT IGNORE t(pk, fld1) VALUES(1, 0); +Warnings: +Warning 1365 Division by 0 +SELECT * FROM t; +pk fld1 fld2 +1 0 NULL +Warnings: +Warning 1365 Division by 0 +BEGIN; +DELETE FROM t; +Warnings: +Warning 1365 Division by 0 +Warning 1365 Division by 0 +Warning 1365 Division by 0 +INSERT INTO t (pk, fld1) VALUES(1,1); +SELECT * FROM t; +pk fld1 fld2 +1 1 100 +# Cleanup +ROLLBACK; +DROP TABLE t; # End of 10.3 tests diff --git a/mysql-test/suite/gcol/t/innodb_virtual_index.test b/mysql-test/suite/gcol/t/innodb_virtual_index.test index 10a7ac51562..747a2fdb64c 100644 --- a/mysql-test/suite/gcol/t/innodb_virtual_index.test +++ b/mysql-test/suite/gcol/t/innodb_virtual_index.test @@ -275,9 +275,9 @@ DROP TABLE t1; CREATE TABLE t1(a INT PRIMARY KEY, b INT, vb DATE AS(b) VIRTUAL, KEY(vb)) ENGINE=InnoDB; INSERT IGNORE INTO t1 (a,b) VALUES(1,20190132); +SELECT * FROM t1; BEGIN; DELETE FROM t1; ---error ER_TRUNCATED_WRONG_VALUE INSERT INTO t1 (a,b) VALUES(1,20190123); SELECT * FROM t1; ROLLBACK; @@ -361,5 +361,24 @@ SELECT fld2 FROM t FORCE INDEX(fld1); --disconnect stop_purge DROP TABLE t, t_odd; +--echo # +--echo # MDEV-29753 An error is wrongly reported during INSERT with vcol index +--echo # See also Bug #22990029 +--echo # + +CREATE TABLE t(pk INT PRIMARY KEY, + fld1 INT NOT NULL, + fld2 INT AS (100/fld1) VIRTUAL, + KEY(fld1), KEY(fld2)); +INSERT IGNORE t(pk, fld1) VALUES(1, 0); +SELECT * FROM t; +BEGIN; +DELETE FROM t; +INSERT INTO t (pk, fld1) VALUES(1,1); +SELECT * FROM t; + +--echo # Cleanup +ROLLBACK; +DROP TABLE t; --echo # End of 10.3 tests diff --git a/sql/table.cc b/sql/table.cc index 65b429a1b5a..1d0edf88fb7 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -8158,9 +8158,10 @@ int TABLE::update_virtual_fields(handler *h, enum_vcol_update_mode update_mode) /* Calculate the virtual field value for a specified field. @param vf A field to calculate - @param ignore_warnings Ignore calculation warnings. This usually - means that a calculation is internal and is - not expected to fail. + @param ignore_warnings Ignore the warnings and also make the + calculations permissive. This usually means + that a calculation is internal and is not + expected to fail. */ int TABLE::update_virtual_field(Field *vf, bool ignore_warnings) { @@ -8169,8 +8170,13 @@ int TABLE::update_virtual_field(Field *vf, bool ignore_warnings) Counting_error_handler count_errors; Suppress_warnings_error_handler warning_handler; in_use->push_internal_handler(&count_errors); + bool abort_on_warning; if (ignore_warnings) + { + abort_on_warning= in_use->abort_on_warning; + in_use->abort_on_warning= false; in_use->push_internal_handler(&warning_handler); + } /* TODO: this may impose memory leak until table flush. See comment in @@ -8183,7 +8189,12 @@ int TABLE::update_virtual_field(Field *vf, bool ignore_warnings) in_use->restore_active_arena(expr_arena, &backup_arena); in_use->pop_internal_handler(); if (ignore_warnings) + { + in_use->abort_on_warning= abort_on_warning; in_use->pop_internal_handler(); + // This is an internal calculation, we expect it to always succeed + DBUG_ASSERT(count_errors.errors == 0); + } DBUG_RETURN(count_errors.errors); } diff --git a/storage/innobase/include/row0upd.h b/storage/innobase/include/row0upd.h index c0139ee7911..9721e975a0a 100644 --- a/storage/innobase/include/row0upd.h +++ b/storage/innobase/include/row0upd.h @@ -215,6 +215,8 @@ the equal ordering fields. NOTE: we compare the fields as binary strings! @param[in] offsets rec_get_offsets(rec,index), or NULL @param[in] no_sys skip the system columns DB_TRX_ID and DB_ROLL_PTR +@param[in] ignore_warnings ignore warnings during vcol calculation, which + means that this calculation is internal only @param[in] trx transaction (for diagnostics), or NULL @param[in] heap memory heap from which allocated @@ -230,11 +232,12 @@ row_upd_build_difference_binary( const rec_t* rec, const rec_offs* offsets, bool no_sys, + bool ignore_warnings, trx_t* trx, mem_heap_t* heap, TABLE* mysql_table, dberr_t* error) - MY_ATTRIBUTE((nonnull(1,2,3,7,9), warn_unused_result)); + MY_ATTRIBUTE((nonnull(1,2,3,8,10), warn_unused_result)); /** Apply an update vector to an index entry. @param[in,out] entry index entry to be updated; the clustered index record must be covered by a lock or a page latch to prevent diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index f03381a2fcf..8330e3ef0c8 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -307,7 +307,7 @@ row_ins_clust_index_entry_by_modify( } update = row_upd_build_difference_binary( - cursor->index, entry, rec, NULL, true, + cursor->index, entry, rec, NULL, true, true, thr_get_trx(thr), heap, mysql_table, &err); if (err != DB_SUCCESS) { return(err); diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index c91f5b96617..aa001a84deb 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -2248,7 +2248,7 @@ func_exit_committed: row, NULL, index, heap, ROW_BUILD_NORMAL); upd_t* update = row_upd_build_difference_binary( index, entry, btr_pcur_get_rec(&pcur), cur_offsets, - false, NULL, heap, dup->table, &error); + false, false, NULL, heap, dup->table, &error); if (error != DB_SUCCESS) { goto func_exit; } diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index cadfc181916..599aece23f5 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -1044,6 +1044,7 @@ row_upd_build_difference_binary( const rec_t* rec, const rec_offs* offsets, bool no_sys, + bool ignore_warnings, trx_t* trx, mem_heap_t* heap, TABLE* mysql_table, @@ -1153,7 +1154,7 @@ row_upd_build_difference_binary( dfield_t* vfield = innobase_get_computed_value( update->old_vrow, col, index, &vc.heap, heap, NULL, thd, mysql_table, record, - NULL, NULL); + NULL, NULL, ignore_warnings); if (vfield == NULL) { *error = DB_COMPUTE_VALUE_FAILED; return(NULL); From 5a9a80a213e249a2903446f9f065eb21268d57cd Mon Sep 17 00:00:00 2001 From: Rucha Deodhar Date: Mon, 10 Oct 2022 16:21:46 +0530 Subject: [PATCH 4/6] MDEV-28480: Assertion `0' failed in Item_row::illegal_method_call on SELECT FROM JSON_TABLE Analysis: When fix_fields_if_needed() is called, it doesnt check if operands are valid because check_cols() is not called. So it doesn't error out and eventually crashes. Fix: Use fix_fields_if_needed_for_scalar() instead of fix_fields_if_needed(). It filters the scalar and returns the error if it occurs. --- mysql-test/suite/json/r/json_table.result | 6 ++++++ mysql-test/suite/json/t/json_table.test | 8 ++++++++ sql/item.h | 5 +++++ sql/json_table.cc | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/json/r/json_table.result b/mysql-test/suite/json/r/json_table.result index cc87a34ffb3..b9cc09fdd97 100644 --- a/mysql-test/suite/json/r/json_table.result +++ b/mysql-test/suite/json/r/json_table.result @@ -1005,5 +1005,11 @@ name VARCHAR(10) CHARACTER SET latin1 COLLATE DEFAULT PATH '$.name' name Jeans # +# MDEV-28480: Assertion `0' failed in Item_row::illegal_method_call +# on SELECT FROM JSON_TABLE +# +SELECT 1 FROM JSON_TABLE (row(1,2), '$' COLUMNS (o FOR ORDINALITY)) AS j; +ERROR 21000: Operand should contain 1 column(s) +# # 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 a6392b7bfff..ec330046f25 100644 --- a/mysql-test/suite/json/t/json_table.test +++ b/mysql-test/suite/json/t/json_table.test @@ -863,6 +863,14 @@ SELECT * FROM json_table('[{"name":"Jeans"}]', '$[*]' ) AS jt; +--echo # +--echo # MDEV-28480: Assertion `0' failed in Item_row::illegal_method_call +--echo # on SELECT FROM JSON_TABLE +--echo # + +--error ER_OPERAND_COLUMNS +SELECT 1 FROM JSON_TABLE (row(1,2), '$' COLUMNS (o FOR ORDINALITY)) AS j; + --echo # --echo # End of 10.6 tests --echo # diff --git a/sql/item.h b/sql/item.h index bc7f72e971b..eb231430751 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1143,6 +1143,11 @@ public: { return fixed() ? false : fix_fields(thd, ref); } + + /* + fix_fields_if_needed_for_scalar() is used where we need to filter items + that can't be scalars and want to return error for it. + */ bool fix_fields_if_needed_for_scalar(THD *thd, Item **ref) { return fix_fields_if_needed(thd, ref) || check_cols(1); diff --git a/sql/json_table.cc b/sql/json_table.cc index 73ae4974956..65fe3c9a659 100644 --- a/sql/json_table.cc +++ b/sql/json_table.cc @@ -1171,7 +1171,7 @@ bool Table_function_json_table::setup(THD *thd, TABLE_LIST *sql_table, // fields in non_agg_field_used: const bool saved_non_agg_field_used= s_lex->non_agg_field_used(); - bool res= m_json->fix_fields_if_needed(thd, &m_json); + bool res= m_json->fix_fields_if_needed_for_scalar(thd, &m_json); s_lex->is_item_list_lookup= save_is_item_list_lookup; s_lex->set_non_agg_field_used(saved_non_agg_field_used); From 1f5615360cce22875ae2ab92386704b2ba363d8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20M=C3=A4kel=C3=A4?= Date: Thu, 13 Oct 2022 14:43:35 +0300 Subject: [PATCH 5/6] Silence clang 13 -Wunused-but-set-variable WITH_EMBEDDED_SERVER compiles the SQL parsers separately. Thanks to Vladislav Vaintroub for helping with this. Fixes up commit e05ab0cfc5f52c8c240bfc02239f199081d82f61 --- libmysqld/CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libmysqld/CMakeLists.txt b/libmysqld/CMakeLists.txt index 8886d69851b..070ef3af70d 100644 --- a/libmysqld/CMakeLists.txt +++ b/libmysqld/CMakeLists.txt @@ -29,15 +29,23 @@ ${SSL_INTERNAL_INCLUDE_DIRS} ) SET(GEN_SOURCES -${CMAKE_BINARY_DIR}/sql/sql_yacc.hh +${CMAKE_BINARY_DIR}/sql/sql_yacc.hh ${CMAKE_BINARY_DIR}/sql/sql_yacc.cc ${CMAKE_BINARY_DIR}/sql/sql_yacc_ora.hh ${CMAKE_BINARY_DIR}/sql/sql_yacc_ora.cc -${CMAKE_BINARY_DIR}/sql/lex_hash.h +${CMAKE_BINARY_DIR}/sql/lex_hash.h ) SET_SOURCE_FILES_PROPERTIES(${GEN_SOURCES} PROPERTIES GENERATED TRUE) +IF(CMAKE_C_COMPILER_ID MATCHES "Clang" AND + NOT CMAKE_C_COMPILER_VERSION VERSION_LESS "13.0.0") + ADD_COMPILE_FLAGS( + ${CMAKE_BINARY_DIR}/sql/sql_yacc.cc + ${CMAKE_BINARY_DIR}/sql/sql_yacc_ora.cc + COMPILE_FLAGS "-Wno-unused-but-set-variable") +ENDIF() + SET(SQL_EMBEDDED_SOURCES emb_qcache.cc libmysqld.c lib_sql.cc libmysql.c ../sql-common/errmsg.c ../sql-common/client.c From 0cddb1ac99cbecaddd08bfe5355c034c01c0c406 Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Thu, 13 Oct 2022 13:17:05 +0200 Subject: [PATCH 6/6] v5.5.1-stable --- extra/wolfssl/wolfssl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/wolfssl/wolfssl b/extra/wolfssl/wolfssl index 57aac1c50b4..f1e2165c591 160000 --- a/extra/wolfssl/wolfssl +++ b/extra/wolfssl/wolfssl @@ -1 +1 @@ -Subproject commit 57aac1c50b45275c7a99eca32ad985998b292dc8 +Subproject commit f1e2165c591f074feb47872a8ff712713ec411e1