diff options
author | Monty <monty@mariadb.org> | 2018-11-27 16:59:29 +0200 |
---|---|---|
committer | Monty <monty@mariadb.org> | 2018-12-09 22:12:27 +0200 |
commit | f386b70beb5742c4b0e3afe8b34cb0897537e375 (patch) | |
tree | a9acb028c265f391a0f47c2781a00d4a9bc64584 /sql/sql_statistics.cc | |
parent | e54643a0637d232f529516de4727b0f976a4e08c (diff) | |
download | mariadb-git-f386b70beb5742c4b0e3afe8b34cb0897537e375.tar.gz |
Honor lock_wait_timeout when updating stats tables
- Call delete_statistics_tables() after lock_table_names in drop tables.
This avoids a deadlock issue with FTWRL and future backup locks.
- Added some missing clear_error()
- Ensure we don't clear error caused by the caller
- Updated function comments
Diffstat (limited to 'sql/sql_statistics.cc')
-rw-r--r-- | sql/sql_statistics.cc | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/sql/sql_statistics.cc b/sql/sql_statistics.cc index 8c88f7f927f..c4b19508c72 100644 --- a/sql/sql_statistics.cc +++ b/sql/sql_statistics.cc @@ -3253,7 +3253,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables) { TABLE_LIST stat_tables[STATISTICS_TABLES]; Open_tables_backup open_tables_backup; - + bool has_error_active= thd->is_error(); DBUG_ENTER("read_statistics_for_tables_if_needed"); DEBUG_SYNC(thd, "statistics_read_start"); @@ -3263,7 +3263,8 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables) if (open_stat_tables(thd, stat_tables, &open_tables_backup, FALSE)) { - thd->clear_error(); + if (!has_error_active) + thd->clear_error(); DBUG_RETURN(1); } @@ -3317,7 +3318,7 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables) 'db' from all statistical tables: table_stats, column_stats, index_stats. @retval - 0 If all deletions are successful + 0 If all deletions are successful or we couldn't open statistics table @retval 1 Otherwise @@ -3325,7 +3326,8 @@ int read_statistics_for_tables_if_needed(THD *thd, TABLE_LIST *tables) The function is called when executing the statement DROP TABLE 'tab'. */ -int delete_statistics_for_table(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *tab) +int delete_statistics_for_table(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *tab) { int err; enum_binlog_format save_binlog_format; @@ -3333,11 +3335,15 @@ int delete_statistics_for_table(THD *thd, const LEX_CSTRING *db, const LEX_CSTRI TABLE_LIST tables[STATISTICS_TABLES]; Open_tables_backup open_tables_backup; int rc= 0; - + bool has_error_active= thd->is_error(); DBUG_ENTER("delete_statistics_for_table"); if (open_stat_tables(thd, tables, &open_tables_backup, TRUE)) - DBUG_RETURN(rc); + { + if (!has_error_active) + thd->clear_error(); + DBUG_RETURN(0); + } save_binlog_format= thd->set_current_stmt_binlog_format_stmt(); @@ -3402,7 +3408,7 @@ int delete_statistics_for_table(THD *thd, const LEX_CSTRING *db, const LEX_CSTRI 'tab' from the statistical table column_stats. @retval - 0 If the deletion is successful + 0 If all deletions are successful or we couldn't open statistics table @retval 1 Otherwise @@ -3419,14 +3425,15 @@ int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col) TABLE_LIST tables; Open_tables_backup open_tables_backup; int rc= 0; - + bool has_error_active= thd->is_error(); DBUG_ENTER("delete_statistics_for_column"); if (open_single_stat_table(thd, &tables, &stat_table_name[1], &open_tables_backup, TRUE)) { - thd->clear_error(); - DBUG_RETURN(rc); + if (!has_error_active) + thd->clear_error(); + DBUG_RETURN(0); } save_binlog_format= thd->set_current_stmt_binlog_format_stmt(); @@ -3468,7 +3475,7 @@ int delete_statistics_for_column(THD *thd, TABLE *tab, Field *col) defined on the table 'tab' from the statistical table index_stats. @retval - 0 If the deletion is successful + 0 If all deletions are successful or we couldn't open statistics table @retval 1 Otherwise @@ -3486,14 +3493,15 @@ int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info, TABLE_LIST tables; Open_tables_backup open_tables_backup; int rc= 0; - + bool has_error_active= thd->is_error(); DBUG_ENTER("delete_statistics_for_index"); if (open_single_stat_table(thd, &tables, &stat_table_name[2], &open_tables_backup, TRUE)) { - thd->clear_error(); - DBUG_RETURN(rc); + if (!has_error_active) + thd->clear_error(); + DBUG_RETURN(0); } save_binlog_format= thd->set_current_stmt_binlog_format_stmt(); @@ -3563,8 +3571,10 @@ int delete_statistics_for_index(THD *thd, TABLE *tab, KEY *key_info, The function is called when executing any statement that renames a table */ -int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *tab, - const LEX_CSTRING *new_db, const LEX_CSTRING *new_tab) +int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *tab, + const LEX_CSTRING *new_db, + const LEX_CSTRING *new_tab) { int err; enum_binlog_format save_binlog_format; @@ -3575,7 +3585,9 @@ int rename_table_in_stat_tables(THD *thd, const LEX_CSTRING *db, const LEX_CSTRI DBUG_ENTER("rename_table_in_stat_tables"); if (open_stat_tables(thd, tables, &open_tables_backup, TRUE)) + { DBUG_RETURN(0); // not an error + } save_binlog_format= thd->set_current_stmt_binlog_format_stmt(); @@ -3667,7 +3679,7 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col, TABLE_LIST tables; Open_tables_backup open_tables_backup; int rc= 0; - + bool has_error_active= thd->is_error(); DBUG_ENTER("rename_column_in_stat_tables"); if (tab->s->tmp_table != NO_TMP_TABLE) @@ -3676,7 +3688,8 @@ int rename_column_in_stat_tables(THD *thd, TABLE *tab, Field *col, if (open_single_stat_table(thd, &tables, &stat_table_name[1], &open_tables_backup, TRUE)) { - thd->clear_error(); + if (!has_error_active) + thd->clear_error(); DBUG_RETURN(rc); } |