MongoDB教育訓練-07

 

image-1639709435352.png

 

image-1639709740460.png

image-1639710154313.png

索引越大,記憶體越大

image-1639710316926.png

前綴壓縮

image-1639710384084.png

Multikey indexs

建在array上的index (是不是由系統判斷)

image-1639710538365.png

image-1639710636236.png

通常使用"comments.rating" : 1 這種索引

image-1639710866463.png

image-1639711096453.png

Compound符合索引

多欄位索引 (欄位A &  欄位B 查詢適用 )

image-1639711185981.png

Compound Indexes 複合索引

image-1639711281834.png

image-1639711459539.png

欄位順序必須相同

image-1639711603003.png

image-1639711744724.png

image-1639711763345.png

image-1639711833183.png

image-1639711867625.png

image-1639711980197.png

 

image-1639712284049.png

 

image-1639712401606.png

ESR原則

等值 排序 範圍

10000以內不算數據量大

image-1639712527794.png

兩欄位都是陣列,禁止使用,因為所有數量是陣列的乘積

image-1639712629336.png

 

index 完全覆蓋查詢(資料都從index返回,不用直接查詢document)

_id 不要出現, multikey 不適用

image-1639712718185.png

image-1639712827734.png

db.listingsAndReviews.find({amenities:"Waterfront","bed_type":{$in:["Futon","Real Bed"]}})
.projection({bedrooms:1, price:1,_id:0,"address.country":1}).explain("executionStats")


db.listingsAndReviews.createIndex({amenities:1, bedrooms:-1,price:11,bed_type:1,first_review:1,last_review:1})

 


修訂版本 #4
由 treeman 建立於 2021-12-17 10:50:57 CST
由 treeman 更新於 2023-05-05 02:14:59 CST