Skip to content

Commit

Permalink
analyze table before cutover
Browse files Browse the repository at this point in the history
  • Loading branch information
wangzihuacool committed May 23, 2024
1 parent e87e2ab commit 653a951
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions go/logic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,23 @@ func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent))
return nil
}

// AnalyzeTable actively analyze table to ensure that the ghost table's statistics are timely updated
func (this *Applier) AnalyzeTable() {
query := fmt.Sprintf(`analyze table /* gh-ost */ %s.%s`,
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.GetGhostTableName()),
)

this.migrationContext.Log.Infof("Analyzing ghost table %s.%s",
sql.EscapeName(this.migrationContext.DatabaseName),
sql.EscapeName(this.migrationContext.GetGhostTableName()),
)
if _, err := sqlutils.ExecNoPrepare(this.db, query); err != nil {
this.migrationContext.Log.Warningf("Ghost table analyzes failed")
}
this.migrationContext.Log.Infof("Ghost table analyzed")
}

func (this *Applier) Teardown() {
this.migrationContext.Log.Debugf("Tearing down...")
this.db.Close()
Expand Down
3 changes: 3 additions & 0 deletions go/logic/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ func (this *Migrator) Migrate() (err error) {
}
this.printStatus(ForcePrintStatusRule)

// analyze table before cutover
this.applier.AnalyzeTable()

if this.migrationContext.IsCountingTableRows() {
this.migrationContext.Log.Info("stopping query for exact row count, because that can accidentally lock out the cut over")
this.migrationContext.CancelTableRowsCount()
Expand Down

0 comments on commit 653a951

Please sign in to comment.