does group command use indexes

51 views
Skip to first unread message

Chad Taylor

unread,
Jan 26, 2011, 9:49:56 PM1/26/11
to mongodb-user
Hello - I'm using the group function and would like to know if there
is anything specific I need to do to take advantage of the
collection's indexes. I thought it would use the index as long as I
specified the attributes in the cond that I've created a compound
index for. But it doesn't appear so. I can do an explain on a find
(with the same conditions) and I see that it uses the correct index.
However, when I execute the group function (with the same conditions),
it takes over 3 minutes.

thanks!

Nat

unread,
Jan 26, 2011, 10:01:57 PM1/26/11
to mongodb-user
What kind of query do you do? Can you show the result?

Chad Taylor

unread,
Jan 26, 2011, 10:07:53 PM1/26/11
to mongodb-user
Thanks in advance. The only thing I can surmise is that I need to
index the "_entrance_ip".

TAKES SEVERAL MINUTES:
db.messages.group( { cond: {_timestamp_in_ms: {$gte :
Date.UTC(2011,0,16), $lt: Date.UTC(2011,0,17) }, "type" : "pageload",
"params[controller]" : "event", "params[action]" : "show" }, key:
{ "_entrance_ip" : true }, initial: { count : 0 }, reduce:
function(doc,out) { out.count++ } } ).length


WORKS AS EXPECTED (same condition as above):
db.messages.find( { "_timestamp_in_ms" : { $gte : Date.UTC(2011,0,16),
$lt: Date.UTC(2011,0,17) }, "type" : "pageload",
"params[controller]" : "event", "params[action]" : "show" }).count()
2122

WORKS AS EXPECTED:
db.messages.find( { "_timestamp_in_ms" : { $gte : Date.UTC(2011,0,16),
$lt: Date.UTC(2011,0,17) }, "type" : "pageload",
"params[controller]" : "event", "params[action]" : "show" }).explain()
{
"cursor" : "BtreeCursor upstream_campaign_reporting",
"nscanned" : 2122,
"nscannedObjects" : 2122,
"n" : 2122,
"millis" : 456,
"indexBounds" : {
"_timestamp_in_ms" : [
[
1295222400000,
1295136000000
]
],
"type" : [
[
"pageload",
"pageload"
]
],
"params[controller]" : [
[
"event",
"event"
]
],
"params[action]" : [
[
"show",
"show"
]
],
"_entrance_params[utm_source]" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
],
"_entrance_params[utm_campaign]" : [
[
{
"$minElement" : 1
},
{
"$maxElement" : 1
}
]
]

Eliot Horowitz

unread,
Jan 27, 2011, 1:49:38 AM1/27/11
to mongod...@googlegroups.com
Are the results correct?

It is supposed to use indexes.

What version are you running?

A simple check might be to remove the index and see if it gets a lot worse.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Chad Taylor

unread,
Jan 27, 2011, 6:21:01 PM1/27/11
to mongodb-user
I had to kill the op prior to getting the result set because it was
crushing our production env. However, the result set is correct
locally and in our test env (neither of which have the magnitude of
data that we have running thru prod). BTW, we are on 1.6.5 using
replica sets. I think I will get a data dump of prod data to play
with. I've turned on profiling locally, but it doesn't really give me
what I want. I mean it identifies the poor performers, but without
the equivalent of an explain plan for the group function, I'm just
guessing at which index it is supposed to use.
Reply all
Reply to author
Forward
0 new messages