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

Investigate lowering to SBE non-distinct_scan lastpoint queries

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 7.2.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Integration
    • Fully Compatible
    • QI 2023-10-02

      > db.createCollection("ts", { timeseries: { timeField: "time", metaField: "meta", granularity: "seconds" }})
      > db.ts.getIndexes()
      [{"v" : 2, "key" : {"meta" : 1,"time" : 1},"name" : "meta_1_time_1"}]
      > db.system.buckets.ts.getIndexes()
      [{"v" : 2,"key" : {"meta" : 1,"control.min.time" : 1,"control.max.time" : 1},"name" : "meta_1_time_1"}]
      > // insert some data into "ts" so it's not empty
      > db.ts.explain().aggregate([{$sort: {meta: 1, time: 1}}, {$group: {_id: "$meta", last: {$last: "$val"}}}])
      

      The plan won't have DISTINCT_SCAN because the default index {meta:1, time: 1} doesn't match the query sorting requirements, but it will have a bucket-level $group with $last accumulator, followed by unpack, followed by event-level $group.

      A pipeline like this should be fully lowerable to SBE but I'm not seeing the bucket-level $group being lowered in my tests. We should investigate this and either keep the whole query in the classic engine or ensure that it gets lowered beyond the unpacking stage. This is likely related to SERVER-79066.

            Assignee:
            irina.yatsenko@mongodb.com Irina Yatsenko (Inactive)
            Reporter:
            irina.yatsenko@mongodb.com Irina Yatsenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: