{"record":{"id":"27005b4174688ab2","repo":"vitessio/vitess","slug":"err-27005b","errorCode":null,"errorMessage":"err","messagePattern":"err","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vtgate/planbuilder/operators/union_merging.go","lineNumber":301,"sourceCode":"\t\tif noDeps {\n\t\t\tcontinue\n\t\t}\n\n\t\tdeps := ctx.SemTable.RecursiveDeps(lae.Expr)\n\t\trae, ok := rhsExprs[idx].(*sqlparser.AliasedExpr)\n\t\tif !ok {\n\t\t\tnoDeps = true\n\t\t\tcontinue\n\t\t}\n\t\tdeps = deps.Merge(ctx.SemTable.RecursiveDeps(rae.Expr))\n\t\trt, foundR := ctx.TypeForExpr(rae.Expr)\n\t\tlt, foundL := ctx.TypeForExpr(lae.Expr)\n\t\tif foundR && foundL {\n\t\t\tcollations := ctx.VSchema.Environment().CollationEnv()\n\t\t\tvar typer evalengine.TypeAggregator\n\n\t\t\tif err := typer.Add(rt, collations); err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t\tif err := typer.Add(lt, collations); err != nil {\n\t\t\t\tpanic(err)\n\t\t\t}\n\n\t\t\tctx.SemTable.ExprTypes[col] = typer.Type()\n\t\t}\n\n\t\tctx.SemTable.Recursive[col] = deps\n\t}\n\n\texprs := [][]sqlparser.SelectExpr{lhsExprs, rhsExprs}\n\tunion := newUnion([]Operator{lhsRoute.Source, rhsRoute.Source}, exprs, cols, distinct)\n\tselectExprs := unionSelects(lhsExprs)\n\treturn &Route{\n\t\tunaryOperator: newUnaryOp(union),\n\t\tMergedWith:    []*Route{rhsRoute},\n\t\tRouting:       routing,","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vtgate/planbuilder/operators/union_merging.go#L283-L319","documentation":"This panic re-raises the first error returned by evalengine.TypeAggregator.Add while merging the types of the LHS/RHS expressions of a UNION column during createMergedUnion (go/vt/vtgate/planbuilder/operators/union_merging.go:301). When both sides' types are known, the planner aggregates rt then lt to compute the merged column type; Add fails when the two types cannot be aggregated (incompatible types/collations). The panic surfaces that type-resolution failure as an internal planning error.","triggerScenarios":"createMergedUnion (called from mergeUnionInputs / tryMergeNoneUnion / tryMergeUnionShardedRouting) merges two routes into one UNION; for a column position, ctx.TypeForExpr succeeds on both sides (foundR && foundL) and the first typer.Add(rt, collations) call returns an error — e.g. an unsupported or invalid type pairing for the aggregation.","commonSituations":"UNION of columns with exotic or incompatible types (e.g. binary/collation conflicts between arms on different keyspaces with different charsets); JSON/enum/set columns unioned with other types; cross-keyspace merges where collation environments disagree.","solutions":["Make both UNION arms produce compatible types for the column, using explicit CAST/CONVERT in one arm","Align charsets/collations of the columns on both sides (ALTER TABLE ... CONVERT TO CHARACTER SET) when arms come from differently configured tables","If types look compatible, reproduce and file a Vitess issue with both arms' column definitions — the aggregator rejecting them may be a bug"],"exampleFix":"// before (incompatible types across arms)\nSELECT int_col FROM t1 UNION SELECT varchar_col FROM t2;\n// after\nSELECT CAST(int_col AS CHAR) FROM t1 UNION SELECT varchar_col FROM t2;","handlingStrategy":"validation","validationCode":"// verify both arms' column types are aggregatable before issuing\nlt, rt := columnTypes(arm1, arm2, idx)\nif !evalengine.CanAggregate(rt, lt) { return fmt.Errorf(\"cast column %d to a common type\", idx) }","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"type\") {\n    return executeWithCasts(ctx, addUnionCasts(query))\n}","preventionTips":["CAST mismatched columns in one arm so both sides share a type","Keep charsets/collations consistent across unioned tables","Avoid unioning JSON/enum/set columns with unrelated types"],"tags":["vitess","planbuilder","union","type-aggregation","collation"],"backgroundTag":"type-mismatch-in-union","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}