Skip to content

Commit

Permalink
feat: add an optimizer switch params to migration context
Browse files Browse the repository at this point in the history
to be able to pass for example:

`--optimizer-switch="prefer_ordering_index=on"`
  • Loading branch information
cyrinux committed Dec 27, 2022
1 parent 7320fda commit d499039
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions go/base/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ type MigrationContext struct {
CutOverCompleteFlag int64
InCutOverCriticalSectionFlag int64
PanicAbort chan error
OptimizerSwitch string

OriginalTableColumnsOnApplier *sql.ColumnList
OriginalTableColumns *sql.ColumnList
Expand Down
1 change: 1 addition & 0 deletions go/cmd/gh-ost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func main() {
criticalLoad := flag.String("critical-load", "", "Comma delimited status-name=threshold, same format as --max-load. When status exceeds threshold, app panics and quits")
flag.Int64Var(&migrationContext.CriticalLoadIntervalMilliseconds, "critical-load-interval-millis", 0, "When 0, migration immediately bails out upon meeting critical-load. When non-zero, a second check is done after given interval, and migration only bails out if 2nd check still meets critical load")
flag.Int64Var(&migrationContext.CriticalLoadHibernateSeconds, "critical-load-hibernate-seconds", 0, "When non-zero, critical-load does not panic and bail out; instead, gh-ost goes into hibernation for the specified duration. It will not read/write anything from/to any server")
flag.StringVar(&migrationContext.OptimizerSwitch, "optimizer-switch", "", "Optimizer switch params, eg: prefer_ordering_index=on")
quiet := flag.Bool("quiet", false, "quiet")
verbose := flag.Bool("verbose", false, "verbose")
debug := flag.Bool("debug", false, "debug mode (very verbose)")
Expand Down
19 changes: 19 additions & 0 deletions go/logic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ func newDmlBuildResultError(err error) *dmlBuildResult {
}
}

func (this *Applier) setOptimizer(tx *gosql.Tx) error {
if this.migrationContext.OptimizerSwitch == "" {
return nil
}
optimizerString := fmt.Sprintf("set session optimizer_switch=%q", this.migrationContext.OptimizerSwitch)
_, err := tx.Query(optimizerString)
return err
}

// Applier connects and writes the applier-server, which is the server where migration
// happens. This is typically the master, but could be a replica when `--test-on-replica` or
// `--execute-on-replica` are given.
Expand Down Expand Up @@ -477,6 +486,11 @@ func (this *Applier) readMigrationMinValues(tx *gosql.Tx, uniqueKey *sql.UniqueK
return err
}

err = this.setOptimizer(tx)
if err != nil {
return err
}

rows, err := tx.Query(query)
if err != nil {
return err
Expand All @@ -502,6 +516,11 @@ func (this *Applier) readMigrationMaxValues(tx *gosql.Tx, uniqueKey *sql.UniqueK
return err
}

err = this.setOptimizer(tx)
if err != nil {
return err
}

rows, err := tx.Query(query)
if err != nil {
return err
Expand Down

0 comments on commit d499039

Please sign in to comment.