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

Time series query plan results with 2dsphere index do not match collection scan

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0-rc5, 6.1.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Fully Compatible
    • ALL
    • v6.0
    • QO 2022-04-18, QO 2022-05-02
    • 135

      Having a 2dsphere index on a time series collection can leave out results. Note that it starts to fail at 1001 documents, and a bucket can hold 1000 documents at most.

       

      (function() {
      "use strict";
      
      load("jstests/core/timeseries/libs/timeseries.js");
      
      const coll = db.collection;
      coll.drop();
      assert.commandWorked(
          db.createCollection(coll.getName(), {timeseries: {timeField: 'timestamp', metaField: 'meta'}}));
      
      Random.srand(1);
      function random(min, max) {
          return Random.rand() * (max - min + 1) + min;
      }
      
      function compareResultsWithAndWithoutIndex(){
          assert.commandWorked(coll.createIndex({location: '2dsphere'}));
      
          const pipeline = [{
              "$match": {
                  "location":
                      {"$geoWithin": {"$centerSphere": [[-78.64332757901981, 42.04289085325348], 0.001]}}
              }
          }]
      
          const results1 = coll.aggregate(pipeline).toArray();
          jsTestLog("results1")
          jsTestLog(results1);
      
          assert.commandWorked(coll.dropIndexes());
      
          const results2 = coll.aggregate(pipeline).toArray();
          jsTestLog("results2")
          jsTestLog(results2);
      
          assert.eq(results1, results2);
      }
      
      for (let i = 0; i < 1001; ++i) {
          const doc = {
              timestamp: new Date(),
              meta: 1,
              location: [random(-80.0, -73.0), random(40.0, 45.0)]
          };
          assert.commandWorked(coll.insert(doc));
      }
      compareResultsWithAndWithoutIndex();
      })();
      

       

            Assignee:
            dan.larkin-york@mongodb.com Dan Larkin-York
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: