diff --git a/mysql-test/r/fts_opt.result b/mysql-test/r/fts_opt.result new file mode 100644 index 00000000000..c74468486d0 --- /dev/null +++ b/mysql-test/r/fts_opt.result @@ -0,0 +1,14 @@ +CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)); +SET GLOBAL innodb_optimize_fulltext_only=ON; +Should be successful. +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status OK +SET DEBUG = '+d, fts_instrument_sync_interrupted'; +Should be failed. +OPTIMIZE TABLE t1; +Table Op Msg_type Msg_text +test.t1 optimize status Operation failed +SET GLOBAL innodb_optimize_fulltext_only=OFF; +SET DEBUG = '-d, fts_instrument_sync_interrupted'; +DROP TABLE t1; diff --git a/mysql-test/t/fts_opt.test b/mysql-test/t/fts_opt.test new file mode 100644 index 00000000000..a4b1351d56d --- /dev/null +++ b/mysql-test/t/fts_opt.test @@ -0,0 +1,14 @@ +CREATE TABLE t1 (a VARCHAR(200), b TEXT, FULLTEXT (a,b)); + +SET GLOBAL innodb_optimize_fulltext_only=ON; + +--echo Should be successful. +OPTIMIZE TABLE t1; + +SET DEBUG = '+d, fts_instrument_sync_interrupted'; +--echo Should be failed. +OPTIMIZE TABLE t1; + +SET GLOBAL innodb_optimize_fulltext_only=OFF; +SET DEBUG = '-d, fts_instrument_sync_interrupted'; +DROP TABLE t1; \ No newline at end of file diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index 919b007f8bc..d810da75508 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -18107,12 +18107,15 @@ int ha_innobase::optimize(THD *, /*!< in: connection thread handle */ calls to OPTIMIZE, which is undesirable. */ if (innodb_optimize_fulltext_only) { + dberr_t err = DB_SUCCESS; if (m_prebuilt->table->fts && m_prebuilt->table->fts->cache && !dict_table_is_discarded(m_prebuilt->table)) { - fts_sync_table(m_prebuilt->table, false, true, false); - fts_optimize_table(m_prebuilt->table); + err = fts_sync_table(m_prebuilt->table, false, true, false); + if (err == DB_SUCCESS) { + err = fts_optimize_table(m_prebuilt->table); + } } - return (HA_ADMIN_OK); + return err == DB_SUCCESS ? HA_ADMIN_OK : HA_ADMIN_FAILED; } else { return (HA_ADMIN_TRY_ALTER); }