Software Development/Database

[몽고디비] Query Plans

루ㅌ 2023. 5. 9. 14:58

https://www.mongodb.com/docs/manual/core/query-plans/

 

Query Plans — MongoDB Manual

Docs Home → MongoDB Manual For a query, the MongoDB query optimizer chooses and caches the most efficient query plan given the available indexes. The evaluation of the most efficient query plan is based on the number of "work units" (works) performed by

www.mongodb.com

 

위의 사이트에서 참고하였습니다.

 

쿼리 성능이 제대로 안나오는 원인은 인덱스랑 관련이 있다.

인덱스 설계가 잘못되서, 너무 많은 인덱스가 있어서, query planner의 캐싱 등이 있을 수 있다.

인덱스 설계가 잘못됐을 때: 주로 조회하는 쿼리에 대해 분석하여 인덱스를 재설계하도록 한다.

너무 많은 인덱스가 있어서: 쿼리 플래너가 잘못된 인덱스를 탈 수 있다. hint 추가하자.

query planner의 캐싱: 캐싱이 되서 계속 성능이 느린 인덱스 스캔을 선택하게 될 경우,  PlanCache.clear(), PlanCache.clearPlansByQuery() 등으로 캐시를 지울 수 있다.