我有一個mongoDB的集合,它的作業速度不如我想的那么快。我一直在閱讀有關explain()和queryPlanner 的內容(直到現在才知道)。而且我觀察到我的指數沒有 macth。
我嘗試了最簡單的索引,但它不回傳匹配項,但winsPlan似乎確實匹配。我會告訴你我是如何完成這些步驟的:
- db.candidatures.createIndex( {"client_id": 1 } )
- db.candidatures.find({ client_id: "800a0d60-b5fe-11ea-ae04-42010a840222", }).explain() (更新:通過 client_id 查找而不是 dni)
- 檢查 queryPlanner 結果
{
"plannerVersion": newNumberInt("1"),
"namespace": "hrbot-prod.candidatures",
"indexFilterSet": false,
"parsedQuery": {
"client_id": {
"$eq": "800a0d60-b5fe-11ea-ae04-42010a840222"
}
},
"queryHash": "6C94666F",
"planCacheKey": "65C00083",
"winningPlan": {
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1")
},
"indexName": "client_id",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
]
}
}
},
"rejectedPlans": [
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"dni": newNumberInt("1")
},
"indexName": "client_id_1_dni_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"dni": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"dni": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"candidature_id": newNumberInt("1")
},
"indexName": "client_id_1_candidature_id_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"candidature_id": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"candidature_id": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("-1")
},
"indexName": "client_id_1_update_at_-1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MaxKey, MinKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("1")
},
"indexName": "client_id_1_update_at_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"matching": newNumberInt("1")
},
"indexName": "client_id_1_matching_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"matching": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"matching": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"matching": newNumberInt("-1")
},
"indexName": "client_id_1_matching_-1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"matching": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"matching": [
"[MaxKey, MinKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"disponibilidad": newNumberInt("-1")
},
"indexName": "client_id_1_disponibilidad_-1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"disponibilidad": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"disponibilidad": [
"[MaxKey, MinKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"email": newNumberInt("1")
},
"indexName": "client_id_1_email_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"email": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"email": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"candidature_id": newNumberInt("1"),
"email": newNumberInt("1")
},
"indexName": "client_id_1_candidature_id_1_email_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"candidature_id": [
],
"email": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"candidature_id": [
"[MinKey, MaxKey]"
],
"email": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"candidature_id": newNumberInt("1"),
"update_at": newNumberInt("-1")
},
"indexName": "client_id_1_candidature_id_1_update_at_-1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"candidature_id": [
],
"update_at": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"candidature_id": [
"[MinKey, MaxKey]"
],
"update_at": [
"[MaxKey, MinKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"disponibilidad": newNumberInt("-1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_disponibilidad_-1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"disponibilidad": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"disponibilidad": [
"[MaxKey, MinKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"direccion": newNumberInt("1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_direccion_1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"direccion": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"direccion": [
"[MinKey, MaxKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"direccion": newNumberInt("1"),
"disponibilidad": newNumberInt("-1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_direccion_1_disponibilidad_-1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"direccion": [
],
"disponibilidad": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"direccion": [
"[MinKey, MaxKey]"
],
"disponibilidad": [
"[MaxKey, MinKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"cp": newNumberInt("1")
},
"indexName": "client_id_1_cp_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"cp": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"cp": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"disponibilidad": newNumberInt("-1"),
"cp": newNumberInt("1")
},
"indexName": "client_id_1_disponibilidad_-1_cp_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"disponibilidad": [
],
"cp": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"disponibilidad": [
"[MaxKey, MinKey]"
],
"cp": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("-1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_update_at_-1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MaxKey, MinKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("-1"),
"disponibilidad": newNumberInt("1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_update_at_-1_disponibilidad_1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
],
"disponibilidad": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MaxKey, MinKey]"
],
"disponibilidad": [
"[MinKey, MaxKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_update_at_1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MinKey, MaxKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("-1"),
"candidature.estado": newNumberInt("1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_update_at_-1_candidature.estado_1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
],
"candidature.estado": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MaxKey, MinKey]"
],
"candidature.estado": [
"[MinKey, MaxKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"create_at": newNumberInt("-1")
},
"indexName": "client_id_1_create_at_-1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"create_at": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"create_at": [
"[MaxKey, MinKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"especialidad": newNumberInt("1"),
"estado": newNumberInt("1")
},
"indexName": "client_id_1_especialidad_1_estado_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"especialidad": [
],
"estado": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"especialidad": [
"[MinKey, MaxKey]"
],
"estado": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"direccion": newNumberInt("1")
},
"indexName": "client_id_1_direccion_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"direccion": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"direccion": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"candidatura_seleccionada": newNumberInt("1")
},
"indexName": "client_id_1_candidatura_seleccionada_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"candidatura_seleccionada": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"candidatura_seleccionada": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"provincia": newNumberInt("1")
},
"indexName": "client_id_1_provincia_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"provincia": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"provincia": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"candidatura_seleccionada": newNumberInt("1"),
"estado": newNumberInt("1"),
"direccion": newNumberInt("1")
},
"indexName": "client_id_1_candidatura_seleccionada_1_estado_1_direccion_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"candidatura_seleccionada": [
],
"estado": [
],
"direccion": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"candidatura_seleccionada": [
"[MinKey, MaxKey]"
],
"estado": [
"[MinKey, MaxKey]"
],
"direccion": [
"[MinKey, MaxKey]"
]
}
}
},
{
"stage": "FETCH",
"inputStage": {
"stage": "IXSCAN",
"keyPattern": {
"client_id": newNumberInt("1"),
"update_at": newNumberInt("-1"),
"estado": newNumberInt("1"),
"matching": newNumberInt("1")
},
"indexName": "client_id_1_update_at_-1_estado_1_matching_1",
"isMultiKey": false,
"multiKeyPaths": {
"client_id": [
],
"update_at": [
],
"estado": [
],
"matching": [
]
},
"isUnique": false,
"isSparse": false,
"isPartial": false,
"indexVersion": newNumberInt("2"),
"direction": "forward",
"indexBounds": {
"client_id": [
"[\"800a0d60-b5fe-11ea-ae04-42010a840222\", \"800a0d60-b5fe-11ea-ae04-42010a840222\"]"
],
"update_at": [
"[MaxKey, MinKey]"
],
"estado": [
"[MinKey, MaxKey]"
],
"matching": [
"[MinKey, MaxKey]"
]
}
}
}
]
}
令我震驚的是它與索引不匹配: indexFilterSet:false,
但是在一個成功的計劃中,它有一個索引,它應該匹配的索引的名稱: winingPlan.inputStage.indexName: "client_id"
有人可以給我一個解釋并幫助我正確使用我的索引嗎?
提前致謝!
uj5u.com熱心網友回復:
簡短的回答是,該indexFilterSet欄位并不表示資料庫是否使用了索引。解釋計劃的winningPlan部分確認資料庫確實按預期使用了一個。
indexFilterSet
該indexFilterSet欄位在檔案中定義如下:
一個布林值,指定 MongoDB 是否為查詢形狀應用了索引過濾器。
索引過濾器,也稱為“計劃快取過濾器”,是用戶手動影響查詢計劃選擇程序的一種方式。它們是客戶端提示的服務器端等價物,盡管兩者的行為略有不同。
索引過濾器有效地限制了資料庫在規劃給定查詢形狀時將考慮使用的索引集。僅當已為查詢形狀手動配置索引過濾器時,解釋輸出中的indexFilterSet欄位才會出現:true
test> db.foo.find({x:1}).explain().queryPlanner.indexFilterSet
false
test> db.runCommand({planCacheSetFilter:"foo", query:{x:1}, indexes:[{x:1}]})
{ ok: 1 }
test> db.foo.find({x:1}).explain().queryPlanner.indexFilterSet
true
在正常操作下,不應使用索引過濾器和提示。資料庫本身負責規劃和執行查詢,通常不需要幫助它這樣做。事實上,在環境中設定索引過濾器是非常罕見的。
winningPlan和索引使用
該winningPlan檔案包含查詢優化器選擇的計劃的詳細資訊。這是您要查看的內容,以確定查詢規劃器為正在解釋的查詢形狀選擇了哪個索引(如果有)。
如問題中所述,在您的情況下,資料庫使用索引上的嚴格索引掃描選擇了一個查詢計劃"client_id"。這似乎是正確和正常的,因此在這方面應該沒有問題或擔憂。
觀察與建議
也就是說,在查看此解釋輸出時,還會想到其他一些問題。
最值得注意的是,有 28 個索引被考慮用于此查詢形狀。我建議查看“創建復合索引以支持多個不同的查詢”。您似乎可以通過洗掉冗余索引來大大減少支持作業負載所需的索引集。
舉個簡單的例子,在{ "client_id"S 1 }中選擇的索引winningPlan本身就是多余的。以該欄位開頭的 27 個其他索引中的任何一個都可能被同樣有效地使用。減少索引的數量將有一些好處,例如減少撰寫檔案時的開銷、減少競爭記憶體空間的專案數量以及簡化查詢計劃程式的程序。如果您當前正在檢查解釋輸出,那么最后一項可能與您的情況特別相關。
這里有關于不必要索引的附加材料(文章和視頻)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/519862.html
下一篇:根據存貨分配/分發鈔票
