I have run the below query
db.getCollection('COL1').find(
{
"type": "A",
"dt_tm" : {
$gte: ISODate("2020-08-17 00:00:00.000Z"),
$lt: ISODate("2020-09-17 00:00:00.000Z")}
},
{_id:0, "type":1, "dt_tm":1 }
)
There is an index on the type and dt_tm column, query uses that index and returned 2886148 records from the IXSCAN stage[Time taken in this index stage is 283ms] , from this stage it goes to PROJECTION_COVERED returning the same records[Time taken in this stage is 82ms].
Then added one more column by name teams in the projection of the above query.
Below is the query
db.getCollection('COL1').find(
{"type": "A",
"dt_tm" : {
$gte: ISODate("2020-08-17 00:00:00.000Z"),
$lt: ISODate("2020-09-17 00:00:00.000Z")}
},
{_id:0, "type":1, "dt_tm":1, "teams":1}
)
Now executed the above query, Mongo uses the same index and returned 2886148 records from the IXSCAN stage[Time taken in this index stage is 771ms].
The time taken is increased here from 283ms to 771ms. Why is this difference since it has used the same index and returning the same record count from the IXSCAN stage…?
Here the FETCH stage is added additionally and it is returning the same records [Time taken is 681ms].
Next is the PROJECTION_SAMPLE stage , giving the same records but time taken is 742ms.
We can see that time taken is increased both in IXSCAN and the PROJECTION_SAMPLE stage, can any one help, why there is increase in the time…?