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

Online DDL --analyze-table: use non-local ANALYZE TABLE #17462

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion go/vt/vttablet/onlineddl/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/onlineddl/vrepl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

@mattlord mattlord Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so this is only called as part of the analyze step where it makes sense not to replicate it. Versus the cutover step where we continue (pre #7201) to use the replicated variant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct!

if _, err := conn.ExecuteFetch(parsed.Query, 1, false); err != nil {
return err
}
Expand Down
Loading