mongodb在IXSCAN上运行缓慢

时间:2016-04-13 09:16:32

标签: mongodb

我无法弄清楚mongodb中的一些请求,我创建了一个索引来匹配请求中的所有字段,但它没有帮助

是索引中的问题吗?我应该在索引中包含哪些字段? 这是slowlog的一部分

query: { 
$query: { 
    moderation.blocked: false, 
    project_id: "9fd6db37-049f-4af3-bea4-8301345dc109", 
    dates.posted: { $gt: 1458720426.177019 }, 
    parent_ids: "31cd1be3-adbd-4108-a05e-58c283176738", 
    moderation.visible: true }, 
    $orderby: { dates.posted: 1 } 
} 
planSummary: IXSCAN { 
    parent_ids: 1, 
    dates.posted: 1, 
    owner_id: 1, 
    project_id: 1, 
    moderation.blocked: 1, 
    moderation.visible: -1 
} 
ntoreturn:0 
ntoskip:0 
nscanned:0 
nscannedObjects:0 
keyUpdates:0 
writeConflicts:0 
numYields:1 
nreturned:0 
reslen:20 
locks:{ Global: { acquireCount: { r: 4 } }, Database: { acquireCount: { r: 2 } }, Collection: { acquireCount: { r: 2 } } } 235ms

explain()查询相同的查询

{
'queryPlanner': {
    'plannerVersion': 1,
    'parsedQuery': {
        '$and': [{
            'moderation.blocked': {
                '$eq': False
            }
        }, {
            'moderation.visible': {
                '$eq': True
            }
        }, {
            'parent_ids': {
                '$eq': '31cd1be3-adbd-4108-a05e-58c283176738'
            }
        }, {
            'project_id': {
                '$eq': '9fd6db37-049f-4af3-bea4-8301345dc109'
            }
        }, {
            'dates.posted': {
                '$gt': 1458720426.177019
            }
        }]
    },
    'namespace': 'comments.comments',
    'rejectedPlans': [],
    'winningPlan': {
        'filter': {
            'moderation.visible': {
                '$eq': True
            }
        },
        'stage': 'FETCH',
        'inputStage': {
            'indexName': 'parent_ids_1_dates.posted_1_owner_id_1_project_id_1_moderation.blocked_1_moderation.visible_-1',
            'keyPattern': {
                'parent_ids': 1,
                'moderation.blocked': 1,
                'owner_id': 1,
                'moderation.visible': -1,
                'dates.posted': 1,
                'project_id': 1
            },
            'isMultiKey': True,
            'indexBounds': {
                'parent_ids': ['["31cd1be3-adbd-4108-a05e-58c283176738", "31cd1be3-adbd-4108-a05e-58c283176738"]'],
                'moderation.blocked': ['[false, false]'],
                'owner_id': ['[MinKey, MaxKey]'],
                'moderation.visible': ['[MaxKey, MinKey]'],
                'dates.posted': ['(1458720426.177019, inf.0]'],
                'project_id': ['["9fd6db37-049f-4af3-bea4-8301345dc109", "9fd6db37-049f-4af3-bea4-8301345dc109"]']
            },
            'stage': 'IXSCAN',
            'direction': 'forward'
        }
    },
    'indexFilterSet': False
},
'executionStats': {
    'totalDocsExamined': 0,
    'allPlansExecution': [],
    'totalKeysExamined': 0,
    'executionSuccess': True,
    'nReturned': 0,
    'executionStages': {
        'invalidates': 0,
        'filter': {
            'moderation.visible': {
                '$eq': True
            }
        },
        'isEOF': 1,
        'needTime': 0,
        'alreadyHasObj': 0,
        'advanced': 0,
        'inputStage': {
            'invalidates': 0,
            'isEOF': 1,
            'needTime': 0,
            'dupsDropped': 0,
            'dupsTested': 0,
            'keyPattern': {
                'parent_ids': 1,
                'moderation.blocked': 1,
                'owner_id': 1,
                'moderation.visible': -1,
                'dates.posted': 1,
                'project_id': 1
            },
            'advanced': 0,
            'seenInvalidated': 0,
            'nReturned': 0,
            'indexBounds': {
                'parent_ids': ['["31cd1be3-adbd-4108-a05e-58c283176738", "31cd1be3-adbd-4108-a05e-58c283176738"]'],
                'moderation.blocked': ['[false, false]'],
                'owner_id': ['[MinKey, MaxKey]'],
                'moderation.visible': ['[MaxKey, MinKey]'],
                'dates.posted': ['(1458720426.177019, inf.0]'],
                'project_id': ['["9fd6db37-049f-4af3-bea4-8301345dc109", "9fd6db37-049f-4af3-bea4-8301345dc109"]']
            },
            'needFetch': 0,
            'saveState': 0,
            'keysExamined': 0,
            'matchTested': 0,
            'executionTimeMillisEstimate': 0,
            'indexName': 'parent_ids_1_dates.posted_1_owner_id_1_project_id_1_moderation.blocked_1_moderation.visible_-1',
            'restoreState': 0,
            'works': 1,
            'direction': 'forward',
            'stage': 'IXSCAN',
            'isMultiKey': True
        },
        'stage': 'FETCH',
        'saveState': 0,
        'docsExamined': 0,
        'nReturned': 0,
        'restoreState': 0,
        'works': 1,
        'executionTimeMillisEstimate': 0,
        'needFetch': 0
    },
    'executionTimeMillis': 0
}

0 个答案:

没有答案