Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-79552

$group rewrite for timeseries returns incorrect result if referencing the metaField in an object

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.0.2, 5.0.22, 6.0.11
    • Affects Version/s: 5.0.19, 6.0.8, 7.0.0-rc11
    • Component/s: None
    • Labels:
    • Query Integration
    • Fully Compatible
    • ALL
    • v7.1, v7.0, v6.0, v5.0
    • Hide
      // create a time-series collection.
      db.createCollection("timeseries", {timeseries: {timeField: "time",         metaField: metaField}});
      
      // insert some documents.
      
      // run both queries.
      coll.aggregate([{$group: {_id: { d: '$meta1.a.b' }, accmin: {$min: '$c'}}}]);
      
      coll.aggregate([{$group: {_id: '$meta1.a.b', accmin: {$min: '$c'}}}]);

      Both queries will return:

      {$group: {_id: '$meta.a.b', accmin: {$min: '$meta1.f1'}}}
      Show
      // create a time-series collection. db.createCollection( "timeseries" , {timeseries: {timeField: "time" , metaField: metaField}}); // insert some documents. // run both queries. coll.aggregate([{$group: {_id: { d: '$meta1.a.b' }, accmin: {$min: '$c' }}}]); coll.aggregate([{$group: {_id: '$meta1.a.b' , accmin: {$min: '$c' }}}]); Both queries will return: {$group: {_id: '$meta.a.b' , accmin: {$min: '$meta1.f1' }}}
    • QI 2023-08-21, QI 2023-09-04, QI 2023-09-18, QI 2023-10-02

      The $group rewrite for time-series does not take into account the difference between  _id: { d: '$meta1.a.b' } and _id: '$meta1.a.b'. The rewrite returns the same result for both group queries, even though the returned documents should have different _id fields. Steps to reproduce are below.

      This bug will be fixed in 7.1 by SERVER-78234, since that ticket rewrites much of this logic, but previous versions need to be corrected. The problem is that the implementation of DocumentSourceGroup::getIdFields returns a vector of size 1 in both cases, and the rewrite logic assumes the _id field looks like _id: '$meta1.a.b'. We can use the _idFieldNames in the group processor to find differentiate between these two cases.

            Assignee:
            erin.zhu@mongodb.com Erin Zhu
            Reporter:
            gil.alon@mongodb.com Gil Alon
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: