[SERVER-55727] Allow rewrite to push inclusion meta projections past $unpackBucket Created: 01/Apr/21  Updated: 20/Apr/21  Resolved: 20/Apr/21

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

Type: Task Priority: Major - P3
Reporter: Hana Pearlman Assignee: Hana Pearlman
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-56209 Complete TODO listed in SERVER-55727 Closed
Sprint: Query Optimization 2021-04-19, Query Optimization 2021-05-03
Participants:

 Description   

If we have an inclusion $project only on meta after an $unpackBucket, we can move the $project before $unpackBucket. For example, roughly:

{$unpackBucket: {exclude: [], metaField: "myMeta"}},
{$project : {myMeta.a : 1, myMeta.b: 1, _id: 0}}
--->
{$project : {meta.a : 1, meta.b: 1}}
{$unpackBucket: {exclude: [], metaField: "myMeta"}},
 



 Comments   
Comment by Jacob Evans [ 20/Apr/21 ]

We decided to abandon this ticket due to implementation difficulty. Optimizing this kind of query was an extrapolation from the scope and not explicitly a requirement.

It's not clear how to optimize it without writing something that explicitly names the bucketing field. That is, we'd actually need to do:
{$unpackBucket: {exclude: [], metaField: "myMeta"}},
{$project : {myMeta.a : 1, myMeta.b: 1, _id: 0}}
--->
{$project : {meta.a : 1, meta.b: 1, data: 1}}
{$unpackBucket: {include: ['meta'], metaField: "myMeta"}},

We've avoided any rewrites up until this point that do this and we currently don't think it's worth relying on the bucket format not changing for a rewrite of marginal value which isn't clearly in scope.

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