[SERVER-73980] Make IndexBounds for wildcard multikey path query respect the wildcard field's ordering Created: 14/Feb/23  Updated: 29/Oct/23  Resolved: 15/Feb/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0

Type: Task Priority: Major - P3
Reporter: Alya Berciu Assignee: Ruoxin Xu
Resolution: Fixed Votes: 0
Labels: M3
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-72467 Support applying compound wildcard in... Closed
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Sprint: QO 2023-02-20
Participants:

 Description   

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.



 Comments   
Comment by Githook User [ 15/Feb/23 ]

Author:

{'name': 'Ruoxin Xu', 'email': 'ruoxin.xu@mongodb.com', 'username': 'RuoxinXu'}

Message: SERVER-73980 Make IndexBounds for wildcard multikey path query respect the wildcard field's ordering
Branch: master
https://github.com/mongodb/mongo/commit/97ec2c53fe594472ca3ff36f47f00128ec350382

Generated at Thu Feb 08 06:26:10 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.