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.

Solutions

  1. Reduce batches, queries per transaction, or connections to a realistic product
  2. Compute the intended total in u128 and pick smaller factors before building the config
  3. 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

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


AI-assisted analysis of tursodatabase/turso@8d4a589f8d (2026-09-13). Data as JSON: /api/errors/5328505f906acd3e. Report an issue: GitHub.

Appendix: source

Thrown at perf/memory/src/fts.rs:299

        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 8d4a589f8d)