32장. Explain·Aggregation 실전 판독
고객 1842의 최근 주문 20건을 executionStats로 본다. winning plan stage만 보지 않고 totalDocsExamined/nReturned, totalKeysExamined, blocking SORT, FETCH, index bounds를 읽는다.
db.orders.find({customerId:NumberLong(1842)})
.sort({createdAt:-1}).limit(20)
.explain("executionStats")
aggregation은 stage별 cardinality를 기록한다. $unwind 후 행수, $lookup input·foreign index, $group memory/spill, $sort 위치를 본다. $match를 앞으로 옮겼다고 결과 의미가 같은지 fixture로 확인한다.
새 index 후 query만 빠른지 보지 않는다. build 시간, disk/cache, write latency, initial sync, oplog window, secondary lag를 비교한다. hidden index로 plan 영향을 시험할 때도 운영 버전과 제약을 확인한다.