From 54e61a5c44333f26f8cc822ac47e50f6130044bc Mon Sep 17 00:00:00 2001 From: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> Date: Wed, 20 Apr 2022 07:39:27 +0300 Subject: [PATCH] OnlineDDL: skip GetSchema where possible (#10107) Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com> --- go/vt/schemamanager/tablet_executor.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/go/vt/schemamanager/tablet_executor.go b/go/vt/schemamanager/tablet_executor.go index 995b3f8cafe..4857f592fb1 100644 --- a/go/vt/schemamanager/tablet_executor.go +++ b/go/vt/schemamanager/tablet_executor.go @@ -217,6 +217,17 @@ func (exec *TabletExecutor) isOnlineSchemaDDL(stmt sqlparser.Statement) (isOnlin // 1. Alter more than 100,000 rows. // 2. Change a table with more than 2,000,000 rows (Drops are fine). func (exec *TabletExecutor) detectBigSchemaChanges(ctx context.Context, parsedDDLs []sqlparser.DDLStatement) (bool, error) { + // We want to avoid any overhead if possible. If all DDLs are online schema changes, then we want to + // skip GetSchema altogether. + foundAnyNonOnlineDDL := false + for _, ddl := range parsedDDLs { + if !exec.isOnlineSchemaDDL(ddl) { + foundAnyNonOnlineDDL = true + } + } + if !foundAnyNonOnlineDDL { + return false, nil + } // exec.tablets is guaranteed to have at least one element; // Otherwise, Open should fail and executor should fail. primaryTabletInfo := exec.tablets[0]