Currently the planner prevents exploding an index to provide a sort when the sort is on a multikey field. See here.
Conceptually there's no reason we must enforce this restriction. Under certain conditions described in SERVER-31898 we can actually use an index to provide a sort on a multikey field.
One way to implement this optimization is to change explodeForScan to return a success/fail indicator. After this function builds the index scan node which has point bounds on the first components we can use the existing logic in IndexScanNode to determine whether the sort is actually provided. See here.
- related to
-
SERVER-31898 Improve sort analysis to allow multikey indexes to provide sorts when possible
- Closed