Read/Write Limits
quick question regarding read/write limits -- i see that these limits are enforced at each query/mutation/function level, but to clarify/confirm -- if my query was to fetch the latest 100 docs, how many documents would be "scanned"? Could you also elaborate on "More than 4096 queries calls to db.get or db.query are made"
5 Replies
Hey @zid, if you do a
db.query
without using an index then the number of documents scanned is the number of documents in the table. Hope this clarifies the “documents scanned” limit.
If your query or mutation function makes a single call to db.query
it counts as one call. If you make a 100 calls to db.query
or db.get
to get a hundred documents it counts as 100 calls.
This “call limit” is there because you could make a milion calls to, say, db.get
against an empty table, in this case you would read from the DB a million times but scan 0 documents (which would likely be a bug).
This a fresh piece of documentation so thanks for the feedback, we’ll work on improving it. 🤗also a very minor clarification, if you do a scan on a document (a query without an index) the number of documents will be the number you walk over, e.g., if you fetch the first 10 documents from a table then that will only count as 10
Just saw this, sorry for the delay.
So...lets see here.
const users = await db.query("users").take(5);
will fetch the first 5 documents because there is no filter or other requirement which would require a full scan of the database, provided there is no index in this query? In other words, if there was a filter present and no defined index, every record has to be scanned in the db, correct?Every record might be scanned - if it turns out that the first 5 documents in the table satisfy your filter, then only those will be scanned. So filter will "stop scanning" once the query found enough results.
I forgot to mention this, but we do have in-depth doc on this topic:
https://docs.convex.dev/database/indexes/indexes-and-query-perf
Introduction to Indexes and Query Performance | Convex Developer Hub
How do I ensure my Convex database queries are