diff --git a/go/vt/vtgate/planbuilder/operators/union_merging.go b/go/vt/vtgate/planbuilder/operators/union_merging.go index 1fb7d4fb454..67853e44c7f 100644 --- a/go/vt/vtgate/planbuilder/operators/union_merging.go +++ b/go/vt/vtgate/planbuilder/operators/union_merging.go @@ -17,8 +17,6 @@ limitations under the License. package operators import ( - "vitess.io/vitess/go/mysql/collations" - "vitess.io/vitess/go/sqltypes" "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vtgate/engine" "vitess.io/vitess/go/vt/vtgate/evalengine" @@ -205,10 +203,12 @@ func createMergedUnion( rt, foundR := ctx.SemTable.TypeForExpr(rae.Expr) lt, foundL := ctx.SemTable.TypeForExpr(lae.Expr) if foundR && foundL { - types := []sqltypes.Type{rt.Type(), lt.Type()} - t := evalengine.AggregateTypes(types) - ctx.SemTable.ExprTypes[col] = evalengine.NewType(t, collations.Unknown) + t, err := evalengine.AggregateEvalTypes([]evalengine.Type{rt, lt}, ctx.VSchema.Environment().CollationEnv()) + if err == nil { + ctx.SemTable.ExprTypes[col] = t + } } + ctx.SemTable.Recursive[col] = deps } diff --git a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json index 6697da92c23..9093fe2f390 100644 --- a/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json +++ b/go/vt/vtgate/planbuilder/testdata/postprocess_cases.json @@ -2205,5 +2205,35 @@ "user.user" ] } + }, + { + "comment": "No weightstrings or derived table needed", + "query": "select textcol1 from user union select textcol1 from user", + "plan": { + "QueryType": "SELECT", + "Original": "select textcol1 from user union select textcol1 from user", + "Instructions": { + "OperatorType": "Distinct", + "Collations": [ + "0: latin1_swedish_ci" + ], + "Inputs": [ + { + "OperatorType": "Route", + "Variant": "Scatter", + "Keyspace": { + "Name": "user", + "Sharded": true + }, + "FieldQuery": "select textcol1 from `user` where 1 != 1 union select textcol1 from `user` where 1 != 1", + "Query": "select textcol1 from `user` union select textcol1 from `user`", + "Table": "`user`" + } + ] + }, + "TablesUsed": [ + "user.user" + ] + } } ]