-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Aggregation Framework, Querying
-
Query Optimization
-
(copied to CRM)
-
None
-
None
-
None
-
None
-
None
-
None
-
None
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.
- is related to
-
SERVER-34428 $facet aggregation stage does not use index created for the sub pipelines in it and perform COLLSCAN instead.
-
- Closed
-