vitessio/vitess · error
err
Error message
err
What it means
Union.AddWSColumn converts addWeightStringToOffset's error into a panic. When appending a weight_string() column on top of a UNION (needed for ORDER BY collation handling), the helper failed — e.g. the requested offset has no matching source column or branches are inconsistent — so Vitess aborts planning. The message is the bare underlying error ('err'), making it opaque without a stack trace.
Source
Thrown at go/vt/vtgate/planbuilder/operators/union.go:172
func (u *Union) GetSelectFor(source int) *sqlparser.Select {
src := u.Sources[source]
for {
switch op := src.(type) {
case *Horizon:
return getFirstSelect(op.Query)
case *Route:
src = op.Source
default:
panic(vterrors.VT13001("expected all sources of the UNION to be horizons"))
}
}
}
func (u *Union) AddWSColumn(ctx *plancontext.PlanningContext, offset int, underRoute bool) int {
outputOffset, err := u.addWeightStringToOffset(ctx, offset)
if err != nil {
panic(err)
}
return outputOffset
}
func (u *Union) AddColumn(ctx *plancontext.PlanningContext, reuse bool, gb bool, expr *sqlparser.AliasedExpr) int {
if reuse {
offset := u.FindCol(ctx, expr.Expr, false)
if offset >= 0 {
return offset
}
}
switch e := expr.Expr.(type) {
case *sqlparser.ColName:
cols := u.GetColumns(ctx)
// here we deal with pure column access on top of the union
offset := slices.IndexFunc(cols, func(column *sqlparser.AliasedExpr) bool {
if column.ColumnName() == expr.ColumnName() {View on GitHub (pinned to 01a25a7d17)
Solutions
- Rewrite the query so the ORDER BY column exists identically in every UNION branch.
- Avoid ORDER BY expressions requiring weight_string on UNION results (e.g. order in each branch or use an explicit compatible column).
- If valid SQL triggers it, file a Vitess issue including the query and schema.
Example fix
// before SELECT a FROM t1 UNION SELECT b FROM t2 ORDER BY a COLLATE utf8_bin; // after: order by a column present in all branches SELECT a FROM t1 UNION SELECT b AS a FROM t2 ORDER BY a;
Defensive patterns
Strategy: try-catch
Try / catch
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("union weight_string planning failed: %v", r)
}
}() Prevention
- ORDER BY columns on UNIONs must exist identically in all branches.
- Prefer ordering by a select-list alias over complex expressions.
- Test collation-sensitive ORDER BY queries against UNIONs before deploying.
When it happens
Trigger: Calling Union.AddWSColumn(ctx, offset, underRoute) where addWeightStringToOffset returns an error, which is immediately panicked. Reached when planning ORDER BY on a UNION that requires weight_string columns.
Common situations: Queries ordering a UNION by a column requiring collation-aware sorting (weight_string) where the UNION branches' columns don't line up; typically hit on unhandled query shapes during development.
Related errors
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/f72922d954f012dc.
Report an issue: GitHub.