vitessio/vitess · error
requested limit is out of range: %v
Error message
requested limit is out of range: %v
What it means
This error is thrown by Limit.getIntFrom when the LIMIT/OFFSET value cannot be converted to a valid count. The value must be a positive integral; a non-numeric string, a number too large for an int, or a negative value all fail. Vitess rejects these instead of passing an invalid limit down to MySQL.
Source
Thrown at go/vt/vtgate/engine/limit.go:227
if expr == nil {
return 0, nil
}
evalResult, err := env.Evaluate(expr)
if err != nil {
return 0, err
}
value := evalResult.Value(vcursor.ConnCollation())
if value.IsNull() {
return 0, nil
}
if !value.IsIntegral() {
return 0, sqltypes.ErrIncompatibleTypeCast
}
count, err := strconv.Atoi(value.RawStr())
if err != nil || count < 0 {
return 0, fmt.Errorf("requested limit is out of range: %v", value.RawStr())
}
return count, nil
}
func (l *Limit) description() PrimitiveDescription {
other := map[string]any{}
if l.Count != nil {
other["Count"] = sqlparser.String(l.Count)
}
if l.Offset != nil {
other["Offset"] = sqlparser.String(l.Offset)
}
if l.RequireCompleteInput {
other["RequireCompleteInput"] = true
}
return PrimitiveDescription{View on GitHub (pinned to 01a25a7d17)
Solutions
- Validate the limit/offset is a non-negative integer before sending the query.
- Check the bind variable supplying the LIMIT value for sign, type, and stray characters.
- Clamp or cap extremely large values to a sane maximum before executing.
Example fix
// before
pageSize := req.PageSize // may be -1 or "abc"
query := "SELECT ... LIMIT ?"
// after
if req.PageSize < 0 || req.PageSize > maxPageSize {
return fmt.Errorf("invalid page size %d", req.PageSize)
}
query := "SELECT ... LIMIT ?" Defensive patterns
Strategy: validation
Validate before calling
n, err := strconv.Atoi(limitStr)
if err != nil || n < 0 {
return fmt.Errorf("limit must be a non-negative integer, got %q", limitStr)
} Type guard
func isValidLimit(s string) bool {
n, err := strconv.Atoi(s)
return err == nil && n >= 0
} Prevention
- Always validate page size/offset against user input before building the query.
- Clamp limits to an application-defined maximum.
- Avoid casting user strings to limits without an explicit integer parse.
When it happens
Trigger: Executing a query whose LIMIT or OFFSET binds to a value that is not a valid non-negative integer, e.g. LIMIT 'abc', LIMIT -1, or a bind variable that resolves to a negative or overflow-sized number.
Common situations: Application computes a page size from user input without validating it (negative page or page*size overflow); ORM serializes limit as a string with sign or whitespace; int overflow on 32-bit builds with very large limits.
Related errors
- requested limit is out of range: %v
- VT12001
- sample is too small
- --batch-size only allowed when all queries are CREATE TABLE|
- BaseKeyspace is required for SNAPSHOT keyspaces
AI-assisted analysis of vitessio/vitess@01a25a7d17 (2026-09-01).
Data as JSON: /api/errors/c03f1157a6c1e197.
Report an issue: GitHub.