vitessio/vitess · error · RowMismatchError
expected %d rows in result, got %d
Error message
expected %d rows in result, got %d
What it means
RowsEquals compares two row sets unordered. Before matching individual rows it checks the cardinality; if want and got have different lengths it returns a RowMismatchError carrying this message plus both full row sets for diffing.
Source
Thrown at go/sqltypes/parse_rows.go:140
type RowMismatchError struct {
err error
want, got []Row
}
func (e *RowMismatchError) Error() string {
return fmt.Sprintf("results differ: %v\n\twant: %v\n\tgot: %v", e.err, e.want, e.got)
}
func RowEqual(want, got Row) bool {
return slices.EqualFunc(want, got, func(a, b Value) bool {
return a.Equal(b)
})
}
func RowsEquals(want, got []Row) error {
if len(want) != len(got) {
return &RowMismatchError{
err: fmt.Errorf("expected %d rows in result, got %d", len(want), len(got)),
want: want,
got: got,
}
}
matched := make([]bool, len(want))
for _, aa := range want {
var ok bool
for i, bb := range got {
if matched[i] {
continue
}
if RowEqual(aa, bb) {
matched[i] = true
ok = true
break
}
}View on GitHub (pinned to 01a25a7d17)
Solutions
- Inspect got vs want (RowMismatchError embeds both) to see which side is wrong
- Fix the query or fixture data so cardinality matches
- Add/adjust a LIMIT or WHERE clause if the test intent is a subset check
Example fix
// before query := "select id from t" // after (if only first row intended) query := "select id from t limit 1"
Defensive patterns
Strategy: type-guard
Validate before calling
if len(got) != expectedCount {
return fmt.Errorf("pre-check: got %d rows, want %d", len(got), expectedCount)
} Type guard
func sameCardinality(want, got []sqltypes.Row) bool { return len(want) == len(got) } Try / catch
err := sqltypes.RowsEquals(want, got)
var rm *sqltypes.RowMismatchError
if errors.As(err, &rm) {
t.Logf("want=%v got=%v", rm.Want, rm.Got)
} Prevention
- Count expected rows explicitly before asserting
- Pin LIMIT in queries whose row count should be stable
- Check fixtures per environment
When it happens
Trigger: Calling RowsEquals (directly or via RowsEqualsStr / AssertMatchesNoOrder) when the actual query result returned a different number of rows than the expected set.
Common situations: Underlying query changed semantics (added/removed a WHERE clause, missing LIMIT), data set differences between environments, or a streaming test collecting fewer/more rows than expected.
Related errors
- row %v is missing from result
- malformed row assertion: %w
- cannot create local vtctldclient without a server; call SetS
- failed to parse literal string at %s: %w
- unexpected token '%s' at %s
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/13e8f64104a0c3bc.
Report an issue: GitHub.