在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)庫/ MongoDB分析查詢
MongoDB教程
MongoDB覆蓋查詢
MongoDB數(shù)據(jù)建模
MongoDB聚合
MongoDB更改用戶密碼和自定義數(shù)據(jù)
MongoDB用戶
MongoDB分片
MongoDB創(chuàng)建集合
MongoDB文本搜索
MongoDB數(shù)據(jù)類型
MongoDB GridFS
MongoDB索引限制
MongoDB插入文檔
MongoDB刪除集合
MongoDB數(shù)據(jù)庫引用
MongoDB復(fù)制
MongoDB Map Reduce
Python連接MongoDB操作
MongoDB原子操作
MongoDB特點(diǎn)
MongoDB安全檢查表
MongoDB排序記錄
MongoDB自動遞增序列
MongoDB安裝配置(Windows)
MongoDB備份與恢復(fù)
MongoDB安裝配置(Ubuntu)
Ruby連接MongoDB操作
MongoDB部署
MongoDB索引
MongoDB分析查詢
MongoDB投影(選擇字段)
MongoDB刪除數(shù)據(jù)庫
MongoDB認(rèn)證
MongoDB限制記錄數(shù)
MongoDB添加用戶
MongoDB固定循環(huán)集合
MongoDB高級索引
MongoDB數(shù)據(jù)庫的優(yōu)點(diǎn)
MongoDB快速入門
MongoDB創(chuàng)建數(shù)據(jù)庫
MongoDB啟用身份驗(yàn)證
MongoDB歷史
MongoDB管理用戶和角色
MongoDB安裝配置(RedHat/CentOS)
MongoDB刪除文檔
Java連接MongoDB操作
MongoDB正則表達(dá)式
MongoDB查詢文檔
MongoDB關(guān)聯(lián)關(guān)系
PHP連接MongoDB操作
MongoDB更新文檔
MongoDB ObjectId

MongoDB分析查詢

分析查詢是衡量數(shù)據(jù)庫和索引設(shè)計的有效性的一個非常重要的方式。在這里我們將介紹兩個經(jīng)常使用的$explain$hint查詢。

使用 $explain 操作符

$explain操作符提供有關(guān)查詢的信息,查詢中使用的索引和其他統(tǒng)計信息。它在在分析索引優(yōu)化情況時非常有用。

在最后一章中,我們已經(jīng)使用以下查詢在users集合的字段:genderuser_name 上創(chuàng)建了一個索引:

>db.users.ensureIndex({gender:1,user_name:1})

現(xiàn)在將在以下查詢中使用$explain

>db.users.find({gender:"M"},{user_name:1,_id:0}).explain()

上述explain()查詢返回以下分析結(jié)果 -

{
   "cursor" : "BtreeCursor gender_1_user_name_1",
   "isMultiKey" : false,
   "n" : 1,
   "nscannedObjects" : 0,
   "nscanned" : 1,
   "nscannedObjectsAllPlans" : 0,
   "nscannedAllPlans" : 1,
   "scanAndOrder" : false,
   "indexOnly" : true,
   "nYields" : 0,
   "nChunkSkips" : 0,
   "millis" : 0,
   "indexBounds" : {
      "gender" : [
         [
            "M",
            "M"
         ]
      ],
      "user_name" : [
         [
            {
               "$minElement" : 1
            },
            {
               "$maxElement" : 1
            }
         ]
      ]
   }
}

現(xiàn)在將看看這個結(jié)果集中的字段 -

  • indexOnlytrue值表示此查詢已使用索引。
  • cursor字段指定使用的游標(biāo)的類型。BTreeCursor類型表示使用了索引,并且還給出了使用的索引的名稱。 BasicCursor表示完全掃描,而不使用任何索引的情況。
  • n表示返回的文檔數(shù)。
  • nscannedObjects表示掃描的文檔總數(shù)。
  • nscanned表示掃描的文檔或索引條目的總數(shù)。

使用 $hint

$hint操作符強(qiáng)制查詢優(yōu)化器使用指定的索引來運(yùn)行查詢。當(dāng)要測試具有不同索引的查詢的性能時,這就特別有用了。 例如,以下查詢指定要用于此查詢的genderuser_name字段的索引 -

> db.users.find({gender:"M"},{user_name:1,_id:0}).hint({gender:1,user_name:1})

要使用$explain來分析上述查詢 -

>db.users.find({gender:"M"},{user_name:1,_id:0}).hint({gender:1,user_name:1}).explain()