{"record":{"id":"0c7a57002103954d","repo":"vitessio/vitess","slug":"vt13001","errorCode":"VT13001","errorMessage":"err.Error()","messagePattern":"err\\.Error\\(\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/planbuilder/operators/delete.go","lineNumber":167,"sourceCode":"\n\tif del.Comments != nil {\n\t\top = newLockAndComment(op, del.Comments, sqlparser.NoLock)\n\t}\n\treturn op\n}\n\n// getFirstVindex returns the first Vindex, if available\nfunc getFirstVindex(vTbl *vindexes.BaseTable) vindexes.Vindex {\n\tif len(vTbl.ColumnVindexes) > 0 {\n\t\treturn vTbl.ColumnVindexes[0].Vindex\n\t}\n\treturn nil\n}\n\nfunc createDeleteOpWithTarget(ctx *plancontext.PlanningContext, target semantics.TableSet, ignore sqlparser.Ignore) dmlOp {\n\tti, err := ctx.SemTable.TableInfoFor(target)\n\tif err != nil {\n\t\tpanic(vterrors.VT13001(err.Error()))\n\t}\n\n\tvTbl := ti.GetVindexTable()\n\tif len(vTbl.PrimaryKey) == 0 {\n\t\tpanic(vterrors.VT09015())\n\t}\n\ttblName, err := ti.Name()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tleftComp := make(sqlparser.ValTuple, 0, len(vTbl.PrimaryKey))\n\tcols := make([]*sqlparser.ColName, 0, len(vTbl.PrimaryKey))\n\tfor _, col := range vTbl.PrimaryKey {\n\t\tcolName := sqlparser.NewColNameWithQualifier(col.String(), tblName)\n\t\tcols = append(cols, colName)\n\t\tleftComp = append(leftComp, colName)\n\t\tctx.SemTable.Recursive[colName] = target","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/planbuilder/operators/delete.go#L149-L185","documentation":"VT13001 is thrown when createDeleteOpWithTarget cannot fetch TableInfo for a DML target table set. Delete-with-input planning resolves each DML target constituent of the statement; if TableInfoFor returns an error (table not found in the semantic table for that TableSet), the planner wraps the underlying message in VT13001 ('table not found in vschema'). It indicates the delete targets a table that semantic analysis could not map.","triggerScenarios":"Multi-table DELETE (e.g. DELETE t1, t2 FROM ...) or DELETE with LIMIT on FK-related tables triggers delete-with-input planning; for one of the SemTable.DMLTargets constituents, ctx.SemTable.TableInfoFor(target) fails.","commonSituations":"Multi-table deletes referencing tables not present/authorized in the keyspace vschema; typos in qualified names inside multi-table DELETE syntax; stale vschema after a table rename during a rolling migration.","solutions":["Read the VT13001 message to identify the unresolved table and confirm it exists in the target keyspace's vschema.","Rewrite the multi-table DELETE as separate single-table DELETE statements.","If FK-driven input planning is the trigger, remove the LIMIT clause or restructure so delete-with-input planning isn't required.","Refresh/redeploy the vschema if the table was recently added or renamed."],"exampleFix":"// before\nDELETE orders, order_items FROM orders JOIN order_items ON orders.id = order_items.order_id WHERE orders.created_at < '2024-01-01';\n\n// after\nDELETE FROM orders WHERE created_at < '2024-01-01';\nDELETE FROM order_items WHERE order_id NOT IN (SELECT id FROM orders);","handlingStrategy":"validation","validationCode":"// validate all targets of a multi-table DELETE resolve before executing\nfor _, target := range deleteTargets(sql) {\n    if !keyspaceHasTable(defaultKeyspace, target) {\n        return fmt.Errorf(\"VT13001 guard: target %s not found in keyspace %s\", target, defaultKeyspace)\n    }\n}","typeGuard":"func isVT13001(err error) bool {\n    return strings.Contains(err.Error(), \"VT13001\")\n}","tryCatchPattern":"if err := execDelete(sql); err != nil {\n    if isVT13001(err) {\n        log.Warn(\"delete target not found; checking vschema\", slog.Any(\"error\", err))\n        return refreshVschemaAndRetry(sql)\n    }\n    return err\n}","preventionTips":["Prefer single-table DELETE statements","Avoid LIMIT on deletes of FK-related tables","Verify vschema after any table rename/migration before running DML","Monitor for VT13001 codes in app logs to catch stale vschema early"],"tags":["vitess","planbuilder","delete","vt13001","table-not-found"],"backgroundTag":"table-not-found-in-vschema","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}