[SERVER-32035] Index doesn't cover a query for a partial filter expression index under certain circumstances Created: 19/Nov/17  Updated: 17/Dec/17  Resolved: 21/Nov/17

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: 3.2.17
Fix Version/s: None

Type: Question Priority: Major - P3
Reporter: Ori Dar Assignee: Mark Agarunov
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-28889 Partial index shouldn't do fetch on c... Closed
Participants:

 Description   

The partial filter expression contains a scalar equality expression : "bool" : true

db.coll.getIndexes()
[
        ...
        {
                "v" : 1,
                "key" : {
                        "timestamp" : 1,
                        "userId" : 1
                },
                "name" : "timestamp_1_userId_1",
                "ns" : "...",
                "background" : true,
                "partialFilterExpression" : {
                        "bool" : true
                }
        }
]

A query contains the index fields, projects the index field and uses the single possible value for the partial expression:

db.coll.explain("executionStats").find({ timestamp: { $gte: 1511041284 }, userId: { $in: [ 1,2,3,4 ]}, bool: true },{timestamp: 1, userId:1, _id:0 })
{
        ...
        "executionStats" : {
                "executionSuccess" : true,
                "nReturned" : 2,
                "executionTimeMillis" : 14,
                "totalKeysExamined" : 294,
                "totalDocsExamined" : 2,
                "executionStages" : {
                        "stage" : "PROJECTION",
                        "nReturned" : 2,
                        "executionTimeMillisEstimate" : 0,
                        "works" : 296,
                        "advanced" : 2,
                        "needTime" : 292,
                        "needYield" : 0,
                        "saveState" : 4,
                        "restoreState" : 4,
                        "isEOF" : 1,
                        "invalidates" : 0,
                        "transformBy" : {
                                "timestamp" : 1,
                                "userId" : 1,
                                "_id" : 0
                        },
                        "inputStage" : {
                                "stage" : "FETCH",
                                "filter" : {
                                        "bool" : {
                                                "$eq" : true
                                        }
                                },
                                "nReturned" : 2,
                                "executionTimeMillisEstimate" : 0,
                                "works" : 296,
                                "advanced" : 2,
                                "needTime" : 292,
                                "needYield" : 0,
                                "saveState" : 4,
                                "restoreState" : 4,
                                "isEOF" : 1,
                                "invalidates" : 0,
                                "docsExamined" : 2,
                                "alreadyHasObj" : 0,
                                "inputStage" : {
                                        "stage" : "IXSCAN",
                                        "nReturned" : 2,
                                        "executionTimeMillisEstimate" : 0,
                                        "works" : 295,
                                        "advanced" : 2,
                                        "needTime" : 292,
                                        "needYield" : 0,
                                        "saveState" : 4,
                                        "restoreState" : 4,
                                        "isEOF" : 1,
                                        "invalidates" : 0,
                                        "keyPattern" : {
                                                "timestamp" : 1,
                                                "userId" : 1
                                        },
                                        "indexName" : "timestamp_1_userId_1",
                                        "isMultiKey" : false,
                                        "isUnique" : false,
                                        "isSparse" : false,
                                        "isPartial" : true,
                                        "indexVersion" : 1,
                                        "direction" : "forward",
                                        "indexBounds" : {
                                                "timestamp" : [
                                                        "[1511041284.0, inf.0]"
                                                ],
                                                "userId" : [
                                                        ...

Under such conditions, shouldn't it be enough for the index to cover the query?



 Comments   
Comment by Mark Agarunov [ 21/Nov/17 ]

Hello orid@trainologic.com,

Thank you for the report. Looking over the output you've described, I believe this is the same issue detailed in SERVER-28889 so I've closed this as a duplicate. Please follow SERVER-28889 for updates on this issue.

Thanks,
Mark

Generated at Thu Feb 08 04:28:58 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.