{"record":{"id":"c47ef46d960e6969","repo":"vitessio/vitess","slug":"could-not-find-vindex-column-v-c47ef4","errorCode":null,"errorMessage":"could not find vindex column %v","messagePattern":"could not find vindex column (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/wrangler/materializer.go","lineNumber":1497,"sourceCode":"\t\t\t\tif colExpr, ok := selExpr.Expr.(*sqlparser.ColName); ok {\n\t\t\t\t\tmatch = colExpr.Name\n\t\t\t\t} else {\n\t\t\t\t\t// Cannot match against a complex expression.\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\t\t\tif match.Equal(col) {\n\t\t\t\tcolExpr, ok := selExpr.Expr.(*sqlparser.ColName)\n\t\t\t\tif !ok {\n\t\t\t\t\treturn nil, fmt.Errorf(\"vindex column cannot be a complex expression: %v\", sqlparser.String(selExpr))\n\t\t\t\t}\n\t\t\t\treturn colExpr, nil\n\t\t\t}\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"unsupported select expression: %v\", sqlparser.String(selExpr))\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"could not find vindex column %v\", sqlparser.String(col))\n}\n\nfunc (mz *materializer) createStreams(ctx context.Context, insertsMap map[string]string) error {\n\treturn mz.forAllTargets(func(target *topo.ShardInfo) error {\n\t\tinserts := insertsMap[target.ShardName()]\n\t\ttargetPrimary, err := mz.wr.ts.GetTablet(ctx, target.PrimaryAlias)\n\t\tif err != nil {\n\t\t\treturn vterrors.Wrapf(err, \"GetTablet(%v) failed\", target.PrimaryAlias)\n\t\t}\n\t\tbuf := &strings.Builder{}\n\t\tt := template.Must(template.New(\"\").Parse(inserts))\n\t\tinput := map[string]string{\n\t\t\t\"keyrange\": key.KeyRangeString(target.KeyRange),\n\t\t\t\"dbname\":   targetPrimary.DbName(),\n\t\t}\n\t\tif err := t.Execute(buf, input); err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":1479,"sourceCodeEnd":1515,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/wrangler/materializer.go#L1479-L1515","documentation":"After scanning the entire SELECT list, matchColInSelect could not find any select expression matching the primary vindex column name. generateInserts needs this column to construct per-shard INSERT statements; without it, the copy plan cannot be built.","triggerScenarios":"SourceExpression for a sharded target table omits the primary vindex column from its select list, or aliases it under a different name than the TargetTable's vindex column, e.g. `select id as uid, name from users` where vindex column is `id`.","commonSituations":"Filters that project only a subset of columns while the table is sharded; column renamed between source and target; typo in column name in the select list.","solutions":["Include the primary vindex column in the SELECT list with the exact target column name","Fix the alias so it matches the target table's vindex column name","Check `vtctldclient GetVSchema <target-keyspace>` to confirm which columns form the primary vindex"],"exampleFix":"// before (vindex column id missing)\n{\"sourceExpression\":\"select name, email from users\"}\n// after\n{\"sourceExpression\":\"select id, name, email from users\"}","handlingStrategy":"validation","validationCode":"vs, _ := wr.ts.GetVSchema(ctx, targetKeyspace)\npvCols := vs.Tables[targetTable].ColumnVindexes[0].Columns\nsel, _ := parser.Parse(sourceExpr)\nfor _, c := range pvCols {\n    if _, err := findColInSelect(sel.(*sqlparser.Select), c); err != nil {\n        return fmt.Errorf(\"SourceExpression must include primary vindex column %s\", c)\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always include all primary vindex columns in the select list","Alias columns to exactly the target table's column names","Cross-check vs `GetVSchema` primary vindex definition"],"tags":["vitess","wrangler","vindex","validation"],"backgroundTag":"vindex-column-missing","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}