tursodatabase/turso · error
total query count overflows usize
Error message
total query count overflows usize
What it means
validate() computes total queries as batches * queries_per_batch * connections using checked arithmetic. If the product overflows usize, the total workload cannot be represented, so validation fails with this error instead of silently wrapping.
Source
Thrown at perf/memory/src/fts.rs:295
ensure!(self.connections > 0, "connections must be positive");
ensure!(
self.execution.batches() > 0,
"queries or transactions must be positive"
);
ensure!(
self.execution.queries_per_batch() > 0,
"queries per transaction must be positive"
);
ensure!(
!matches!(self.state, QueryState::First)
|| (self.execution.batches() == 1 && self.execution.queries_per_batch() == 1),
"first-query runs require one query per connection; use warm for repeated transactions"
);
self.execution
.batches()
.checked_mul(self.execution.queries_per_batch())
.and_then(|n| n.checked_mul(self.connections))
.ok_or_else(|| anyhow::anyhow!("total query count overflows usize"))?;
Ok(())
}
}
impl Execution {
pub fn batches(self) -> usize {
match self {
Self::Queries(queries) => queries,
Self::Transactions { per_connection, .. } => per_connection,
}
}
fn queries_per_batch(self) -> usize {
match self {
Self::Queries(_) => 1,
Self::Transactions {
queries_per_transaction,
..View on GitHub (pinned to 492c4a71cd)
Solutions
- Reduce batches, queries per transaction, or connections to a realistic product
- Compute the intended total in u128 and pick smaller factors before building the config
- If on a 32-bit target, run the benchmark on a 64-bit platform or lower the workload
Example fix
// before
Execution { batches: usize::MAX, queries_per_transaction: usize::MAX, .. }
// after
Execution { batches: 100, queries_per_transaction: 10, .. } Defensive patterns
Strategy: validation
Validate before calling
let total = batches as u128 * queries_per_batch as u128 * connections as u128;
if total > usize::MAX as u128 { return Err(anyhow!("total query count too large")); } Try / catch
if let Err(e) = config.validate() {
if e.to_string().contains("overflows usize") {
// scale the workload down and rebuild the config
}
} Prevention
- Sanity-check workload totals in u128 before building the config
- Cap user-supplied workload multipliers to realistic bounds
- Be extra careful with 32-bit builds where usize is small
When it happens
Trigger: Setting extremely large values for queries/queries-per-transaction/connections whose product exceeds usize::MAX (only plausible on 32-bit targets or with absurd 64-bit values).
Common situations: Passing an unvalidated 64-bit number from a config file on a 32-bit build; a runaway multiplier in generated configs; unit mistake (passing total queries as queries-per-transaction).
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- HTTP request missing URL: no URL in request and no baseUrl i
- Partial sync requires exactly one prefix or query bootstrap
- UNSUPPORTED_CONFIG
- MISSING_URL
- index contains {} segment bytes, below requested minimum {};
AI-assisted analysis of tursodatabase/turso@492c4a71cd (2026-09-13).
Data as JSON: /api/errors/5328505f906acd3e.
Report an issue: GitHub.