We have collection with 70k documents. On prod our query executing about 2,8 minute. We trier reproduce same case on another instance, but with the same collection size and on the worse in performance instance query takes 6 sec. What it can be? Cache?
Exec:
db.collection.stats()
do not show any info about cache. Does DocumentDB cache queries?
Here executionStats from slow db:
{
"queryPlanner": {
"plannerVersion": 1.0,
"namespace": "nnnnnnnn",
"winningPlan": {
"stage": "LIMIT_SKIP",
"inputStage": {
"stage": "SORT",
"sortPattern": {
"_tempSortEventId": -1.0
},
"inputStage": {
"stage": "SUBSCAN",
"inputStage": {
"stage": "COLLSCAN"
}
}
}
}
},
"executionStats": {
"executionSuccess": true,
"executionTimeMillis": "113311.697",
"planningTimeMillis": "0.303",
"executionStages": {
"stage": "LIMIT_SKIP",
"nReturned": "50",
"executionTimeMillisEstimate": "113310.782",
"inputStage": {
"stage": "SORT",
"nReturned": "50",
"executionTimeMillisEstimate": "113310.776",
"sortPattern": {
"_tempSortEventId": -1.0
},
"inputStage": {
"stage": "SUBSCAN",
"nReturned": "70107",
"executionTimeMillisEstimate": "110684.645",
"inputStage": {
"stage": "COLLSCAN",
"nReturned": "70107",
"executionTimeMillisEstimate": "67827.520",
"inputStage": {
"nReturned": "1",
"executionTimeMillisEstimate": "0.048"
}
}
}
}
}
},
"serverInfo": {
"host": "prod",
"port": 27017.0,
"version": "4.0.0"
},
"ok": 1.0,
"operationTime": Timestamp(1670838896,1)
}
request is following:
aggregate(
[
{
"$match" :
{
"ApplicationId" : NUUID("dd25dadc-6b22-4f81-995b-2cce698a111a"),
"FilterKeys" :
{
"$elemMatch" :
{
"Name" : "CorporateId",
"Value" : "bbbfe3a7-fbec-4c88-8746-adf883a2ae6b"
}
}
}
},
{
"$addFields" :
{
"_tempSortEventId" :
{
"$toLower" : "$EventId"
}
}
},
{
"$sort" :
{
"_tempSortEventId" : -1
}
},
{
"$project" :
{
"_tempSortEventId" : 0
}
},
{
"$skip" : 0
},
{
"$limit" : 50
}])