MongoDB медленная фасетная производительность - PullRequest
0 голосов
/ 14 декабря 2018

У меня есть следующий фасетный запрос в MongoDB, на котором у меня низкая производительность.Ниже приведен граненый запрос по сравнению с запросом без агрегации.Кто-нибудь знает, как заставить фасетный запрос работать лучше?

db.texts.explain("allPlansExecution").aggregate([ { '$facet': { texts: [ { '$limit': 30 } ] } } ])

Что дает следующее объяснение

{
    "stages" : [
        {
            "$cursor" : {
                "query" : {

                },
                "queryPlanner" : {
                    "plannerVersion" : 1,
                    "namespace" : "db.texts",
                    "indexFilterSet" : false,
                    "parsedQuery" : {

                    },
                    "winningPlan" : {
                        "stage" : "COLLSCAN",
                        "direction" : "forward"
                    },
                    "rejectedPlans" : [ ]
                },
                "executionStats" : {
                    "executionSuccess" : true,
                    "nReturned" : 3497,
                    "executionTimeMillis" : 231,
                    "totalKeysExamined" : 0,
                    "totalDocsExamined" : 3497,
                    "executionStages" : {
                        "stage" : "COLLSCAN",
                        "nReturned" : 3497,
                        "executionTimeMillisEstimate" : 0,
                        "works" : 3499,
                        "advanced" : 3497,
                        "needTime" : 1,
                        "needYield" : 0,
                        "saveState" : 40,
                        "restoreState" : 40,
                        "isEOF" : 1,
                        "invalidates" : 0,
                        "direction" : "forward",
                        "docsExamined" : 3497
                    },
                    "allPlansExecution" : [ ]
                }
            }
        },
        {
            "$facet" : {
                "texts" : [
                    {
                        "$limit" : NumberLong(30)
                    }
                ]
            }
        }
    ],
    "ok" : 1
}

Я сравнил приведенный выше запрос с запросом без фасета, и он намного быстрее

db.texts.explain("allPlansExecution").find({}).limit(30)

С объяснением

{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "copybank.texts",
        "indexFilterSet" : false,
        "parsedQuery" : {

        },
        "winningPlan" : {
            "stage" : "LIMIT",
            "limitAmount" : 30,
            "inputStage" : {
                "stage" : "COLLSCAN",
                "direction" : "forward"
            }
        },
        "rejectedPlans" : [ ]
    },
    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 30,
        "executionTimeMillis" : 0,
        "totalKeysExamined" : 0,
        "totalDocsExamined" : 30,
        "executionStages" : {
            "stage" : "LIMIT",
            "nReturned" : 30,
            "executionTimeMillisEstimate" : 0,
            "works" : 32,
            "advanced" : 30,
            "needTime" : 1,
            "needYield" : 0,
            "saveState" : 0,
            "restoreState" : 0,
            "isEOF" : 1,
            "invalidates" : 0,
            "limitAmount" : 30,
            "inputStage" : {
                "stage" : "COLLSCAN",
                "nReturned" : 30,
                "executionTimeMillisEstimate" : 0,
                "works" : 31,
                "advanced" : 30,
                "needTime" : 1,
                "needYield" : 0,
                "saveState" : 0,
                "restoreState" : 0,
                "isEOF" : 0,
                "invalidates" : 0,
                "direction" : "forward",
                "docsExamined" : 30
            }
        },
        "allPlansExecution" : [ ]
    },
    "ok" : 1
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...