[SERVER-73253] Better path tracking when renaming nested/compound grouping fields Created: 24/Jan/23  Updated: 29/Oct/23  Resolved: 12/Jul/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.1.0-rc0, 7.0.2

Type: Improvement Priority: Major - P3
Reporter: Chris Harris Assignee: Matt Olma
Resolution: Fixed Votes: 0
Labels: neweng, query-director-triage
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
is depended on by SERVER-78467 Fix test failure of predicate push-do... Closed
Problem/Incident
Related
is related to SERVER-72037 Allow $replace(With|Root) to particip... Open
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Backport Requested:
v7.0
Sprint: QO 2023-05-15, QO 2023-05-29, QO 2023-06-12, QO 2023-06-26, QO 2023-07-10, QO 2023-07-24
Participants:
Linked BF Score: 38

 Description   

Via SERVER-34741, all of the following pipelines will have the $match predicate pulled ahead of the $group to leverage an index and minimize the amount of work performed:

//Match directly on single field group
db.foo.aggregate([
      { '$group': { _id: '$city', c: { '$sum': 1 } } },
      { '$match': { _id: 'Austin' } }
]);
//Match on directly single field nested group value
db.foo.aggregate([
      { '$group': { _id: { c: '$city' }, c: { '$sum': 1 } } },
      { '$match': { '_id.c': 'Austin' } }
]);
//Match directly on one field in a compound grouping
db.foo.aggregate([
      {
        '$group': { _id: { c: '$city', s: '$state' }, c: { '$sum': 1 } }
      },
      { '$match': { '_id.c': 'Austin' } }
]);
//Match on a renamed single field grouping
db.foo.aggregate([
      { '$group': { _id: '$city', c: { '$sum': 1 } } },
      { '$project': { cityName: '$_id', c: 1 } },
      { '$match': { cityName: 'Austin' } }
]);

Introducing a $project specifically when the there is a nested or compound grouping prevents the optimization from applying:

//Match on a renamed single field grouping, but with nested names
db.foo.aggregate([
      { '$group': { _id: { c: '$city' }, c: { '$sum': 1 } } },
      { '$project': { cityName: '$_id.c' } },
      { '$match': { cityName: 'Austin' } }
]);
//Match on a renamed compound grouping (necessarily with nested names)
db.foo.aggregate([
      {
        '$group': { _id: { c: '$city', s: '$state' }, c: { '$sum': 1 } }
      },
      { '$project': { cityName: '$_id.c' } },
      { '$match': { cityName: 'Austin' } }
]);

This ticket will enhance our projection analysis to handle projections that rename nested field names from the grouping _id field.



 Comments   
Comment by Githook User [ 28/Aug/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: SERVER-73253: Better path tracking when renaming nested/compound grouping fields

(cherry picked from commit 54fd27f7c5c2efd6ada9ec561fd555b75859162f)
Branch: v7.0
https://github.com/mongodb/mongo/commit/0a08a3d7e6432ad813f4631039a6ce718bafb682

Comment by Githook User [ 11/Jul/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: SERVER-73253: Better path tracking when renaming nested/compound grouping fields
Branch: master
https://github.com/mongodb/mongo/commit/54fd27f7c5c2efd6ada9ec561fd555b75859162f

Comment by Githook User [ 11/Jul/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: Revert "SERVER-73253: Better path tracking when renaming nested/compound grouping fields"

This reverts commit d3f6ed7761d9c5cdbc42ed5a56eb5de92f6a8af8.
Branch: master
https://github.com/mongodb/mongo/commit/a236c188d9e03a588470e12b9fcc709157bd7cf7

Comment by Githook User [ 10/Jul/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: SERVER-73253: Better path tracking when renaming nested/compound grouping fields
Branch: master
https://github.com/mongodb/mongo/commit/d3f6ed7761d9c5cdbc42ed5a56eb5de92f6a8af8

Comment by Githook User [ 03/Jul/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: Revert "SERVER-73253: Better path tracking when renaming nested/compound grouping fields – after revert"

This reverts commit 244f33b7433c74c470855864f3ae6b167decbd89.
Branch: master
https://github.com/mongodb/mongo/commit/fa3def588a9bfbf43661bfd3c74a6cfb5d215eef

Comment by Githook User [ 03/Jul/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: SERVER-73253: Better path tracking when renaming nested/compound grouping fields – after revert
Branch: master
https://github.com/mongodb/mongo/commit/244f33b7433c74c470855864f3ae6b167decbd89

Comment by Githook User [ 27/Jun/23 ]

Author:

{'name': 'liubov.molchanova', 'email': 'liubov.molchanova@mongodb.com', 'username': 'liubov-molchanova'}

Message: Revert "SERVER-73253: Better path tracking when renaming nested/compound grouping fields – updated"

This reverts commit 288a08f4c02b366b68f87d7d3abde88fcef25912.
Branch: master
https://github.com/mongodb/mongo/commit/d3d641c27e5e3f4ea8cd99819bcc79a6c63edfe8

Comment by Githook User [ 27/Jun/23 ]

Author:

{'name': 'Matt Olma', 'email': 'matt.olma@mongodb.com', 'username': 'mattsimply'}

Message: SERVER-73253: Better path tracking when renaming nested/compound grouping fields – updated
Branch: master
https://github.com/mongodb/mongo/commit/288a08f4c02b366b68f87d7d3abde88fcef25912

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