Skip to content

Commit

Permalink
feat: use collation aware typing for UNION (#15122)
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <andres@planetscale.com>
  • Loading branch information
systay authored Feb 7, 2024
1 parent 26c2e72 commit f31f064
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
10 changes: 5 additions & 5 deletions go/vt/vtgate/planbuilder/operators/union_merging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
30 changes: 30 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/postprocess_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
}
]

0 comments on commit f31f064

Please sign in to comment.