See comments for repro steps.
---- Investigation results ----
(This failure happens especially when the wildcard field is in descending order.)
Root cause: IndexBounds generated to query a wildcard index’s multikey paths does not respect the ordering of the wildcard field.
There is a false assumption that the multikey path keys are stored in ascending order always, but it actually depends on the ordering of the wildcard field. Here's some related code, we can assure "$_path" field is always in ascending order, but when we generate keys for multikey paths, the ordering of the multikey path actually aligns with the wildcard field.
For example,
Keys generated for wildcard index:
{"$_path": 1, "$**": -1}with Ordering
{“”: 1, “”: -1}:
{"": 1, "": "a"} {"": 1, "": "a.c.d"} {"": 1, "": "e"} {"": "a.b", "": 1} {"": "a.b", "": 2} {"": "a.c", "": 1}
The first three are multikey-path index keys, the second column in descending order is for the multi key paths. While in the last three keys indexing documents, the first column in ascending order represents the path.
- depends on
-
SERVER-72467 Support applying compound wildcard indexes to sort operations
- Closed