【问题标题】:Mongodb after Indexing Taking Longer execution time索引后的MongoDB需要更长的执行时间
【发布时间】:2022-01-11 20:18:08
【问题描述】:

我有 145359 个文档存储在本地 MongoDB 中,我正在尝试对其进行索引。加快我的查询速度。

{
  "Categorized": true
}

示例文档

{
    "_id" : "dbe14c04-bd1e-454a-af57-4ca61566c0c0",
    "Categorized" : true,
    "Archived" : false,
    "HasTorrent" : false,
    "TorrentFile" : null,
    "File" : {
        "TitlePattern" : null,
        "Extension" : ".mp4",
        "FileName" : "A Costume for Nicholas (Un Disfraz para Nicolas) (2020) 1080p WEBRip.mp4",
        "FileNameWithoutExtension" : "A Costume for Nicholas (Un Disfraz para Nicolas) (2020) 1080p WEBRip",
        "AdapterName" : "CandyBD",
        "AdapterNameLower" : "candybd",
        "Type" : 1,
        "SupportedISPs" : [ 
            "dotinternet"
        ]
    },
    "IsSaved" : false,
    "IsUpdated" : true,
    "MovieId" : "tt8045396",
    "Quality" : 16,
    "UpdateComplete" : true,
    "WatchCount" : 0,
    "Is3D" : false,
    "FileFoundDateTime" : ISODate("2022-01-03T02:12:03.236Z"),
    "InformationDateTime" : ISODate("2022-01-03T02:12:11.553Z"),
    "Dimension" : "1080p",
    "IsDubbed" : false
}

问题是当试图索引集合时

{
    "Categorized" : 1
}

根据罗盘返回的文档:94057 和已检查的文档:索引前的 145359 中的 94057,很好。但事情是在索引 Actual Query Execution Time (ms):95 (around) 和 CollScan Execution Time 为 0-11 平均 4 ms 之前。但是在索引 Actual Query Execution Time (ms):124 之后,Fetch 大约是 9 ms,Ixscan 大约是 5 ms。

这个值是什么意思,为什么我的查询在索引后执行的时间似乎更长了?

【问题讨论】:

    标签: mongodb indexing execution-time mongodb-compass


    【解决方案1】:

    您的集合中有 145359 个文档。当 T/F 分布接近 50/50 时,布尔字段并不是特别好的索引候选者,在这种情况下,您有 94057 个文档 (65%) 匹配 true。索引在这里真的不会对您有实质性帮助。

    【讨论】:

    • 但据我所知,不推荐使用 Full scan 或 Collscan 扫描所有 145359 个文档?
    • 由于文档数量不多,索引可能没用(150,000不是很大的文档量)。而且,正如上面答案中已经提到的,布尔字段不能作为索引字段的良好候选者。另外,请参阅Create Queries that Ensure Selectivity 上的此主题。我可以拥有一个包含数千个文档且没有索引的集合。我所有的查询都会进行集合扫描——这没有问题。
    猜你喜欢
    • 1970-01-01
    • 2010-12-18
    • 1970-01-01
    • 1970-01-01
    • 2020-05-22
    • 2013-03-19
    • 2020-11-28
    • 1970-01-01
    • 2016-09-08
    相关资源
    最近更新 更多