[SERVER-15026] Allow covered queries for first stage of Pipeline Aggregation Created: 25/Aug/14  Updated: 26/Sep/16  Resolved: 08/Apr/15

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Rod Adams Assignee: Unassigned
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-12015 Reenable use of covering indexes with... Closed
Related
Backwards Compatibility: Fully Compatible
Participants:

 Description   

In select cases, it would be beneficial to users if they could make use of covered queries as the first stage of a pipeline aggregation. One use case would be for aggregating the metadata on a collection with a very large blob on each document, where the blob is not part of the query.

My suggestion would be that if an aggregations starts off with a combination of $match, $sort, and $project, with the $project required, then it be considered for a covered query by the planner. Any of these combinations should be directly translatable to a .find() which does have the potential to be covered.

Example:

db.coll.insert({
  created: ISODate('2014-07-04'),
  type: 'Blog',
  size: 1234567,
  title: 'My Title',
  body: '<2MB text string>',
})
 
db.coll.ensureIndex({created:1, type: 1, size:1})
 
db.coll.aggregate([
  {$match: {created: {$gte: ISODate('2014-01-01')}}},
  {$project: {size: 1, type:1, _id :0}},
  // Up to here is a covered query.
  {$group: {_id: '$type',
            total_size: {$sum: '$size'},
            count: {$sum: 1}}}
  ])



 Comments   
Comment by Asya Kamsky [ 08/Apr/15 ]

Duplicate of SERVER-12015

Generated at Thu Feb 08 03:36:42 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.