Skip to main content
err:user:unprocessable_entity:query_rows_limit_exceeded
Example
{
  "meta": {
    "requestId": "req_4dgzrNP3Je5mU1tD"
  },
  "error": {
    "detail": "Query exceeded the maximum rows to scan limit of 100 million",
    "status": 422,
    "title": "Unprocessable Entity",
    "type": "https://unkey.com/docs/errors/user/unprocessable_entity/query_rows_limit_exceeded"
  }
}

What Happened?

Your query tried to scan more than 100 million rows! We limit the number of rows that can be scanned to keep queries fast and prevent resource exhaustion. This happens when you query large time ranges or don’t filter your data enough, causing ClickHouse to scan millions of rows even if the final result is small.

How to Fix It

1. Add Time Range Filters

Always filter by time to limit the number of rows scanned:
SELECT COUNT(*)
FROM key_verifications_v1
WHERE outcome = 'VALID'

2. Use More Selective Filters

Add filters that reduce the data before aggregation:
SELECT api_id, COUNT(*) as total
FROM key_verifications_v1
WHERE time >= now() - INTERVAL 90 DAY
GROUP BY api_id

3. Use Pre-Aggregated Tables

For historical queries, use aggregated tables that have fewer rows:
SELECT
  toStartOfDay(time) as day,
  COUNT(*) as total
FROM key_verifications_v1
WHERE time >= now() - INTERVAL 90 DAY
GROUP BY day

4. Query in Smaller Batches

Instead of one large query, break it into smaller time windows:
// Instead of querying 90 days at once
const results = [];
for (let i = 0; i < 90; i += 7) {
  const start = `now() - INTERVAL ${i + 7} DAY`;
  const end = `now() - INTERVAL ${i} DAY`;

  const result = await query(`
    SELECT COUNT(*) as total
    FROM key_verifications_v1
    WHERE time >= ${start} AND time < ${end}
  `);

  results.push(result);
}

Need Higher Row Limits?

Have a legitimate need to scan more rows? Contact our support team!Reach out to support and tell us:
  • What you’re trying to analyze
  • Why you need to scan more than 100 million rows
  • An example of the query you’re running
We’ll review your use case and help optimize your query or adjust limits if needed.