vitessio/vitess · error

cannot find column %v in table %v

Error message

cannot find column %v in table %v

What it means

Returned when the column referenced by the vstreamer's keyspace-id mapping (from the vschema) is not present in the table's schema definition as seen in the binlog, so the keyspace id column value cannot be located.

Source

Thrown at go/vt/binlog/keyspace_id_resolver.go:95

		colVindex, err := vindexes.FindVindexForSharding(table.Name.String(), tableSchema.ColumnVindexes)
		if err != nil {
			return -1, nil, err
		}

		// TODO @rafael - when rewriting the mapping function, this will need to change.
		// for now it's safe to assume the sharding key will be always on index 0.
		shardingColumnName := colVindex.Columns[0].String()
		for i, col := range table.Fields {
			if strings.EqualFold(col.Name, shardingColumnName) {
				// We found the column.
				return i, &keyspaceIDResolverFactoryV3{
					// Only SingleColumn vindexes are returned by FindVindexForSharding.
					vindex: colVindex.Vindex.(vindexes.SingleColumn),
				}, nil
			}
		}
		// The column was not found.
		return -1, nil, fmt.Errorf("cannot find column %v in table %v", shardingColumnName, table.Name)
	}, nil
}

// keyspaceIDResolverFactoryV3 uses the Vindex to compute the value.
type keyspaceIDResolverFactoryV3 struct {
	vindex vindexes.SingleColumn
}

func (r *keyspaceIDResolverFactoryV3) keyspaceID(v sqltypes.Value) ([]byte, error) {
	destinations, err := r.vindex.Map(context.TODO(), nil, []sqltypes.Value{v})
	if err != nil {
		return nil, err
	}
	if len(destinations) != 1 {
		return nil, fmt.Errorf("mapping row to keyspace id returned an invalid array of destinations: %v", key.DestinationsString(destinations))
	}
	ksid, ok := destinations[0].(key.DestinationKeyspaceID)
	if !ok || len(ksid) == 0 {

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Confirm the column exists: SHOW COLUMNS FROM <table> and compare with the vschema column name.
  2. Update the vschema's column_vindexes to reference the actual column name.
  3. Reload the table schema (restart vttablet or apply schema) so schema.Table matches the vschema.

Example fix

// before
{"column_vindexes":[{"column":"user_id","name":"h"}]}
// after (column actually named uid)
{"column_vindexes":[{"column":"uid","name":"h"}]}
Defensive patterns

Strategy: validation

Validate before calling

// verify vschema vindex columns exist in the live table
cols := getMysqlColumns(t, dbName, tableName)
for _, cv := range tableVindexes {
	if !contains(cols, cv.Column) {
		return fmt.Errorf("vindex column %s not in table %s", cv.Column, tableName)
	}
}

Try / catch

if err := streamKeyRange(ctx, kr); err != nil {
	if strings.Contains(err.Error(), "cannot find column") {
		// fix vschema column name or reload table schema
	}
	return err
}

Prevention

When it happens

Trigger: The resolver's returned function is invoked for a table whose declared vindex column (shardingColumnName) does not appear in schema.Table's columns — mismatch between vschema column_vindexes and the actual table schema.

Common situations: Renamed/dropped sharding column; vschema lists a column that doesn't exist on the table; case/name mismatch between vschema and MySQL schema.

Related errors


AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01). Data as JSON: /api/errors/db1a0d2c1047c903. Report an issue: GitHub.