Repository navigation
D1: clarify that a db.batch() counts as one query against the per-invocation limit - #34192
Merged
irvinebroque merged 1 commit intoOct 24, 2026
Conversation
The Batch limits note says per-query limits apply to each statement inside a batch. The Queries per Worker invocation limit is listed above that note but behaves differently, and the page does not say which way it goes. The batch API page does not mention it either, so a reader cannot currently determine whether a 2,000-statement batch costs 1 query or 2,000.
vince-gonzalez
requested review from
a team,
irvinebroque,
ivoryibu,
joshthoward,
lambrospetrou,
rita3ko,
rts-rob and
vy-ton
as code owners
October 11, 2026 07:57
Contributor
AI Review✅ Reviewed Commands
|
ivoryibu
approved these changes
Oct 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Adds one paragraph to the Batch limits note on the D1 limits page, stating that a
db.batch()counts as a single query against Queries per Worker invocation, rather than one query per statement.Why
The note immediately above says:
Queries per Worker invocation is listed above that note, so the sentence reads as though it applies — but it does not.
/d1/worker-api/d1-database/does not mention per-invocation limits either, so a reader currently cannot determine whether a 2,000-statement batch costs 1 query or 2,000 against a documented budget of 1,000.In practice this leads people to chunk bulk inserts to keep the statement count under 1,000, which is not necessary.
How I checked
Against a live D1 database (region ENAM, Workers Paid), from inside a deployed Worker, one fresh invocation per measurement, using
SELECT 1so a count limit would bite before any duration limit.The documented figure is exact. It is enforced on the 1,001st query, and the first 1,000 complete:
Too many API requests by single Worker invocationToo many API requests by single Worker invocationA batch is counted differently. Both of these are above the same documented budget, in the same shape of invocation:
db.batch()A single
batch()call also completed with 150,000 statements, which is 150x the per-invocation budget.Scope
The change only states how a batch is counted. It deliberately does not claim anything about:
batch()No existing text is altered and no documented number is disputed. The 1,000 figure is correct as written.
Method and raw data: https://github.com/vince-gonzalez/d1bench