[DOCS-13309] MongoDB does not guarantee short circuit evaluation and it should not be mentioned Created: 18/Dec/19 Updated: 30/Oct/23 Resolved: 01/Sep/21 |
|
| Status: | Closed |
| Project: | Documentation |
| Component/s: | manual, Server |
| Affects Version/s: | None |
| Fix Version/s: | Server_Docs_20231030 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Jacob Evans | Assignee: | Jason Price |
| Resolution: | Done | Votes: | 1 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||
| Participants: | |||||||||||||||||||||
| Days since reply: | 2 years, 23 weeks ago | ||||||||||||||||||||
| Epic Link: | DOCSP-11701 | ||||||||||||||||||||
| Story Points: | 3 | ||||||||||||||||||||
| Description |
DescriptionThese pages: mention that
and
Although there is a kernel of truth here and $and does perform short-circuit evaluation for performance, the query system is free to change the order of predicates inside a $and. In fact the find query system currently sorts all of them in an order that's arbitrary to the user in find. Agg performs some reordering in unusual circumstances. In general the query system must be free to reorder predicates as it sees fit during optimization and the order it chooses may change when MongoDB is upgraded or due to other factors. When the order is changed, the user will not get the short-circuit evaluation they specified in the query. I've opened a ticket to track a request for a way to optionally define predicate evaluation order: This is true for find and aggregation and for predicates listed outside of a $and within a find query. If we're defensive about it in the docs we can prevent customer surprise later. Scope of changesImpact to Other DocsMVP (Work and Date)Resources (Scope or Design Docs, Invision, etc.) |
| Comments |
| Comment by Githook User [ 01/Sep/21 ] |
|
Author: {'name': 'jason-price-mongodb', 'email': 'jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com'}Message: |
| Comment by Githook User [ 01/Sep/21 ] |
|
Author: {'name': 'jason-price-mongodb', 'email': 'jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com'}Message: |
| Comment by Githook User [ 01/Sep/21 ] |
|
Author: {'name': 'jason-price-mongodb', 'email': 'jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com'}Message: |
| Comment by Githook User [ 01/Sep/21 ] |
|
Author: {'name': 'jason-price-mongodb', 'email': 'jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com'}Message: |
| Comment by Githook User [ 01/Sep/21 ] |
|
Author: {'name': 'jason-price-mongodb', 'email': 'jshfjghsdfgjsdjh@aolsdjfhkjsdhfkjsdf.com'}Message: |
| Comment by Charlie Swanson [ 02/Feb/21 ] |
|
Just wanted to ping again on this - it came up again in the context of |
| Comment by Charlie Swanson [ 07/Jan/20 ] |
|
bduncan@visualmining.com the expression language also does not have any such guarantees. To the extent that it works today, it is only because the optimizer isn't sophisticated enough to do any transformations or reorderings to it. I think SERVER-37530 should remain as the ticket requesting any guaranteed order of evaluation, there is no such concept today - it just may happen to work out that way. |
| Comment by Bruce Duncan [ 29/Dec/19 ] |
|
I would argue that the documentation should also address short-circuit evaluation within the expression language accessible using `$expr`. To my knowledge, reordering does not happen within those expressions and so the user specified order is retained and thereby any benefit they were counting on from short-circuit evaluation. |