vitessio/vitess · error

column type mismatch for column : %s, types: %d vs %d

Error message

column type mismatch for column : %s, types: %d vs %d

What it means

vtexplain merges column type information from multiple FROM tables into a shared colTypeMap. If the same column name appears with different querypb types in two tables (e.g. an aliased table vs the base table map), it reports a type mismatch with both numeric type codes. This indicates inconsistent schema assumptions in the explain input.

Source

Thrown at go/vt/vtexplain/vtexplain_vttablet.go:661

		tableName := sqlparser.String(sqlparser.GetTableName(table.Expr))
		columns, exists := t.vte.getGlobalTabletEnv().tableColumns[tableName]
		if !exists && tableName != "" {
			return nil, fmt.Errorf("unable to resolve table name %s", tableName)
		}

		colTypeMap := map[string]querypb.Type{}

		if table.As.IsEmpty() {
			tableColumnMap[sqlparser.GetTableName(table.Expr)] = colTypeMap
		} else {
			tableColumnMap[table.As] = colTypeMap
		}

		for k, v := range columns {
			if colType, exists := colTypeMap[k]; exists {
				if colType != v {
					return nil, fmt.Errorf("column type mismatch for column : %s, types: %d vs %d", k, colType, v)
				}
				continue
			}
			colTypeMap[k] = v
		}
	}

	colNames, colTypes := t.analyzeExpressions(selStmt, tableColumnMap)

	inColName, inVal, rowCount, s, err := t.analyzeWhere(selStmt, tableColumnMap)
	if err != nil {
		return s, err
	}

	fields := make([]*querypb.Field, len(colNames))
	rows := make([][]sqltypes.Value, 0, rowCount)
	for i, col := range colNames {
		colType := colTypes[i]

View on GitHub (pinned to 01a25a7d17)

Solutions

  1. Make the column types consistent across the joined tables in the schema.
  2. Qualify/alias columns to avoid the conflicting name collision.
  3. Compare the reported type codes in the error to find which table's schema is wrong and fix the CREATE TABLE.

Example fix

-- before
create table a (id bigint);
create table b (id int);
select * from a join b on a.id=b.id; -- mismatch
-- after
create table b (id bigint);
Defensive patterns

Strategy: validation

Validate before calling

// Compare shared column names across joined tables before explaining
for col, t1 := range tableACols {
    if t2, ok := tableBCols[col]; ok && t1 != t2 {
        return fmt.Errorf("column %s type differs: %v vs %v", col, t1, t2)
    }
}

Try / catch

if err != nil && strings.Contains(err.Error(), "column type mismatch") {
    // diff the CREATE TABLE definitions of the joined tables and align types
}

Prevention

When it happens

Trigger: A SELECT joins/aliases tables where the same column name has different querypb.Type values between tableColumns and the accumulated colTypeMap, e.g. mismatched column definitions for identically named columns across joined tables.

Common situations: Joining two tables that share a column name (like `id`) with different types (INT vs BIGINT/VARCHAR); schema files with drifted column definitions across keyspaces.

Related errors


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