繁体   English   中英

MongoDb geoIntersects不使用IndexOnly

[英]MongoDb geoIntersects doesn't use IndexOnly

我有一个名为search2的集合,包含大约20000个这样的文档:

    {
        "loc": {
        "type": "Polygon",
        "coordinates": [
            [
            [
                43.78526674007639,
                11.14739998758569
            ],
            [
                43.78526674007639,
                11.183372851822439
            ],
            [
                43.79443488391605,
                11.183372851822439
            ],
            [
                43.79443488391605,
                11.264311796355125
            ],
            [
                43.812771171595415,
                11.264311796355125
            ],
            [
                43.83110745927479,
                11.264311796355125
            ],
            [
                43.83110745927479,
                11.273305012414314
            ],
            [
                43.849443746954144,
                11.273305012414314
            ],
            [
                43.858611890793824,
                11.273305012414314
            ],
            [
                43.858611890793824,
                11.264311796355125
            ],
            [
                43.8769481784732,
                11.264311796355125
            ],
            [
                43.8769481784732,
                11.246325364236752
            ],
            [
                43.88611632231286,
                11.246325364236752
            ],
            [
                43.88611632231286,
                11.237332148177565
            ],
            [
                43.895284466152546,
                11.237332148177565
            ],
            [
                43.895284466152546,
                11.228338932118376
            ],
            [
                43.904452609992234,
                11.228338932118376
            ],
            [
                43.904452609992234,
                11.165386419704065
            ],
            [
                43.895284466152546,
                11.165386419704065
            ],
            [
                43.895284466152546,
                11.156393203644878
            ],
            [
                43.88611632231286,
                11.156393203644878
            ],
            [
                43.8769481784732,
                11.156393203644878
            ],
            [
                43.858611890793824,
                11.156393203644878
            ],
            [
                43.849443746954144,
                11.156393203644878
            ],
            [
                43.849443746954144,
                11.165386419704065
            ],
            [
                43.83110745927479,
                11.165386419704065
            ],
            [
                43.83110745927479,
                11.156393203644878
            ],
            [
                43.812771171595415,
                11.156393203644878
            ],
            [
                43.812771171595415,
                11.14739998758569
            ],
            [
                43.79443488391605,
                11.14739998758569
            ],
            [
                43.78526674007639,
                11.14739998758569
            ]
            ]
        ]
        },
        "docId": 1,
        "docVote": 0,
        "title": "title-1",
        "_id": {
        "$oid": "5248725d2dd5622510000001"
        }
    }

我用这个命令定义一个索引:

    db.search2.ensureIndex({"loc":"2dsphere"});

在集合上,只有这个索引和“_id”字段的默认索引。

当我执行以下查询时,我希望解释中的indexOnly参数设置为true:

    db.search2.find({
        loc: {
        $geoIntersects: {
            $geometry: {
            type: "Polygon",
            coordinates: [
                [
                    [43.7269795, 11.1540365],
                    [43.7269796, 11.1540365],
                    [43.7269796, 11.1540366],
                    [43.7269795, 11.1540366],
                    [43.7269795, 11.1540365]
                ]
            ]
            }
        }
        }
    }, {
        loc: 1,
        _id: 0
    }).hint({"loc":"2dsphere"}).explain()

但这是结果:

    {
        "cursor" : "S2Cursor",
        "isMultiKey" : true,
        "n" : 14,
        "nscannedObjects" : 14,
        "nscanned" : 186,
        "nscannedObjectsAllPlans" : 14,
        "nscannedAllPlans" : 186,
        "scanAndOrder" : false,
        "indexOnly" : false,
        "nYields" : 0,
        "nChunkSkips" : 0,
        "millis" : 20,
        "indexBounds" : {

        },
        "nscanned" : 186,
        "matchTested" : NumberLong(80),
        "geoTested" : NumberLong(80),
        "cellsInCover" : NumberLong(1),
        "server" : "*******"
    }

我注意到isMultiKey为true,由文档多边形语法引起。 光标是S2Cursor,所以我认为使用了索引。 但是为什么indexOnly是假的? 是由于多边形语法? 那么IndexOnly = true是不可能的? 提前致谢

indexOnly来自这里的解释说明:

indexOnly是一个布尔值,当查询被光标字段中指示的索引覆盖时,该值返回true。 当索引覆盖查询时,MongoDB可以匹配查询条件并仅使用索引返回结果,因为:

  • 查询中的所有字段都是该索引的一部分,并且

  • 查询中的所有字段都是该索引的一部分,并且

这里它说:

在以下情况下,索引无法覆盖查询:

  • 集合中任何文档中的任何索引字段都包含一个数组。 如果索引字段是数组,则索引将成为多键索引索引,并且不支持覆盖查询。
  • 任何索引字段都是子文档中的字段。

希望能帮助到你

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM