Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#1235): add an optimizer switch flag to migration context #1236

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions doc/command-line-flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,12 @@ Defaults to 1000 (1 second). Configures the HTTP throttler check timeout in mill

Makes the _old_ table include a timestamp value. The _old_ table is what the original table is renamed to at the end of a successful migration. For example, if the table is `gh_ost_test`, then the _old_ table would normally be `_gh_ost_test_del`. With `--timestamp-old-table` it would be, for example, `_gh_ost_test_20170221103147_del`.

### optimizer-switch

Default is "", this allow to override a `SET GLOBAL optimizer_switch=key=value` by one set on the session with `SET SESSION optimizer_switch=key=value`.
You can find values on https://dev.mysql.com/doc/refman/8.0/en/switchable-optimizations.html.
Example: `--optimizer-switch="prefer_ordering_index=on"`.

### tungsten

See [`tungsten`](cheatsheet.md#tungsten) on the cheatsheet.
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")
cyrinux marked this conversation as resolved.
Show resolved Hide resolved
quiet := flag.Bool("quiet", false, "quiet")
verbose := flag.Bool("verbose", false, "verbose")
debug := flag.Bool("debug", false, "debug mode (very verbose)")
Expand Down
14 changes: 14 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) setOptimizerSwitch(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 @@ -547,6 +556,11 @@ func (this *Applier) ReadMigrationRangeValues() error {
}
defer tx.Rollback()

err = this.setOptimizerSwitch(tx)
cyrinux marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return err
}

if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil {
return err
}
Expand Down