github / gh-ost

GitHub's Online Schema-migration Tool for MySQL
MIT License
12.11k stars 1.23k forks source link

collect table statistics before renaming table #1418

Open wangzihuacool opened 1 month ago

wangzihuacool commented 1 month ago

I encountered an extreme case last week. After alter table using gh-ost, the table statistics was not updated until half an hour later, causing a lot of slow queries. The root cause of this issue is that the statistical event for this table was lost while being placed in the asynchronous queue waiting waiting to be consumed by background statistics update thread.

This may be an extreme case, but since the collection of statististics is performed asynchronously in the background, it is very likely that there will be situations where the statistics are not updated for a period of time after gh-ost modification, especially when there are a large number of tables in the database.

I wrote a script to test gh-ost schema changes thousands of times, and it often happens that the table's statistics were updated 2-3 seconds after gh-ost renames the table. I'm thinking if gh-ost could collect statistics once before renaming table, in order to avoid the issue of statistics not being updated in time after the schema change.

part of test info below:

                              table_name: sbtest1

    table_stats_last_update_time: 2024-05-19 02:07:06

    table_stats_last_update_rows: 134208

        gh_ost_table_create_time: 2024-05-19 10:47:47

        gh_ost_table_rename_time: 2024-05-19 10:47:56

              gh_ost_finish_time: 2024-05-19 10:47:47

  table_stats_after_gh_ost_finish_rows: 0

   table_stats_final_update_time: 2024-05-19 10:47:58

          table_stats_final_rows: 134208`