Support explicit MongoDB filters and aggregation pipelines in external table scans - #27553
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
aunjgr
left a comment
There was a problem hiding this comment.
Reviewed exact head 2abf65ca9eb0823e7137cb61345849f4ecbfe7df against merge base 6a8e7ecc530539948663a35a52259224ee1d128a.
[P1] Use a true minimal row-carrier projection when column pruning removes every mapped column. The new explicit-query path intentionally allows projectedMongoColumns to return no columns for COUNT(*) and query-only scans (pkg/sql/compile/compile.go:2851-2872) and installs NewRowCountConverter. But ProjectionDocument(nil) returns {_id: 0} (pkg/sql/mongodb/predicate.go:148-179). That is an exclusion projection: MongoDB returns every field except _id. The aggregate path appends the same $project, also preserving every non-_id output field.
Consequently a valid query such as SELECT COUNT(*) ... WHERE __mo_query = '{"filter":...}' downloads and validates complete documents even though no value is consumed. A document with an irrelevant field larger than MaxValueBytes/MaxBatchBytes then fails at mongoscan.Call/Converter.AppendDocumentWithBudget with a connector size error; the count would succeed if the scan selected a tiny carrier. This is also an avoidable network and memory amplification for every zero-column count.
For the zero-column path, use an inclusion projection that preserves cardinality while returning a bounded document (for example _id: 1; after an arbitrary pipeline, projecting even a missing _id still emits one small document per pipeline output). Keep the normal mapped-column projection unchanged. Add both Find and Aggregate regressions with a large irrelevant field, proving row count succeeds and the remote projection is genuinely minimal.
|
@Mergifyio queue |
Merge Queue Status
This pull request spent 1 hour 1 minute 41 seconds in the queue, including 1 hour 55 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #27536
What this PR does / why we need it:
Support explicit MongoDB filters and aggregation pipelines in external table scans.
Design
docs/rfcs/20260826_mongodb_explicit_query.md76b76496a70d2cca5f408f9ce19a617b5b01f75b.8fcd7fc2e076110d6362e70dc7fd2df5f7f8792a: passed 24 scenarios; profiler evidence israw_scan_documents=5andpipeline_documents=1.