Query-analyzer sampled-byte counters versus TTL-retained storage
Parent: analyzeShardKey and query sampling · Published reference · snapshot 2026-11-02
↓ Facts as markdownall context files
Source-anchored research for Query-analyzer sampled-byte counters versus TTL-retained storage. Run status: COMPLETED.
These notes link each claim to its source. Some citations identify archived research reports that are no longer hosted on this site. A published reference means the content is available; it does not certify independent review or accuracy.Read the editorial policy and follow the sources before relying on a claim.
Structure and components
- In MongoDB release 8.0.0, the read, update, delete and findAndModify sampling paths add doc.objsize() to the corresponding byte counter when _queries.add(doc) accepts a serialized sample document into the buffer. The read sample document contains sample identity, namespace, collection UUID, command name, command and expiration. Thus the byte counter counts serialized sample documents, including this metadata, and is updated before the later flush; it is not a compressed-disk or completed-persistence byte meter. (medium confidence) [source 1] [source 2] [source 3]
How it works
- In the pinned implementation, the server-wide byte totals aggregate samples across collections. When sampling is disabled for a collection, its per-collection tracker is removed from the tracker map without subtracting the server-wide byte totals. Configuration refresh replaces the collection-tracker map while leaving those totals intact. (high confidence) [source 1] [source 2]
Comparisons and alternatives
- In MongoDB release 8.0.0, these server-wide totals accumulate sampled sizes over the server lifetime. The tracker starts its byte totals at zero, adds each supplied size, and reports those totals directly. They are cumulative counters rather than a measurement of the documents currently retained after TTL deletion. (medium confidence) [source 1] [source 2] [source 3]
- In the pinned implementation, sampled-query documents and update-diff documents use separate internal collections, `sampledQueries` and `sampledQueriesDiff`, in the config database. The diff path adds documents to `_diffs.add(doc.toBSON())` without incrementing the sampled-write byte counter. A storage comparison that includes sampled-update diffs must measure that collection separately rather than assume the write byte counter covers it. (high confidence) [source 1] [source 2] [source 3]
- A sampling TTL window is not a strict retained-disk bound: MongoDB warns that expiration need not delete documents immediately, and Percona explains that WiredTiger can retain deleted-document space for reuse instead of returning it to the operating system. Thus expired samples, reusable allocation and live retained documents must be distinguished when interpreting storage measurements. (high confidence) [source 1] [source 2] [source 3] [source 4]
Facts and statements
- The serverStatus queryAnalyzers.totalSampledReadsBytes and queryAnalyzers.totalSampledWritesBytes fields report total sampled read-query and write-query sizes in bytes. MongoDB documents both byte fields as available on mongod only. (low confidence) [source]
- Keep logical and allocated bytes separate: `collStats.size` is uncompressed record size excluding indexes; `collStats.storageSize` is allocated document storage and reflects compression; `collStats.totalIndexSize` is index disk space; and `collStats.totalSize` sums document allocation and index space. `collStats.freeStorageSize` identifies reusable storage, not additional live records. (low confidence) [source]
- Do not convert the cumulative sample-byte counters directly into a retained-disk guarantee or apply a fixed overhead multiplier. The pinned writer counts buffered sample BSON, the diff path has separate storage, and collection statistics distinguish compressed allocation, indexes and reusable space. These mechanisms support measuring an observed footprint; they do not establish a universal conversion formula. This is a bounded inference from the cited implementation and field definitions. (medium confidence) [source 1] [source 2] [source 3]
Children
- No children recorded.