0% found this document useful (0 votes)
4 views

Performance Query

The document provides detailed query performance summaries for MongoDB operations including find and aggregate commands. It highlights the number of documents returned, execution time, and stages of query execution such as COLLSCAN and SORT, with specific metrics for ascending and descending sorts. The performance metrics indicate that the queries examined 10,000 documents with varying execution times, primarily relying on collection scans.

Uploaded by

lili 879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Performance Query

The document provides detailed query performance summaries for MongoDB operations including find and aggregate commands. It highlights the number of documents returned, execution time, and stages of query execution such as COLLSCAN and SORT, with specific metrics for ascending and descending sorts. The performance metrics indicate that the queries examined 10,000 documents with varying execution times, primarily relying on collection scans.

Uploaded by

lili 879
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 12

find() => Query Performance Summary (MongoDB Compass Explain)

1. Documents Returned:10000
2. index Keys Examined:0
3. Documents Examined:10000
4. Actual Query Execution Time (ms):7
5. Sorted in Memory:no
6. COLLSCAN Details {
"stage": "COLLSCAN",
"nReturned": 10000,
"executionTimeMillisEstimate": 5,
"works": 10002,
"advanced": 10000,
"needTime": 1,
"needYield": 0,
"saveState": 78,
"restoreState": 78,
"isEOF": 1,
"direction": "forward",
"docsExamined": 10000
}
-----------------------------------------------------------------------------------
----------------------------------------
find() => Query Performance Summary (MongoDB Shell Command)
-> Query : db.player.find().sort({"Name":
1}).pretty().explain("executionStats")

results :

{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"winningPlan" : {
"stage" : "COLLSCAN",
"direction" : "forward"
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 10000,
"executionTimeMillis" : 3,
"totalKeysExamined" : 0,
"totalDocsExamined" : 10000,
"executionStages" : {
"stage" : "COLLSCAN",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 0,
"works" : 10002,
"advanced" : 10000,
"needTime" : 1,
"needYield" : 0,
"saveState" : 78,
"restoreState" : 78,
"isEOF" : 1,
"direction" : "forward",
"docsExamined" : 10000
}
},
"serverInfo" : {
"host" : "cluster0-shard-00-02-vt6ia.mongodb.net",
"port" : 27017,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593490710, 12),
"signature" : {
"hash" : BinData(0,"UL+oqkSOp7dGR42y/Fdi6DTvuQI="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593490710, 12)
}

===================================================================================
========================================

sort() ASCENDING => Query Performance Summary (MongoDB Compass Explain) ->
{ "Name": 1 }
1. Documents Returned:10000
2. Index Keys Examined:0
3. Documents Examined:10000
4. Actual Query Execution Time (ms):32
5. Sorted in Memory:yes
6. SORT -> {
"stage": "SORT",
"nReturned": 10000,
"executionTimeMillisEstimate": 11,
"works": 20004,
"advanced": 10000,
"needTime": 10003,
"needYield": 0,
"saveState": 156,
"restoreState": 156,
"isEOF": 1,
"sortPattern": {
"Name": 1
},
"memUsage": 4144208,
"memLimit": 33554432
}
SORT_KEY GENERATOR -> {
"stage": "SORT_KEY_GENERATOR",
"nReturned": 10000,
"executionTimeMillisEstimate": 3,
"works": 10003,
"advanced": 10000,
"needTime": 2,
"needYield": 0,
"saveState": 156,
"restoreState": 156,
"isEOF": 1,
"parentName": "SORT"
}

COLLSCAN -> {
"stage": "COLLSCAN",
"nReturned": 10000,
"executionTimeMillisEstimate": 0,
"works": 10002,
"advanced": 10000,
"needTime": 1,
"needYield": 0,
"saveState": 156,
"restoreState": 156,
"isEOF": 1,
"direction": "forward",
"docsExamined": 10000,
"parentName": "SORT_KEY_GENERATOR"
}

sort() DESCENDING => Query Performance Summary (MongoDB Compass Explain) ->
{ "Name": -1 }
1. Documents Returned:10000
2. Index Keys Examined:0
3. Documents Examined:10000
4. Actual Query Execution Time (ms):32
5. Sorted in Memory:yes
6. SORT {
"stage": "SORT",
"nReturned": 10000,
"executionTimeMillisEstimate": 10,
"works": 20004,
"advanced": 10000,
"needTime": 10003,
"needYield": 0,
"saveState": 156,
"restoreState": 156,
"isEOF": 1,
"sortPattern": {
"Name": -1
},
"memUsage": 4144208,
"memLimit": 33554432
}
SORT_KEY_GENERATOR {
"stage": "SORT_KEY_GENERATOR",
"nReturned": 10000,
"executionTimeMillisEstimate": 2,
"works": 10003,
"advanced": 10000,
"needTime": 2,
"needYield": 0,
"saveState": 156,
"restoreState": 156,
"isEOF": 1,
"parentName": "SORT"
}
COLLSCAN {
"stage": "COLLSCAN",
"nReturned": 10000,
"executionTimeMillisEstimate": 1,
"works": 10002,
"advanced": 10000,
"needTime": 1,
"needYield": 0,
"saveState": 156,
"restoreState": 156,
"isEOF": 1,
"direction": "forward",
"docsExamined": 10000,
"parentName": "SORT_KEY_GENERATOR"
}
-----------------------------------------------------------------------------------
----------------------------------------

sort() => Query Performance Summary (MongoDB Shell Command)

results:
Ascending :
-> Query : db.player.find().sort({"Name": 1}).pretty()
-> Query : db.player.find().sort({"Name": 1}).pretty().explain("executionStats") ->
query show execution status
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"winningPlan" : {
"stage" : "SORT",
"sortPattern" : {
"Name" : 1
},
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "COLLSCAN",
"direction" : "forward"
}
}
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 10000,
"executionTimeMillis" : 31,
"totalKeysExamined" : 0,
"totalDocsExamined" : 10000,
"executionStages" : {
"stage" : "SORT",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 8,
"works" : 20004,
"advanced" : 10000,
"needTime" : 10003,
"needYield" : 0,
"saveState" : 156,
"restoreState" : 156,
"isEOF" : 1,
"sortPattern" : {
"Name" : 1
},
"memUsage" : 4144208,
"memLimit" : 33554432,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 0,
"works" : 10003,
"advanced" : 10000,
"needTime" : 2,
"needYield" : 0,
"saveState" : 156,
"restoreState" : 156,
"isEOF" : 1,
"inputStage" : {
"stage" : "COLLSCAN",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 0,
"works" : 10002,
"advanced" : 10000,
"needTime" : 1,
"needYield" : 0,
"saveState" : 156,
"restoreState" : 156,
"isEOF" : 1,
"direction" : "forward",
"docsExamined" : 10000
}
}
}
},
"serverInfo" : {
"host" : "cluster0-shard-00-02-vt6ia.mongodb.net",
"port" : 27017,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593491898, 1),
"signature" : {
"hash" : BinData(0,"Y9SmxwMebM5bo1eUGgmjQkUBUQg="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593491898, 1)
}

Descending :
-> Query : db.player.find().sort({"Name": -1}).pretty()
-> Query 1 : db.player.find().sort({"Name": -1}).pretty().explain("executionStats")
-> query show execution status
{
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" : "fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"winningPlan" : {
"stage" : "SORT",
"sortPattern" : {
"Name" : -1
},
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"inputStage" : {
"stage" : "COLLSCAN",
"direction" : "forward"
}
}
},
"rejectedPlans" : [ ]
},
"executionStats" : {
"executionSuccess" : true,
"nReturned" : 10000,
"executionTimeMillis" : 31,
"totalKeysExamined" : 0,
"totalDocsExamined" : 10000,
"executionStages" : {
"stage" : "SORT",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 11,
"works" : 20004,
"advanced" : 10000,
"needTime" : 10003,
"needYield" : 0,
"saveState" : 156,
"restoreState" : 156,
"isEOF" : 1,
"sortPattern" : {
"Name" : -1
},
"memUsage" : 4144208,
"memLimit" : 33554432,
"inputStage" : {
"stage" : "SORT_KEY_GENERATOR",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 0,
"works" : 10003,
"advanced" : 10000,
"needTime" : 2,
"needYield" : 0,
"saveState" : 156,
"restoreState" : 156,
"isEOF" : 1,
"inputStage" : {
"stage" : "COLLSCAN",
"nReturned" : 10000,
"executionTimeMillisEstimate" : 0,
"works" : 10002,
"advanced" : 10000,
"needTime" : 1,
"needYield" : 0,
"saveState" : 156,
"restoreState" : 156,
"isEOF" : 1,
"direction" : "forward",
"docsExamined" : 10000
}
}
}
},
"serverInfo" : {
"host" : "cluster0-shard-00-02-vt6ia.mongodb.net",
"port" : 27017,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593492305, 1),
"signature" : {
"hash" : BinData(0,"vCYuHvsC/UmaqrK3P87vQhY0494="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593492305, 1)
}

===================================================================================
=======================================

Aggregate

1. $sum -> Query : db.player.aggregate([ { $group: {_id: "$Club", Total:


{$sum:1}}}]).pretty() -> query show data
db.player.aggregate([ { $group: {_id: "$Club", Total:{$sum:1}}}],
{explain:true}) -> query show

explainStats
Performance : {
"stages" : [
{
"$cursor" : {
"query" : {

},
"fields" : {
"Club" : 1,
"_id" : 0
},
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" :
"5ef98b244c7d431c28d3ced3_fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"queryHash" : "8B3D4AB8",
"planCacheKey" : "8B3D4AB8",
"winningPlan" : {
"stage" : "COLLSCAN",
"direction" : "forward"
},
"rejectedPlans" : [ ]
}
}
},
{
"$group" : {
"_id" : "$Club",
"Total" : {
"$sum" : {
"$const" : 1
}
}
}
}
],
"serverInfo" : {
"host" : "atlas-xms0hk-shard-00-02.r4ytv.mongodb.net",
"port" : 27000,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593497107, 1),
"signature" : {
"hash" : BinData(0,"mxFfyWkgPDYFNk4TR+V4OY/H5Nw="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593497107, 1)
}
-----------------------------------------------------------------------------------
----------------------------------------
2. $avg -> Query : db.player.aggregate([ { $group: {_id:"$Name", TotalAverage :
{ $avg: {$toInt: "$Physical"}}}},
{ "$sort": { "TotalAverage": -
1 }}]).pretty()

show explain stats : db.player.aggregate([ { $group: {_id:"$Name", TotalAverage :


{ $avg: {$toInt: "$Physical"}}}}],
{explain:true})

Performance : {
"stages" : [
{
"$cursor" : {
"query" : {

},
"fields" : {
"Name" : 1,
"Physical" : 1,
"_id" : 0
},
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" :
"5ef98b244c7d431c28d3ced3_fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"queryHash" : "8B3D4AB8",
"planCacheKey" : "8B3D4AB8",
"winningPlan" : {
"stage" : "COLLSCAN",
"direction" : "forward"
},
"rejectedPlans" : [ ]
}
}
},
{
"$group" : {
"_id" : "$Name",
"TotalAverage" : {
"$avg" : {
"$convert" : {
"input" : "$Physical",
"to" : {
"$const" : "int"
}
}
}
}
}
}
],
"serverInfo" : {
"host" : "atlas-xms0hk-shard-00-02.r4ytv.mongodb.net",
"port" : 27000,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593501989, 2),
"signature" : {
"hash" : BinData(0,"uYU9JXw5DZWrBdWzeAKOIDzhu3M="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593501989, 2)
}

-----------------------------------------------------------------------------------
----------------------------------------
3. $min -> -> Query : db.player.aggregate([ { $group: {_id:"$Name",
MaxPhysicalStats:{$min:"$Physical"}}},
{ "$sort":
{ "MaxPhysicalStats": 1 }}]).pretty() -> show data
show explain stats : db.player.aggregate([ { $group: {_id:"$Name",
MaxPhysicalStats:{$min:"$Physical"}}}],{explain:true})

Performance : {
"stages" : [
{
"$cursor" : {
"query" : {

},
"fields" : {
"Name" : 1,
"Physical" : 1,
"_id" : 0
},
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" :
"5ef98b244c7d431c28d3ced3_fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"queryHash" : "8B3D4AB8",
"planCacheKey" : "8B3D4AB8",
"winningPlan" : {
"stage" : "COLLSCAN",
"direction" : "forward"
},
"rejectedPlans" : [ ]
}
}
},
{
"$group" : {
"_id" : "$Name",
"MaxPhysicalStats" : {
"$min" : "$Physical"
}
}
}
],
"serverInfo" : {
"host" : "atlas-xms0hk-shard-00-02.r4ytv.mongodb.net",
"port" : 27000,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593499808, 1),
"signature" : {
"hash" : BinData(0,"S8zqvYNrjMuNzBn71sbNH9XQtaw="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593499808, 1)
}
-----------------------------------------------------------------------------------
----------------------------------------
4. $max (Desc 9-0) -> Query : db.player.aggregate([ { $group: {_id:"$Name",
MaxPhysicalStats:{$max:"$Physical"}}},
{ "$sort":
{ "MaxPhysicalStats": -1 }}]).pretty() -> show data
show explain stats : db.player.aggregate([ { $group: {_id:"$Name",
MaxPhysicalStats:{$max:"$Physical"}}}],{explain:true})

performance : {
"stages" : [
{
"$cursor" : {
"query" : {

},
"fields" : {
"Name" : 1,
"Physical" : 1,
"_id" : 0
},
"queryPlanner" : {
"plannerVersion" : 1,
"namespace" :
"5ef98b244c7d431c28d3ced3_fifa20.player",
"indexFilterSet" : false,
"parsedQuery" : {

},
"queryHash" : "8B3D4AB8",
"planCacheKey" : "8B3D4AB8",
"winningPlan" : {
"stage" : "COLLSCAN",
"direction" : "forward"
},
"rejectedPlans" : [ ]
}
}
},
{
"$group" : {
"_id" : "$Name",
"MaxPhysicalStats" : {
"$max" : "$Physical"
}
}
}
],
"serverInfo" : {
"host" : "atlas-xms0hk-shard-00-02.r4ytv.mongodb.net",
"port" : 27000,
"version" : "4.2.8",
"gitVersion" : "43d25964249164d76d5e04dd6cf38f6111e21f5f"
},
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1593499778, 1),
"signature" : {
"hash" : BinData(0,"HoYMj05D2OU+GG+sQz+By80IfCw="),
"keyId" : NumberLong("6843396449003110402")
}
},
"operationTime" : Timestamp(1593499778, 1)
}

You might also like