Skip to content

Commit eec7aa5

Browse files
feat: add an optimizer switch params to migration context
to be able to pass for example: `--optimizer-switch="prefer_ordering_index=on"` Co-authored-by: Tim Vaillancourt <[email protected]>
1 parent 7320fda commit eec7aa5

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

doc/command-line-flags.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ Defaults to 1000 (1 second). Configures the HTTP throttler check timeout in mill
286286

287287
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`.
288288

289+
### optimizer-switch
290+
291+
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`.
292+
You can find values on https://dev.mysql.com/doc/refman/8.0/en/switchable-optimizations.html.
293+
Example: `--optimizer-switch="prefer_ordering_index=on"`.
294+
289295
### tungsten
290296

291297
See [`tungsten`](cheatsheet.md#tungsten) on the cheatsheet.

go/base/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ type MigrationContext struct {
209209
CutOverCompleteFlag int64
210210
InCutOverCriticalSectionFlag int64
211211
PanicAbort chan error
212+
OptimizerSwitch string
212213

213214
OriginalTableColumnsOnApplier *sql.ColumnList
214215
OriginalTableColumns *sql.ColumnList

go/cmd/gh-ost/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ func main() {
139139
criticalLoad := flag.String("critical-load", "", "Comma delimited status-name=threshold, same format as --max-load. When status exceeds threshold, app panics and quits")
140140
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")
141141
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")
142+
flag.StringVar(&migrationContext.OptimizerSwitch, "optimizer-switch", "", "Optimizer switch params, eg: prefer_ordering_index=on")
142143
quiet := flag.Bool("quiet", false, "quiet")
143144
verbose := flag.Bool("verbose", false, "verbose")
144145
debug := flag.Bool("debug", false, "debug mode (very verbose)")

go/logic/applier.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ func newDmlBuildResultError(err error) *dmlBuildResult {
4949
}
5050
}
5151

52+
func (this *Applier) setOptimizerSwitch(tx *gosql.Tx) error {
53+
if this.migrationContext.OptimizerSwitch == "" {
54+
return nil
55+
}
56+
optimizerString := fmt.Sprintf("SET SESSION optimizer_switch=%q", this.migrationContext.OptimizerSwitch)
57+
_, err := tx.Query(optimizerString)
58+
return err
59+
}
60+
5261
// Applier connects and writes the applier-server, which is the server where migration
5362
// happens. This is typically the master, but could be a replica when `--test-on-replica` or
5463
// `--execute-on-replica` are given.
@@ -547,6 +556,11 @@ func (this *Applier) ReadMigrationRangeValues() error {
547556
}
548557
defer tx.Rollback()
549558

559+
err = this.setOptimizerSwitch(tx)
560+
if err != nil {
561+
return err
562+
}
563+
550564
if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil {
551565
return err
552566
}

0 commit comments

Comments
 (0)