{"record":{"id":"2d12d715cd8867c2","repo":"vitessio/vitess","slug":"deferring-secondary-key-creation-is-not-supported","errorCode":null,"errorMessage":"deferring secondary key creation is not supported for %s workflows","messagePattern":"deferring secondary key creation is not supported for (.+?) workflows","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vreplicator.go","lineNumber":788,"sourceCode":"\n\tisPKMap := map[string]bool{}\n\tfor i, colName := range uniqueKeyColumnNames {\n\t\tcolumnOrderMap[colName] = int64(i)\n\t\tisPKMap[colName] = true\n\t}\n\tsort.SliceStable(pkColInfos, func(i, j int) bool { return columnOrderMap[pkColInfos[i].Name] < columnOrderMap[pkColInfos[j].Name] })\n\tfor i := range pkColInfos {\n\t\tpkColInfos[i].IsPK = isPKMap[pkColInfos[i].Name]\n\t}\n\treturn pkColInfos\n}\n\n// stashSecondaryKeys temporarily DROPs all secondary keys from the table schema\n// and stashes an ALTER TABLE statement that will be used to recreate them at the\n// end of the copy phase.\nfunc (vr *vreplicator) stashSecondaryKeys(ctx context.Context, tableName string) error {\n\tif !vr.supportsDeferredSecondaryKeys() {\n\t\treturn fmt.Errorf(\"deferring secondary key creation is not supported for %s workflows\",\n\t\t\tbinlogdatapb.VReplicationWorkflowType_name[vr.WorkflowType])\n\t}\n\tsecondaryKeys, err := vr.getTableSecondaryKeys(ctx, tableName)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(secondaryKeys) > 0 {\n\t\talterDrop := &sqlparser.AlterTable{\n\t\t\tTable: sqlparser.TableName{\n\t\t\t\tQualifier: sqlparser.NewIdentifierCS(vr.dbClient.DBName()),\n\t\t\t\tName:      sqlparser.NewIdentifierCS(tableName),\n\t\t\t},\n\t\t}\n\t\talterReAdd := &sqlparser.AlterTable{\n\t\t\tTable: sqlparser.TableName{\n\t\t\t\tQualifier: sqlparser.NewIdentifierCS(vr.dbClient.DBName()),\n\t\t\t\tName:      sqlparser.NewIdentifierCS(tableName),\n\t\t\t},","sourceCodeStart":770,"sourceCodeEnd":806,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vreplicator.go#L770-L806","documentation":"stashSecondaryKeys drops secondary indexes before a table copy and re-creates them afterwards to speed up copying. This optimization is only supported for certain workflow types (checked via supportsDeferredSecondaryKeys). If invoked for an unsupported workflow, this error names the workflow type and aborts the key-deferral path.","triggerScenarios":"stashSecondaryKeys called (from initTablesForCopy or a post-copy callback) with vr.WorkflowType not in the supported set — e.g. legacy/custom workflows rather than MoveTables/Reshard/Migrate where deferral is implemented.","commonSituations":"Running a newer Vitess feature path against a workflow type that predates the optimization; custom or v2 workflows; workflows created before the feature existed and carrying a zero/unknown WorkflowType value.","solutions":["Verify the workflow's type in _vt.vreplication (workflow_type column); only MoveTables/Reshard/Migrate-style workflows support deferred secondary keys.","Upgrade Vitess if the workflow should be supported — support has been expanding across releases.","Proceed without deferral: the copy will run with secondary indexes in place (slower but correct); no manual action needed for correctness.","If copy speed is the concern, manually drop secondary indexes before the copy and re-add them after, outside the workflow machinery."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// Check the workflow type before expecting deferred secondary keys:\n// SELECT workflow_type FROM _vt.vreplication WHERE id = <id>;\n// Only MoveTables/Reshard/Migrate-style types support it.","typeGuard":null,"tryCatchPattern":"if err := vr.stashSecondaryKeys(ctx, tableName); err != nil {\n\tlog.Warn(\"secondary key deferral unsupported; copying with indexes in place\", slog.Any(\"error\", err))\n\t// fall back to normal copy path (correct, only slower)\n}","preventionTips":["Use current Vitess for MoveTables/Reshard to get the optimization.","Don't assume the deferral feature applies to custom/legacy workflow types.","If copy speed matters on unsupported types, drop indexes manually pre-copy and re-add post-copy.","Track release notes for expanding workflow-type support."],"tags":["vreplication","schema","secondary-index","copy-phase"],"backgroundTag":"deferred-secondary-keys-unsupported","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}