From a30d7764581471e3e6a724bfb69c5d68139ad407 Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Mon, 6 Jan 2025 08:16:09 +0200 Subject: [PATCH] Online DDL --analyze-table: use non-local ANALYZE TABLE Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/vttablet/onlineddl/executor.go | 4 +++- go/vt/vttablet/onlineddl/schema.go | 3 ++- go/vt/vttablet/onlineddl/vrepl.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/go/vt/vttablet/onlineddl/executor.go b/go/vt/vttablet/onlineddl/executor.go index f8b5cfd9b8d..ce81a2dd516 100644 --- a/go/vt/vttablet/onlineddl/executor.go +++ b/go/vt/vttablet/onlineddl/executor.go @@ -968,7 +968,9 @@ func (e *Executor) cutOverVReplMigration(ctx context.Context, s *VReplStream, sh defer preparationConnRestoreLockWaitTimeout() if needsShadowTableAnalysis { - // Run `ANALYZE TABLE` on the vreplication table so that it has up-to-date statistics at cut-over + // Run `ANALYZE TABLE` on the vreplication table so that it has up-to-date statistics at cut-over. + // The statement will be replicated, so that in case there's a PRS/ERS shortly after cut-over, the + // promoted replica will have good statistics. parsed := sqlparser.BuildParsedQuery(sqlAnalyzeTable, vreplTable) if _, err := preparationsConn.Conn.Exec(ctx, parsed.Query, -1, false); err != nil { // Best effort only. Do not fail the mgiration if this fails. diff --git a/go/vt/vttablet/onlineddl/schema.go b/go/vt/vttablet/onlineddl/schema.go index 943a3b1df07..6ba0217519c 100644 --- a/go/vt/vttablet/onlineddl/schema.go +++ b/go/vt/vttablet/onlineddl/schema.go @@ -499,7 +499,8 @@ const ( sqlDropTable = "DROP TABLE `%a`" sqlDropTableIfExists = "DROP TABLE IF EXISTS `%a`" sqlShowTableStatus = "SHOW TABLE STATUS LIKE '%a'" - sqlAnalyzeTable = "ANALYZE NO_WRITE_TO_BINLOG TABLE `%a`" + sqlAnalyzeTableLocal = "ANALYZE NO_WRITE_TO_BINLOG TABLE `%a`" + sqlAnalyzeTable = "ANALYZE TABLE `%a`" sqlShowCreateTable = "SHOW CREATE TABLE `%a`" sqlShowVariablesLikePreserveForeignKey = "show global variables like 'rename_table_preserve_foreign_key'" sqlShowVariablesLikeFastAnalyzeTable = "show global variables like 'fast_analyze_table'" diff --git a/go/vt/vttablet/onlineddl/vrepl.go b/go/vt/vttablet/onlineddl/vrepl.go index 2761c27c801..b00bcc40894 100644 --- a/go/vt/vttablet/onlineddl/vrepl.go +++ b/go/vt/vttablet/onlineddl/vrepl.go @@ -208,7 +208,7 @@ func (v *VRepl) executeAnalyzeTable(ctx context.Context, conn *dbconnpool.DBConn defer conn.ExecuteFetch(sqlDisableFastAnalyzeTable, 1, false) } - parsed := sqlparser.BuildParsedQuery(sqlAnalyzeTable, tableName) + parsed := sqlparser.BuildParsedQuery(sqlAnalyzeTableLocal, tableName) if _, err := conn.ExecuteFetch(parsed.Query, 1, false); err != nil { return err }