Details
-
Improvement
-
Status: Backlog
-
Major - P3
-
Resolution: Unresolved
-
None
-
None
-
Query Optimization
-
(copied to CRM)
Description
Imagine you have an aggregation pipeline that looks something like:
db.collection.aggregate([
|
{$facet: {
|
xs: [
|
{$match: {x: "SOMETHING"}}, |
{$group: {...}}
|
],
|
ys: [
|
{$match: {y: "SOMETHING ELSE"}}, |
{$unwind: "$y"}, |
...
|
]
|
}}
|
])
|
Such a pipeline would not provide any predicates for the query system to use to begin the pipeline. This pipeline might benefit from being optimized to something more like:
db.collection.aggregate([
|
{$match: {$or: [{x: "SOMETHING"}, {y: "SOMETHING ELSE"}]}}, |
{$facet: {
|
xs: [
|
{$match: {x: "SOMETHING"}}, |
{$group: {...}}
|
],
|
ys: [
|
{$match: {y: "SOMETHING ELSE"}}, |
{$unwind: "$y"}, |
...
|
]
|
}}
|
])
|
Original Description
$facet is not smart enough to use an index. if the only stage in a pipeline is $facet, the planning system will simply default to a COLLSCAN.
Attachments
Issue Links
- is related to
-
SERVER-34428 $facet aggregation stage does not use index created for the sub pipelines in it and perform COLLSCAN instead.
-
- Closed
-
- related to
-
DOCS-13879 Document that $facet cannot use indexes
-
- Closed
-