Skip to content

Commit

Permalink
Online DDL --analyze-table: use non-local ANALYZE TABLE
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach committed Jan 6, 2025
1 parent b1f6147 commit a30d776
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,9 @@ func (e *Executor) cutOverVReplMigration(ctx context.Context, s *VReplStream, sh
defer preparationConnRestoreLockWaitTimeout()

if needsShadowTableAnalysis {
// Run `ANALYZE TABLE` on the vreplication table so that it has up-to-date statistics at cut-over
// Run `ANALYZE TABLE` on the vreplication table so that it has up-to-date statistics at cut-over.
// The statement will be replicated, so that in case there's a PRS/ERS shortly after cut-over, the
// promoted replica will have good statistics.
parsed := sqlparser.BuildParsedQuery(sqlAnalyzeTable, vreplTable)
if _, err := preparationsConn.Conn.Exec(ctx, parsed.Query, -1, false); err != nil {
// Best effort only. Do not fail the mgiration if this fails.
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vttablet/onlineddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,8 @@ const (
sqlDropTable = "DROP TABLE `%a`"
sqlDropTableIfExists = "DROP TABLE IF EXISTS `%a`"
sqlShowTableStatus = "SHOW TABLE STATUS LIKE '%a'"
sqlAnalyzeTable = "ANALYZE NO_WRITE_TO_BINLOG TABLE `%a`"
sqlAnalyzeTableLocal = "ANALYZE NO_WRITE_TO_BINLOG TABLE `%a`"
sqlAnalyzeTable = "ANALYZE TABLE `%a`"
sqlShowCreateTable = "SHOW CREATE TABLE `%a`"
sqlShowVariablesLikePreserveForeignKey = "show global variables like 'rename_table_preserve_foreign_key'"
sqlShowVariablesLikeFastAnalyzeTable = "show global variables like 'fast_analyze_table'"
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/onlineddl/vrepl.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func (v *VRepl) executeAnalyzeTable(ctx context.Context, conn *dbconnpool.DBConn
defer conn.ExecuteFetch(sqlDisableFastAnalyzeTable, 1, false)
}

parsed := sqlparser.BuildParsedQuery(sqlAnalyzeTable, tableName)
parsed := sqlparser.BuildParsedQuery(sqlAnalyzeTableLocal, tableName)
if _, err := conn.ExecuteFetch(parsed.Query, 1, false); err != nil {
return err
}
Expand Down

0 comments on commit a30d776

Please sign in to comment.