[SERVER-83529] Generate covered projections with $expr Created: 22/Nov/23  Updated: 12/Dec/23  Resolved: 23/Nov/23

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

Type: Improvement Priority: Major - P3
Reporter: Ivan Fefer Assignee: Backlog - Query Optimization
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by SERVER-84094 Implement initial drain policy for un... Backlog
Duplicate
duplicates SERVER-41252 cannot get covered query with $expr w... Open
Assigned Teams:
Query Optimization
Participants:

 Description   

if we are using $expr, we don’t produce covered projections.

If index on a is present,

This will have fetch + projection simple
db.test.explain().aggregate([{$match: {$expr: {$eq: ["$a", 1]}}}, {$project: {_id: 0, a: 1}}])

But this will have projection covered:
db.test.explain().aggregate([\{$match: {a: 1}}, \{$project: {_id: 0, a: 1}}])

It looks like a problem with dependency analysis of $expr that can’t determine that we only need field “a” that can come from the index.

In some cases we have to use $expr syntax. For example, in $lookup with pipelines.



 Comments   
Comment by Ivan Fefer [ 23/Nov/23 ]

Closing this as a duplicate

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