From 66211eef7b02d8a5ef103648d618ce2552e13db8 Mon Sep 17 00:00:00 2001 From: Cyril Levis Date: Tue, 27 Dec 2022 19:58:55 +0100 Subject: [PATCH] chore: fix first review --- doc/command-line-flags.md | 6 ++++++ go/logic/applier.go | 17 ++++++----------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/doc/command-line-flags.md b/doc/command-line-flags.md index 021462fa2..e88017e5c 100644 --- a/doc/command-line-flags.md +++ b/doc/command-line-flags.md @@ -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. diff --git a/go/logic/applier.go b/go/logic/applier.go index 48ad2be27..506fcd4d1 100644 --- a/go/logic/applier.go +++ b/go/logic/applier.go @@ -49,7 +49,7 @@ func newDmlBuildResultError(err error) *dmlBuildResult { } } -func (this *Applier) setOptimizer(tx *gosql.Tx) error { +func (this *Applier) setOptimizerSwitch(tx *gosql.Tx) error { if this.migrationContext.OptimizerSwitch == "" { return nil } @@ -486,11 +486,6 @@ 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 @@ -516,11 +511,6 @@ 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 @@ -566,6 +556,11 @@ func (this *Applier) ReadMigrationRangeValues() error { } defer tx.Rollback() + err = this.setOptimizerSwitch(tx) + if err != nil { + return err + } + if err := this.readMigrationMinValues(tx, this.migrationContext.UniqueKey); err != nil { return err }