{"record":{"id":"e430c4ea3bbdad8b","repo":"vitessio/vitess","slug":"column-type-mismatch-for-column-s-types-d-vs","errorCode":null,"errorMessage":"column type mismatch for column : %s, types: %d vs %d","messagePattern":"column type mismatch for column : (.+?), types: (.+?) vs (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtexplain/vtexplain_vttablet.go","lineNumber":661,"sourceCode":"\n\t\ttableName := sqlparser.String(sqlparser.GetTableName(table.Expr))\n\t\tcolumns, exists := t.vte.getGlobalTabletEnv().tableColumns[tableName]\n\t\tif !exists && tableName != \"\" {\n\t\t\treturn nil, fmt.Errorf(\"unable to resolve table name %s\", tableName)\n\t\t}\n\n\t\tcolTypeMap := map[string]querypb.Type{}\n\n\t\tif table.As.IsEmpty() {\n\t\t\ttableColumnMap[sqlparser.GetTableName(table.Expr)] = colTypeMap\n\t\t} else {\n\t\t\ttableColumnMap[table.As] = colTypeMap\n\t\t}\n\n\t\tfor k, v := range columns {\n\t\t\tif colType, exists := colTypeMap[k]; exists {\n\t\t\t\tif colType != v {\n\t\t\t\t\treturn nil, fmt.Errorf(\"column type mismatch for column : %s, types: %d vs %d\", k, colType, v)\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tcolTypeMap[k] = v\n\t\t}\n\t}\n\n\tcolNames, colTypes := t.analyzeExpressions(selStmt, tableColumnMap)\n\n\tinColName, inVal, rowCount, s, err := t.analyzeWhere(selStmt, tableColumnMap)\n\tif err != nil {\n\t\treturn s, err\n\t}\n\n\tfields := make([]*querypb.Field, len(colNames))\n\trows := make([][]sqltypes.Value, 0, rowCount)\n\tfor i, col := range colNames {\n\t\tcolType := colTypes[i]","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtexplain/vtexplain_vttablet.go#L643-L679","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make the column types consistent across the joined tables in the schema.","Qualify/alias columns to avoid the conflicting name collision.","Compare the reported type codes in the error to find which table's schema is wrong and fix the CREATE TABLE."],"exampleFix":"-- before\ncreate table a (id bigint);\ncreate table b (id int);\nselect * from a join b on a.id=b.id; -- mismatch\n-- after\ncreate table b (id bigint);","handlingStrategy":"validation","validationCode":"// Compare shared column names across joined tables before explaining\nfor col, t1 := range tableACols {\n    if t2, ok := tableBCols[col]; ok && t1 != t2 {\n        return fmt.Errorf(\"column %s type differs: %v vs %v\", col, t1, t2)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"column type mismatch\") {\n    // diff the CREATE TABLE definitions of the joined tables and align types\n}","preventionTips":["Keep schemas in sync across keyspaces (schema swap tools).","Avoid naming shared columns with different types in joined tables.","Validate schema consistency in CI."],"tags":["vtexplain","schema","type-mismatch"],"backgroundTag":"schema-type-mismatch","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}