【问题标题】:getMore executor error: Overflow sort stage buffered data usage exceeds internal limitgetMore 执行器错误:溢出排序阶段缓冲数据使用量超过内部限制
【发布时间】:2015-05-13 11:14:56
【问题描述】:

这不是一个重复的问题。所有其他答案都说解决方案是在排序键上创建索引。就我而言,我确实有一个索引,但仍然面临这个错误

给定一个 mongodb 集合,其文档类似于:

{
    '_id': ...,
    'title': ...,
    'price': ...,
    'category_id': ...,
    'last_updated': ...,
    ... other keys
}

category_id 上有一个升序单字段索引,last_updated 有一个降序单字段索引。

以下查询崩溃:

> var c = db.collection_name.find({category_id: "categ_id"}, {_id: 0, price: 1, title: 1}).sort({last_updated: -1}).limit(20000).batchSize(500)
> c.forEach(function(doc) {
... ;
... })
2015-05-13T10:00:46.561+0000 E QUERY    Error: error: {
        "$err" : "getMore executor error: Overflow sort stage buffered data usage of 33554596 bytes exceeds internal limit of 33554432 bytes",
        "code" : 17406
}
    at Error (<anonymous>)
    at DBQuery.next (src/mongo/shell/query.js:259:15)
    at DBQuery.forEach (src/mongo/shell/query.js:414:20)
    at (shell):1:3 at src/mongo/shell/query.js:259

如果有帮助,这里是查询的解释:

{
        "queryPlanner" : {
                "plannerVersion" : 1,
                "namespace" : "db_name.collection_name",
                "indexFilterSet" : false,
                "parsedQuery" : {
                        "category_id" : {
                                "$eq" : "categ_id"
                        }
                },
                "winningPlan" : {
                        "stage" : "PROJECTION",
                        "transformBy" : {
                                "_id" : 0,
                                "price" : 1,
                                "title" : 1
                        },
                        "inputStage" : {
                                "stage" : "SORT",
                                "sortPattern" : {
                                        "last_updated" : -1
                                },
                                "limitAmount" : 500,
                                "inputStage" : {
                                        "stage" : "KEEP_MUTATIONS",
                                        "inputStage" : {
                                                "stage" : "FETCH",
                                                "inputStage" : {
                                                        "stage" : "IXSCAN",
                                                        "keyPattern" : {
                                                                "category_id" : 1
                                                        },
                                                        "indexName" : "category_id_1",
                                                        "isMultiKey" : false,
                                                        "direction" : "forward",
                                                        "indexBounds" : {
                                                                "category_id" : [
                                                                        "[\"categ_id\", \"categ_id\"]"
                                                                ]
                                                        }
                                                }
                                        }
                                }
                        }
                },
                "rejectedPlans" : [
                        {
                                "stage" : "LIMIT",
                                "limitAmount" : 500,
                                "inputStage" : {
                                        "stage" : "PROJECTION",
                                        "transformBy" : {
                                                "_id" : 0,
                                                "price" : 1,
                                                "title" : 1
                                        },
                                        "inputStage" : {
                                                "stage" : "FETCH",
                                                "filter" : {
                                                        "category_id" : {
                                                                "$eq" : "categ_id"
                                                        }
                                                },
                                                "inputStage" : {
                                                        "stage" : "IXSCAN",
                                                        "keyPattern" : {
                                                                "last_updated" : 1
                                                        },
                                                        "indexName" : "last_updated_1",
                                                        "isMultiKey" : false,
                                                        "direction" : "backward",
                                                        "indexBounds" : {
                                                                "last_updated" : [
                                                                        "[MaxKey, MinKey]"
                                                                ]
                                                        }
                                                }
                                        }
                                }
                        }
                ]
        },
        "serverInfo" : {
                "host" : "host",
                "port" : 27017,
                "version" : "3.0.2",
                "gitVersion" : "6201872043ecbbc0a4cc169b5482dcf385fc464f"
        },
        "ok" : 1
}

有趣的是,此错误仅发生在特定类别而不是全部。此外,如果我删除 batchSize 选项,查询不会崩溃(不管我为批处理设置的大小)。

值得注意的是last_updated字段可能并不存在于所有文档中。

【问题讨论】:

    标签: mongodb mongodb-query


    【解决方案1】:

    所以,原来线索在我的问题的查询解释中。由于查询中使用了category_id,因此查询优化器选择使用category_id 索引并完全忽略last_updated 索引。我的想法是它将使用category_id 进行获取和last_updated 进行排序,但这似乎不是mongodb 查询的工作方式。为了解决这个问题,需要按顺序为category_idlast_updated 创建复合索引:

    db.collection_name.createIndex({category_id: 1, last_updated: -1})
    

    【讨论】:

      猜你喜欢
      • 2015-01-17
      • 2015-02-02
      • 2017-03-23
      • 2016-01-15
      • 2015-08-03
      • 1970-01-01
      • 2017-05-12
      相关资源
      最近更新 更多