Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions go/logic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,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 @@ -424,6 +424,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