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

Incorrect optimization of $match with $exists over the metaField in timeseries discards valid results

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0-rc10, 6.1.0-rc0
    • Affects Version/s: 5.3.1, 6.0.0-rc8
    • Component/s: None
    • Labels:
      None
    • Fully Compatible
    • ALL
    • v6.0
    • Hide
      db.createCollection("yyy", { timeseries: {timeField: "time", metaField: "tag"}});
      
      db.yyy.insertMany([
      {_id: 20, time: new Date("2019-07-29T07:46:38.746Z"), tag: {scientist: 2, assistant: 2, office: 0, }, measurement0: 585.0363180488305},
      
      {_id: 449, time: new Date("2019-11-29T12:20:34.821Z"), tag: {scientist: 2, assistant: 1, office: 3, }, measurement0: 708.2660627314729},
      
      {_id: 454, time: new Date("2019-03-09T07:29:34.201Z"), tag: {scientist: 2, assistant: 0, office: 3, }, measurement0: 220.7121256827354,measurement1: 762.5075842068677}
      ]);
      
      db.yyy.aggregate([ {$match: {$or: [{"tag.office": {$exists: true}}, {"time": {$eq: new Date("2019-02-08T06:41:54.182Z")}}]}}, {$sort: {_id: 1}}]); 
      Show
      db.createCollection( "yyy" , { timeseries: {timeField: "time" , metaField: "tag" }}); db.yyy.insertMany([ {_id: 20, time: new Date( "2019-07-29T07:46:38.746Z" ), tag: {scientist: 2, assistant: 2, office: 0, }, measurement0: 585.0363180488305}, {_id: 449, time: new Date( "2019-11-29T12:20:34.821Z" ), tag: {scientist: 2, assistant: 1, office: 3, }, measurement0: 708.2660627314729}, {_id: 454, time: new Date( "2019-03-09T07:29:34.201Z" ), tag: {scientist: 2, assistant: 0, office: 3, }, measurement0: 220.7121256827354,measurement1: 762.5075842068677} ]); db.yyy.aggregate([ {$match: {$or: [{ "tag.office" : {$exists: true }}, { "time" : {$eq: new Date( "2019-02-08T06:41:54.182Z" )}}]}}, {$sort: {_id: 1}}]);
    • QO 2022-06-13, QO 2022-06-27
    • 160

      When the following $match expression is pushed down before $_internalUnpackBucket, the meta field of the timeseries is not recognized correctly. 

      {$match: {$or: [{"tag.office": {$exists: true}}, {"time": {$eq: new Date("2019-02-08T06:41:54.182Z")}}]}}

      The $exists predicate is expanded into 

       

      '$and': [ { 'control.max.tag.office': { '$exists': true } },
                { 'control.min.tag.office': { '$exists': true } }                    ]
      

       

      which results in discarding valid documents from the result set.

      The correct expansion of the predicate over the metaField "tag" is:

      { 'meta.office': { '$exists': true } }

      The problem doesn't appear for other predicate, such as $eq, or if the predicate is the only one in $match, i.e the following aggregations produce correct results:

       

      {$match: {$or: [{"tag.office": {$eq: 3}}, {"time": {$eq: new Date("2019-02-08T06:41:54.182Z")}}]}}
      {$match: {"tag.office": {$exists: true}}}
      

       

       

            Assignee:
            david.percy@mongodb.com David Percy
            Reporter:
            milena.ivanova@mongodb.com Milena Ivanova
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: