vitessio/vitess · error
unsupported multiple columns in sum clause: %v
Error message
unsupported multiple columns in sum clause: %v
What it means
SUM in a vreplication table plan must take exactly one argument. analyzeExpr rejects SUM(a, b) or SUM() with 'unsupported multiple columns in sum clause' because the plan builder stores only a single column reference for the opSum operation.
Source
Thrown at go/vt/vttablet/tabletmanager/vreplication/table_plan_builder.go:503
// The vstreamer responds with "keyspace_id" as the field name for this request.
cexpr.expr = &sqlparser.ColName{Name: sqlparser.NewIdentifierCI("keyspace_id")}
return cexpr, nil
}
}
if expr, ok := aliased.Expr.(sqlparser.AggrFunc); ok {
if sqlparser.IsDistinct(expr) {
return nil, fmt.Errorf("unsupported distinct expression usage: %v", sqlparser.String(expr))
}
switch fname := expr.AggrName(); fname {
case "count":
if _, ok := expr.(*sqlparser.CountStar); !ok {
return nil, fmt.Errorf("only count(*) is supported: %v", sqlparser.String(expr))
}
cexpr.operation = opCount
return cexpr, nil
case "sum":
if len(expr.GetArgs()) != 1 {
return nil, fmt.Errorf("unsupported multiple columns in sum clause: %v", sqlparser.String(expr))
}
innerCol, ok := expr.GetArg().(*sqlparser.ColName)
if !ok {
return nil, fmt.Errorf("unsupported non-column name in sum clause: %v", sqlparser.String(expr))
}
if !innerCol.Qualifier.IsEmpty() {
return nil, fmt.Errorf("unsupported qualifier for column: %v", sqlparser.String(innerCol))
}
cexpr.operation = opSum
cexpr.expr = innerCol
tpb.addCol(innerCol.Name)
cexpr.references[innerCol.Name.String()] = true
return cexpr, nil
}
}
err := sqlparser.Walk(func(node sqlparser.SQLNode) (kontinue bool, err error) {
switch node := node.(type) {
case *sqlparser.ColName:View on GitHub (pinned to 01a25a7d17)
Solutions
- Split into multiple single-argument sums: SUM(a), SUM(b).
- If you need a+b then sum the result upstream or compute an expression column outside vreplication.
- Ensure the SUM argument is exactly one unqualified column name (see also non-column and qualifier restrictions).
Example fix
// before select sum(a, b) as total from t // after select sum(a) as sum_a, sum(b) as sum_b from t
Defensive patterns
Strategy: validation
Validate before calling
// Ensure SUM has exactly one argument before building the plan
func validSumArgCount(e sqlparser.Expr) bool {
ag, ok := e.(*sqlparser.AliasedExpr)
if !ok { return true }
sum, ok := ag.Expr.(*sqlparser.Sum)
if !ok { return true }
return len(sum.Args) == 1
} Type guard
func isSingleArgSum(n sqlparser.SQLNode) (ok bool) { s, is := n.(*sqlparser.Sum); return is && len(s.Args) == 1 } Prevention
- Always write SUM(col) with exactly one column argument.
- Split multi-column sums into separate select-list items.
When it happens
Trigger: A Materialize/vreplication SELECT containing SUM with zero or more than one argument, e.g. SELECT SUM(a, b) FROM t; analyzeExpr (via analyzeExprs) hits the len(expr.GetArgs()) != 1 branch.
Common situations: Hand-edited materialization queries; users trying to sum multiple columns in one aggregate instead of summing each column separately; copy-paste from spreadsheets-style formulas.
Related errors
- only count(*) is supported: %v
- unsupported non-column name in sum clause: %v
- unsupported aggregation function: %v
- group by expression is not allowed to reference an aggregate
- unsupported subquery: %v
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/67601139698a0bcd.
Report an issue: GitHub.