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

Comparisons on timeField in time-series could sometimes be optimized away

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Do
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration

      The time field is required to be present and be of type Date. Comparisons on the time field that use non-Date types for the constant would be either trivially false (e.g. in the case of type-bracketing) or trivially true (in some cases without type-bracketing).

      Currently, we don't optimize such comparisons out and always create $_internalUnpackBucket stage with an eventFilter:

      > db.ts.explain().find({t: 42}) // "t" is the timeField in this collection
      {
              "explainVersion" : "1",
              "stages" : [
                      {
                              "$cursor" : {
                                      "queryPlanner" : {
                                              "namespace" : "my.system.buckets.ts",
                                              "indexFilterSet" : false,
                                              "parsedQuery" : {
      
                                              },
                                              "queryHash" : "FCBE9F38",
                                              "planCacheKey" : "64E90EFC",
                                              "maxIndexedOrSolutionsReached" : false,
                                              "maxIndexedAndSolutionsReached" : false,
                                              "maxScansToExplodeReached" : false,
                                              "winningPlan" : {
                                                      "stage" : "COLLSCAN",
                                                      "direction" : "forward"
                                              },
                                              "rejectedPlans" : [ ]
                                      }
                              }
                      },
                      {
                              "$_internalUnpackBucket" : {
                                      "exclude" : [ ],
                                      "timeField" : "t",
                                      "metaField" : "m",
                                      "bucketMaxSpanSeconds" : 3600,
                                      "assumeNoMixedSchemaData" : true,
                                      "eventFilter" : {
                                              "t" : {
                                                      "$eq" : 42
                                              }
                                      }
                              }
                      }
              ],
      

            Assignee:
            backlog-query-integration [DO NOT USE] Backlog - Query Integration
            Reporter:
            irina.yatsenko@mongodb.com Irina Yatsenko (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: