[SERVER-50291] Add query knob to enumerate $or children in a different order Created: 13/Aug/20  Updated: 09/Nov/23  Resolved: 02/Sep/20

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: 3.6.6, 4.0.0
Fix Version/s: 4.7.0, 4.2.10, 4.4.2, 4.0.21

Type: New Feature Priority: Major - P3
Reporter: Charlie Swanson Assignee: Charlie Swanson
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
related to SERVER-83091 $or query can trigger an infinite loo... Closed
is related to SERVER-36393 Contained $or pushdown optimization c... Backlog
is related to SERVER-74893 Change default enumeration strategy f... Closed
Backwards Compatibility: Fully Compatible
Backport Requested:
v4.4, v4.2, v4.0, v3.6
Sprint: Query 2020-08-24, Query 2020-09-07
Participants:

 Description   

As described in SERVER-36393 there are cases where we fail to enumerate some interesting plans because we limit the number of plans we generate for a contained $or. While not a complete solution, one suggestion for a workaround on that ticket was to add a way to enumerate the children of the $or in a different "more interesting" order. To quote:

Asya points out that our plan enumeration code might fall over like this less if it changes its enumeration strategy from something like:
A, A, A
A, A, B
A, A, C
...
To something like
A, A, A
B, B, B
C, C, C
...
This is a heuristic that might help us to force the plan selection code to consider the best index in more cases, short of a more complete solution.

This ticket tracks the work to implement that solution.



 Comments   
Comment by James Wahlin [ 03/Sep/20 ]

charlie.swanson - this looks OK to backport. I agree that with the feature flag off the risk of introducing is minimal.

Comment by Charlie Swanson [ 02/Sep/20 ]

james.wahlin can you take a look at the patch and let me know if you agree it is safe to backport? It's a lot of code for sure, but I think it's not too risky since it's all under a flag and the patch doesn't change much of the existing code.

Comment by Charlie Swanson [ 02/Sep/20 ]

Accidentally committed this under the wrong ticket. Copying githook comment here.

Author:

{'name': 'Charlie Swanson', 'email': 'charlie.swanson@mongodb.com', 'username': 'cswanson310'}

Message: SERVER-36393 Add new opt-in $or enumeration order
Branch: master
https://github.com/mongodb/mongo/commit/bffdd28e183d5b720c897b56278821e65762ccd7

Generated at Thu Feb 08 05:22:17 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.