[SERVER-81863] Avoid a scan of either IDX or a collection if the filter is $alwaysFalse: Created: 04/Oct/23  Updated: 15/Nov/23  Resolved: 15/Nov/23

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

Type: Improvement Priority: Major - P3
Reporter: Peter Volk Assignee: Carlos Alonso Pérez
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-70477 Optimizing expressions that are tauto... Closed
Problem/Incident
Related
is related to SERVER-82397 User EOF plan for trivially false pre... Open
is related to SERVER-82497 Optimize SBE EOF plans when in $looku... Open
Backwards Compatibility: Fully Compatible
Sprint: QO 2023-10-16, QO 2023-10-30, QO 2023-11-13, QO 2023-11-27
Participants:
Linked BF Score: 56

 Description   

For the case that a find() has an $alwaysFalse: 1 condition (after Boolean optimization) the query should not be inspecting any documents at all. Instead the planner should generate a plan returning an empty set. The corresponding test is:

db.test.drop();
var explain = db.test.find({$alwaysFalse: 1}).explain("executionStats");
assert.eq(0, explain.executionStats.totalDocsExamined, explain);
db.test.insert({a: 1});
var explain = db.test.find({$alwaysFalse: 1}).explain("executionStats");
assert.eq(0, explain.executionStats.totalDocsExamined, explain);

 



 Comments   
Comment by Githook User [ 14/Nov/23 ]

Author:

{'name': 'Carlos Alonso', 'email': 'calonso@users.noreply.github.com', 'username': 'calonso'}

Message: SERVER-81863 Use EOF plan for trivially false predicates

If we're resorting to collection scan and the predicate is trivially false then we're producing an EOF plan.
Branch: master
https://github.com/mongodb/mongo/commit/477d62b47ab9d68a5f114a7e7bb89ca45a6d39f5

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