Mongodb的複合(組合)查詢怎麼看explain?
世界只因有你
世界只因有你 2017-05-17 10:01:57
0
1
879

Mongodb的版本:v3.4

db.h.reateIndex({'port':1});
db.h.reateIndex({'geo.city':1});

在使用的時候

db.h.find({'port':'80','geo.city':'Taipei'},{'port':1,'geo.city':1,'geo.country':1})

explain('executionStats')

"executionStats" : {
                "executionSuccess" : true,
                "nReturned" : 280952,
                "executionTimeMillis" : 10056,
                "totalKeysExamined" : 879232,
                "totalDocsExamined" : 879232,
                "executionStages" : {
                        "stage" : "PROJECTION",
                        "nReturned" : 280952,
                        "executionTimeMillisEstimate" : 9763,
                        "works" : 879233,
                        "advanced" : 280952,
                        "needTime" : 598280,
                        "needYield" : 0,
                        "saveState" : 6915,
                        "restoreState" : 6915,
                        "isEOF" : 1,
                        "invalidates" : 0,
                        "transformBy" : {
                                "port" : 1,
                                "geo.city" : 1,
                                "geo.country" : 1,
                        },
                        "inputStage" : {
                                "stage" : "FETCH",
                                "filter" : {
                                        "geo.city" : {
                                                "$eq" : "Taipei"
                                        }
                                },
                                "nReturned" : 280952,
                                "executionTimeMillisEstimate" : 9246,
                                "works" : 879233,
                                "advanced" : 280952,
                                "needTime" : 598280,
                                "needYield" : 0,
                                "saveState" : 6915,
                                "restoreState" : 6915,
                                "isEOF" : 1,
                                "invalidates" : 0,
                                "docsExamined" : 879232,
                                "alreadyHasObj" : 0,
                                "inputStage" : {
                                        "stage" : "IXSCAN",
                                        "nReturned" : 879232,
                                        "executionTimeMillisEstimate" : 466,
                                        "works" : 879233,
                                        "advanced" : 879232,
                                        "needTime" : 0,
                                        "needYield" : 0,
                                        "saveState" : 6915,
                                        "restoreState" : 6915,
                                        "isEOF" : 1,
                                        "invalidates" : 0,
                                        "keyPattern" : {
                                                "port" : 1
                                        },
                                        "indexName" : "port_1",
                                        "isMultiKey" : false,
                                        "multiKeyPaths" : {
                                                "port" : [ ]
                                        },
                                        "isUnique" : false,
                                        "isSparse" : false,
                                        "isPartial" : false,
                                        "indexVersion" : 2,
                                        "direction" : "forward",
                                        "indexBounds" : {
                                                "port" : [
                                                        "[\"80\", \"80\"]"
                                                ]
                                        },
                                        "keysExamined" : 879232,
                                        "seeks" : 1,
                                        "dupsTested" : 0,
                                        "dupsDropped" : 0,
                                        "seenInvalidated" : 0
                                }
                        }
                }

像上面的例子,除了連接埠使用了索引嗎?還是兩個都使用了,如果兩個都使用了,那還要建立複合索引嗎?
謝謝

世界只因有你
世界只因有你

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!