{"record":{"id":"9264d993c1c48b24","repo":"vitessio/vitess","slug":"values-v-for-column-v-does-not-map-to-keyspace-i","errorCode":null,"errorMessage":"values %v for column %v does not map to keyspace ids","messagePattern":"values (.+?) for column (.+?) does not map to keyspace ids","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/engine/insert_common.go","lineNumber":338,"sourceCode":"\t\t}\n\n\t\tvar mismatchVindexKeys []sqltypes.Row\n\t\tfor i, v := range verified {\n\t\t\trowNum := verifyIndexes[i]\n\t\t\tif !v {\n\t\t\t\tif !ic.Ignore {\n\t\t\t\t\tmismatchVindexKeys = append(mismatchVindexKeys, vindexColumnsKeys[rowNum])\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\n\t\t\t\t// Skip the whole row if this is a `INSERT IGNORE` or `INSERT ... ON DUPLICATE KEY ...` statement\n\t\t\t\t// but the keyspace ids didn't match.\n\t\t\t\tksids[verifyIndexes[i]] = nil\n\t\t\t}\n\t\t}\n\n\t\tif mismatchVindexKeys != nil {\n\t\t\treturn fmt.Errorf(\"values %v for column %v does not map to keyspace ids\", mismatchVindexKeys, colVindex.Columns)\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// processGenerateFromSelect generates new values using a sequence if necessary.\n// If no value was generated, it returns 0. Values are generated only\n// for cases where none are supplied.\nfunc (ic *InsertCommon) processGenerateFromSelect(\n\tctx context.Context,\n\tvcursor VCursor,\n\tloggingPrimitive Primitive,\n\trows []sqltypes.Row,\n) (insertID int64, err error) {\n\tif ic.Generate == nil {\n\t\treturn 0, nil\n\t}","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/engine/insert_common.go#L320-L356","documentation":"When inserting into a table with unowned vindexes (e.g. lookup vindexes the application must populate), processUnowned verifies that the supplied column values actually map to keyspace ids. If verification shows the values do not map (mismatchVindexKeys set), the insert fails with this error so inconsistent vindex state is not created.","triggerScenarios":"INSERT (or ON DUPLICATE KEY UPDATE / REPLACE via processVindexes -> processUnowned) where a value for an unowned vindex column exists in the lookup table but points to different keyspace ids, or cannot be verified to map consistently.","commonSituations":"Stale or inconsistent lookup-vindex tables after resharding; application-inserted lookup rows pointing at wrong shards; inserting duplicate values that already map elsewhere.","solutions":["Rebuild/repair the lookup vindex table so its entries point to the correct keyspace ids","Verify the inserted values are consistent with the existing vindex data before inserting","If the value legitimately belongs elsewhere, delete the stale lookup entry first"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// before insert, confirm the unowned vindex value maps consistently\nksids, err := vindex.Map(cursor, vindexParams, []string{val})\nif err != nil || len(ksids) == 0 || hasNilKsid(ksids) {\n    return fmt.Errorf(\"value %v does not map to keyspace ids\", val)\n}","typeGuard":null,"tryCatchPattern":"if err := insert(row); err != nil && strings.Contains(err.Error(), \"does not map to keyspace ids\") {\n    // repair lookup vindex entries for the offending value, then retry\n}","preventionTips":["Keep lookup vindex tables in sync with resharding (rebuild after MoveTables)","Insert unowned-vindex lookup rows and application rows in the same transaction","Regularly run vindex consistency checks (e.g. vtctldclient VDiff/ExternallyReparentAtomically tooling)"],"tags":["vtgate","vindex","insert","lookup-vindex"],"backgroundTag":"vindex-mapping-failure","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}