mongodb $ lookup不为简单的等式联接使用哈希索引

我有一个名为songs_test的集合,并且有一个字段“ artist_name”。我已经在同一目录上创建了哈希索引。

Black

然后,我运行以下聚合查询:

> db.songs_test.getIndexes()
[
    {
        "v" : 2,"key" : {
            "_id" : 1
        },"name" : "_id_","ns" : "songs_new.songs_test"
    },{
        "v" : 2,"key" : {
            "artist_name" : "hashed"
        },"name" : "artist_name_hashed","ns" : "songs_new.songs_test"
    }
]

运行此聚合查询大约需要13分钟。 Songs_test集合有100万条记录。当我做一个解释时-我发现查询没有使用索引。

说明输出:

use songs_new

db.songs_test.explain().aggregate([
        {$lookup : {
                 "from": "songs_test","localField": "artist_name","foreignField": "artist_name","as": "artist_name_matches"
                 }
        },{$unwind : "$artist_name_matches"}
],{allowDiskUse: true}
)

我尝试了各种方法(建议在网络上进行),但找不到确切的原因。此外,在8thread 64GB RAM计算机上运行大约需要13分钟。聚合查询仅使用一个线程(也很奇怪)。 有人可以帮忙为什么不使用索引以及为什么聚合在单个线程上运行吗?

tpl1123 回答:mongodb $ lookup不为简单的等式联接使用哈希索引

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3149113.html

大家都在问