greenman
unread,Nov 16, 2011, 11:03:49 AM11/16/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongodb-user
Hi Marc,
Thanks for your answer...
I tried to get the queries from log file while using mongodb ruby
driver. the unfortunate thing is even if I add the sort clause to the
query in log, its not shown as part of the query. .. I see both
queries with and without sort clause are same in log file ({:sort
=> [["added_at",-1]]})
hence after adding manually sort to the queries on mongo shell I got
the following plan.. which looks similar to the one described above...
1) Query without sort....
db.threads.find({"$or":
[{'recipient_id':ObjectId('4d0a429ad7226105c60006ac'),
'is_deleted_by_recipient':false}, {'is_replied':true,
'is_deleted_by_sender':false,
'sender_id':ObjectId('4d0a429ad7226105c60006ac')}]}).explain(true)
{
"clauses" : [
{
"cursor" : "BtreeCursor
recipient_id_-1_is_deleted_by_recipient_-1_message_added_at_-1",
"nscanned" : 50,
"nscannedObjects" : 50,
"n" : 50,
"millis" : 0,
"indexBounds" : {
"recipient_id" : [
[
ObjectId("4d0a429ad7226105c60006ac"),
ObjectId("4d0a429ad7226105c60006ac")
]
],
"is_deleted_by_recipient" : [
[
false,
false
]
],
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
},
"allPlans" : [
{
"cursor" : "BtreeCursor
recipient_id_-1_is_deleted_by_recipient_-1_message_added_at_-1",
"indexBounds" : {
"recipient_id" : [
[
ObjectId("4d0a429ad7226105c60006ac"),
ObjectId("4d0a429ad7226105c60006ac")
]
],
"is_deleted_by_recipient" : [
[
false,
false
]
],
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
}
]
},
{
"cursor" : "BtreeCursor
sender_id_-1_is_deleted_by_sender_-1_message_added_at_-1",
"nscanned" : 0,
"nscannedObjects" : 0,
"n" : 0,
"millis" : 0,
"indexBounds" : {
"sender_id" : [
[
ObjectId("4d0a429ad7226105c60006ac"),
ObjectId("4d0a429ad7226105c60006ac")
]
],
"is_deleted_by_sender" : [
[
false,
false
]
],
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
},
"allPlans" : [
{
"cursor" : "BtreeCursor
sender_id_-1_is_deleted_by_sender_-1_message_added_at_-1",
"indexBounds" : {
"sender_id" : [
[
ObjectId("4d0a429ad7226105c60006ac"),
ObjectId("4d0a429ad7226105c60006ac")
]
],
"is_deleted_by_sender" : [
[
false,
false
]
],
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
},
{
"cursor" : "BasicCursor",
"indexBounds" : {
}
}
]
}
],
"nscanned" : 50,
"nscanneObjects" : 50,
"n" : 50,
"millis" : 0
}
2) Query with sort option....
db.threads.find({"$or":
[{'recipient_id':ObjectId('4d0a429ad7226105c60006ac'),
'is_deleted_by_recipient':false}, {'is_replied':true,
'is_deleted_by_sender':false,
'sender_id':ObjectId('4d0a429ad7226105c60006ac')}]}).sort({message_added_at:
-1}).explain(true);
{
"cursor" : "BtreeCursor message_added_at_-1",
"nscanned" : 545760,
"nscannedObjects" : 545760,
"n" : 50,
"millis" : 925,
"indexBounds" : {
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
},
"allPlans" : [
{
"cursor" : "BtreeCursor message_added_at_-1",
"indexBounds" : {
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
}
],
"oldPlan" : {
"cursor" : "BtreeCursor message_added_at_-1",
"indexBounds" : {
"message_added_at" : [
[
{
"$maxElement" : 1
},
{
"$minElement" : 1
}
]
]
}
}
}
Perhaps you have clue what could be wrong..
thxs,,