[SERVER-5361] early $group should provide a hint to use an index matching the group key Created: 22/Mar/12  Updated: 15/Aug/12  Resolved: 30/Mar/12

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

Type: Improvement Priority: Major - P3
Reporter: Chris Westin Assignee: Chris Westin
Resolution: Duplicate Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-4961 $group is taking 2x as long as collec... Closed
Related
is related to SERVER-4507 aggregation: optimize $group to take... Backlog
Participants:

 Description   

For an example query that could use this (assuming the appropriate index is there), see https://groups.google.com/forum/#!msg/mongodb-user/V5nO8gkgzbk/iI9F_faNPFsJ .



 Comments   
Comment by Chris Westin [ 29/Mar/12 ]

@Samual Garcia Martinez: values of query_hash can repeat for different date values, so there's no way to use a concatenated key index for this. The best that could be done would be to use an index on date to do the initial filtering. 2.1.1 already has that optimization.

Comment by Samuel García Martínez [ 29/Mar/12 ]

This makes a lot of sense. Even should use compound indexes, in order to use same index as previous $match clause.

Querying like
db.test_coll.aggregate(
{$match: { date:

{ $gte: ISODate('2010-09-01T00:00:00Z'), $lt: ISODate('2010-10-01T00:00:00Z')}

}},
{$group: {_id:

{query_hash:1}

,totalCount:{$sum:"$queryCount"}} },
{$skip:10},
{$limit:10}
);
should be this feature able to use a compound index with date and query_hash?

I think it would be nice to be able to use a compound index instead of using two separated indexes.

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