Mongodb在多键索引上使用$ all时不使用索引交集

时间:2017-10-06 07:23:24

标签: mongodb

我正在尝试创建一个集合,其中每个对象可以具有不同数量的属性,我必须在多个属性上过滤对象并返回在字段排序器上排序的结果。因此,我将这些属性添加为数组并在我的集合上创建了多键索引

db.ixisect.createIndex({"dimensions": 1, "sortorder": -1});

这就是我的数据外观

{
    "_id" : NumberLong("79076429340352512"),
    "record" : {
        "fiid" : NumberLong("79076429340352512"),
        "actor" : "Salmonweak",
        "action" : "Gematom",
        "data" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed molestie, lectus eu suscipit vulputate, orci magna gravida nibh, quis dignissim risus ipsum sed urna. Maecenas ullamcorper ligula a ipsum venenatis, ac sodales massa tincidunt. Ut odio diam, commodo in viverra vitae, eleifend sit amet eros. Aenean at enim ac tortor faucibus imperdiet non ac mauris. Ut pulvinar, eros et auctor suscipit, nunc lorem varius odio, vel ullamcorper ante urna at lorem. Duis volutpat egestas augue nec hendrerit. In venenatis vestibulum elit ut commodo. Donec ac elementum lectus, quis ultricies lacus. Duis placerat nec sapien luctus pharetra. Nulla facilisi.Nullam condimentum efficitur leo at condimentum. Pellentesque rhoncus massa arcu, eget tincidunt odio congue non. Etiam in ultricies lacus. Pellentesque pulvinar, turpis nec fringilla placerat, libero erat scelerisque tellus, nec pellentesque ligula tellus sit amet urna. Mauris lacinia cursus mauris, sed sollicitudin risus interdum in"
    },
    "dimensions" : [
        "500001110",
        "50000124",
        "50000133",
        "50000148",
        "50000157"
    ],
    "sortorder" : NumberLong("79076429340352512")
}    

db.ixisect.find( {dimensions: {$all: ["90000119", "90000144"]}}).explain(true)

{
"queryPlanner" : {
    "plannerVersion" : 1,
    "namespace" : "feeds.ixisect",
    "indexFilterSet" : false,
    "parsedQuery" : {
        "$and" : [
            {
                "dimensions" : {
                    "$eq" : "90000119"
                }
            },
            {
                "dimensions" : {
                    "$eq" : "90000144"
                }
            }
        ]
    },
    "winningPlan" : {
        "stage" : "FETCH",
        "filter" : {
            "dimensions" : {
                "$eq" : "90000119"
            }
        },
        "inputStage" : {
            "stage" : "IXSCAN",
            "keyPattern" : {
                "dimensions" : 1,
                "sortorder" : -1
            },
            "indexName" : "dimensions_1_sortorder_-1",
            "isMultiKey" : true,
            "isUnique" : false,
            "isSparse" : false,
            "isPartial" : false,
            "indexVersion" : 1,
            "direction" : "forward",
            "indexBounds" : {
                "dimensions" : [
                    "[\"90000144\", \"90000144\"]"
                ],
                "sortorder" : [
                    "[MaxKey, MinKey]"
                ]
            }
        }
    },
    "rejectedPlans" : [
        {
            "stage" : "FETCH",
            "filter" : {
                "dimensions" : {
                    "$eq" : "90000144"
                }
            },
            "inputStage" : {
                "stage" : "IXSCAN",
                "keyPattern" : {
                    "dimensions" : 1,
                    "sortorder" : -1
                },
                "indexName" : "dimensions_1_sortorder_-1",
                "isMultiKey" : true,
                "isUnique" : false,
                "isSparse" : false,
                "isPartial" : false,
                "indexVersion" : 1,
                "direction" : "forward",
                "indexBounds" : {
                    "dimensions" : [
                        "[\"90000119\", \"90000119\"]"
                    ],
                    "sortorder" : [
                        "[MaxKey, MinKey]"
                    ]
                }
            }
        }
    ]
},
"executionStats" : {
    "executionSuccess" : true,
    "nReturned" : 13,
    "executionTimeMillis" : 1,
    "totalKeysExamined" : 106,
    "totalDocsExamined" : 106,
    "executionStages" : {
        "stage" : "FETCH",
        "filter" : {
            "dimensions" : {
                "$eq" : "90000119"
            }
        },
        "nReturned" : 13,
        "executionTimeMillisEstimate" : 0,
        "works" : 108,
        "advanced" : 13,
        "needTime" : 93,
        "needYield" : 0,
        "saveState" : 1,
        "restoreState" : 1,
        "isEOF" : 1,
        "invalidates" : 0,
        "docsExamined" : 106,
        "alreadyHasObj" : 0,
        "inputStage" : {
            "stage" : "IXSCAN",
            "nReturned" : 106,
            "executionTimeMillisEstimate" : 0,
            "works" : 107,
            "advanced" : 106,
            "needTime" : 0,
            "needYield" : 0,
            "saveState" : 1,
            "restoreState" : 1,
            "isEOF" : 1,
            "invalidates" : 0,
            "keyPattern" : {
                "dimensions" : 1,
                "sortorder" : -1
            },
            "indexName" : "dimensions_1_sortorder_-1",
            "isMultiKey" : true,
            "isUnique" : false,
            "isSparse" : false,
            "isPartial" : false,
            "indexVersion" : 1,
            "direction" : "forward",
            "indexBounds" : {
                "dimensions" : [
                    "[\"90000144\", \"90000144\"]"
                ],
                "sortorder" : [
                    "[MaxKey, MinKey]"
                ]
            },
            "keysExamined" : 106,
            "dupsTested" : 106,
            "dupsDropped" : 0,
            "seenInvalidated" : 0
        }
    },
    "allPlansExecution" : [
        {
            "nReturned" : 12,
            "executionTimeMillisEstimate" : 0,
            "totalKeysExamined" : 107,
            "totalDocsExamined" : 107,
            "executionStages" : {
                "stage" : "FETCH",
                "filter" : {
                    "dimensions" : {
                        "$eq" : "90000144"
                    }
                },
                "nReturned" : 12,
                "executionTimeMillisEstimate" : 0,
                "works" : 107,
                "advanced" : 12,
                "needTime" : 95,
                "needYield" : 0,
                "saveState" : 1,
                "restoreState" : 1,
                "isEOF" : 0,
                "invalidates" : 0,
                "docsExamined" : 107,
                "alreadyHasObj" : 0,
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "nReturned" : 107,
                    "executionTimeMillisEstimate" : 0,
                    "works" : 107,
                    "advanced" : 107,
                    "needTime" : 0,
                    "needYield" : 0,
                    "saveState" : 1,
                    "restoreState" : 1,
                    "isEOF" : 0,
                    "invalidates" : 0,
                    "keyPattern" : {
                        "dimensions" : 1,
                        "sortorder" : -1
                    },
                    "indexName" : "dimensions_1_sortorder_-1",
                    "isMultiKey" : true,
                    "isUnique" : false,
                    "isSparse" : false,
                    "isPartial" : false,
                    "indexVersion" : 1,
                    "direction" : "forward",
                    "indexBounds" : {
                        "dimensions" : [
                            "[\"90000119\", \"90000119\"]"
                        ],
                        "sortorder" : [
                            "[MaxKey, MinKey]"
                        ]
                    },
                    "keysExamined" : 107,
                    "dupsTested" : 107,
                    "dupsDropped" : 0,
                    "seenInvalidated" : 0
                }
            }
        },
        {
            "nReturned" : 13,
            "executionTimeMillisEstimate" : 0,
            "totalKeysExamined" : 106,
            "totalDocsExamined" : 106,
            "executionStages" : {
                "stage" : "FETCH",
                "filter" : {
                    "dimensions" : {
                        "$eq" : "90000119"
                    }
                },
                "nReturned" : 13,
                "executionTimeMillisEstimate" : 0,
                "works" : 107,
                "advanced" : 13,
                "needTime" : 93,
                "needYield" : 0,
                "saveState" : 1,
                "restoreState" : 1,
                "isEOF" : 1,
                "invalidates" : 0,
                "docsExamined" : 106,
                "alreadyHasObj" : 0,
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "nReturned" : 106,
                    "executionTimeMillisEstimate" : 0,
                    "works" : 107,
                    "advanced" : 106,
                    "needTime" : 0,
                    "needYield" : 0,
                    "saveState" : 1,
                    "restoreState" : 1,
                    "isEOF" : 1,
                    "invalidates" : 0,
                    "keyPattern" : {
                        "dimensions" : 1,
                        "sortorder" : -1
                    },
                    "indexName" : "dimensions_1_sortorder_-1",
                    "isMultiKey" : true,
                    "isUnique" : false,
                    "isSparse" : false,
                    "isPartial" : false,
                    "indexVersion" : 1,
                    "direction" : "forward",
                    "indexBounds" : {
                        "dimensions" : [
                            "[\"90000144\", \"90000144\"]"
                        ],
                        "sortorder" : [
                            "[MaxKey, MinKey]"
                        ]
                    },
                    "keysExamined" : 106,
                    "dupsTested" : 106,
                    "dupsDropped" : 0,
                    "seenInvalidated" : 0
                }
            }
        }
    ]
},
"serverInfo" : {
    "host" : "ShreyasMBP.local",
    "port" : 27017,
    "version" : "3.2.9",
    "gitVersion" : "22ec9e93b40c85fc7cae7d56e7d6a02fd811088c"
},
"ok" : 1
}

Mongo甚至不考虑这里的指数交叉计划。 https://jira.mongodb.org/browse/SERVER-3071表示它将考虑多键索引上的自我索引交集。我在这里错过了什么吗?

我正在使用mongodb 3.2版

0 个答案:

没有答案