You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
collect table statistics before renaming table #1418
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.
Hi, following up on this, since we've hit this exact issue at Airtable, and have deployed a fix in our fork.
Our version adds the opt-in flag (--analyze-ghost-table-before-cutover, default off) and the docs, and addresses two things we hit in practice:
it runs the ANALYZE after the cut-over postpone gate releases, so a postponed cut-over doesn't re-stale its statistics before the swap
a failed ANALYZE aborts the migration (fatal) rather than swapping in a table with stale stats — ANALYZE TABLE surfaces table-level failures as Msg_type=Error rows while the statement itself succeeds, so we inspect the result rows and fail closed.
It's flag-gated, so the partition-count/replication-lag concern @shaohk raised only applies to opt-in users.
Activity
VandhanaSelvaprakash-at commentedon Jul 29, 2026
Hi, following up on this, since we've hit this exact issue at Airtable, and have deployed a fix in our fork.
Our version adds the opt-in flag (--analyze-ghost-table-before-cutover, default off) and the docs, and addresses two things we hit in practice:
Happy to open a PR that supersedes this one and credits @wangzihuacool as the original author — @timvaillancourt does that work for you?
ericyan commentedon Aug 4, 2026
Hi @VandhanaSelvaprakash-at , please feel to open a new PR (with credits to @wangzihuacool) for this 👍
VandhanaSelvaprakash-at commentedon Aug 5, 2026
Thanks Eric, opened PR #1747 as discussed.
Add opt-in ANALYZE TABLE on the ghost table before cut-over