mongodb - Mogodb使用了文本索引,就不能使用复合索引?
PHP中文网
PHP中文网 2017-05-24 11:31:30
0
1
762

是不是如果使用了文本索引,就不能使用复合索引?
因为我用了下面的查询语句但是只做了文本索引:

db.tests.find({$text:{$search:'zhangshan'},'age':5,'city':'beijing'}

通过explain查看,他是做了text的索引。然后再从这个索引中去过滤出其他条件的!
那么我该怎么做才能全部走索引呢?
我想到把所有字段建立一个text索引。因为数据量大,所以没有尝试,想问问这个可行吗?
谢谢


补充一下explain()

"executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 50424,
        "executionTimeMillis" : 510228,
        "totalKeysExamined" : 83546,
        "totalDocsExamined" : 167092,
        "executionStages" : {
            "stage" : "FETCH",
            "filter" : {
                "$and" : [
                    {
                        "age" : {
                            "$eq" : "5"
                        }
                    },
                    {
                        "city" : {
                            "$eq" : "beijing"
                        }
                    }
                ]
            },
            "nReturned" : 50424,
            "executionTimeMillisEstimate" : 509543,
            "works" : 167095,
            "advanced" : 50424,
            "needTime" : 116670,
            "needYield" : 0,
            "saveState" : 24418,
            "restoreState" : 24418,
            "isEOF" : 1,
            "invalidates" : 0,
            "docsExamined" : 83546,
            "alreadyHasObj" : 83546,
            "inputStage" : {
                "stage" : "TEXT",
                "nReturned" : 83546,
                "executionTimeMillisEstimate" : 509362,
                "works" : 167095,
                "advanced" : 83546,
                "needTime" : 83548,
                "needYield" : 0,
                "saveState" : 24418,
                "restoreState" : 24418,
                "isEOF" : 1,
                "invalidates" : 0,
                "indexPrefix" : {
                    
                },
                "indexName" : "banner_text",
                "parsedTextQuery" : {
                    "terms" : [
                        "ii"
                    ],
                    "negatedTerms" : [ ],
                    "phrases" : [ ],
                    "negatedPhrases" : [ ]
                },
                "textIndexVersion" : 3,
                "inputStage" : {
                    "stage" : "TEXT_MATCH",
                    "nReturned" : 83546,
                    "executionTimeMillisEstimate" : 509320,
                    "works" : 167095,
                    "advanced" : 83546,
                    "needTime" : 83548,
                    "needYield" : 0,
                    "saveState" : 24418,
                    "restoreState" : 24418,
                    "isEOF" : 1,
                    "invalidates" : 0,
                    "docsRejected" : 0,
                    "inputStage" : {
                        "stage" : "TEXT_OR",
                        "nReturned" : 83546,
                        "executionTimeMillisEstimate" : 509310,
                        "works" : 167095,
                        "advanced" : 83546,
                        "needTime" : 83548,
                        "needYield" : 0,
                        "saveState" : 24418,
                        "restoreState" : 24418,
                        "isEOF" : 1,
                        "invalidates" : 0,
                        "docsExamined" : 83546,
                        "inputStage" : {
                            "stage" : "IXSCAN",
                            "nReturned" : 83546,
                            "executionTimeMillisEstimate" : 1642,
                            "works" : 83547,
                            "advanced" : 83546,
                            "needTime" : 0,
                            "needYield" : 0,
                            "saveState" : 24418,
                            "restoreState" : 24418,
                            "isEOF" : 1,
                            "invalidates" : 0,
                            "keyPattern" : {
                                "_fts" : "text",
                                "_ftsx" : 1
                            },
                            "indexName" : "name_text",
                            "isMultiKey" : true,
                            "isUnique" : false,
                            "isSparse" : false,
                            "isPartial" : false,
                            "indexVersion" : 2,
                            "direction" : "backward",
                            "indexBounds" : {
                                
                            },
                            "keysExamined" : 83546,
                            "seeks" : 1,
                            "dupsTested" : 83546,
                            "dupsDropped" : 0,
                            "seenInvalidated" : 0
                        }
                    }
PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
世界只因有你

试着回答一下:

1、首先想看看你的复合索引是具体怎么建立的?

2、执行的结果是按照选择的执行计划执行的;如果性能不满意,可以使用hint来指定您所创建的复合索引。

Love MongoDB! Have fun!


2017MongoDB中文社区北京用户组大会在即,2017年6月3日 13:00-18:00

众多精彩分享!值得参与!

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!