Time series wrong answer with compound rawData index with descending key

XMLWordPrintableJSON

    • Query Integration
    • ALL
    • Hide
      // Setup: create a timeseries collection with test data
        db.repro.drop();
        db.createCollection("repro", {timeseries: {timeField: "t", metaField: "m"}});
      
        db.repro.insertMany([
            {t: new Date("2024-01-01T00:00:00Z"), m: "a", x: 1},
            {t: new Date("2024-01-01T00:00:00Z"), m: "a", x: 2},
            {t: new Date("2024-01-01T00:01:00Z"), m: "b", x: 3},
        ]);
      
        // Unhinted query: returns 3 documents (all have x >= 1)
        db.repro.find({x: {$gte: 1}}).toArray().length;
        // => 3
      
        // Create a non-conforming index with mismatched min/max sort order via rawData
        db.runCommand({
            createIndexes: "repro",
            indexes: [{key: {"control.min.x": 1, "control.max.x": -1}, name: "mismatched_order_x"}],
            rawData: true
        });
      
        // Hinted query using the non-conforming index by name: returns fewer results
        db.repro.find({x: {$gte: 1}}).hint("mismatched_order_x").toArray().length;
        // => 2 (WRONG — should be 3)
      
      Show
      // Setup: create a timeseries collection with test data db.repro.drop(); db.createCollection( "repro" , {timeseries: {timeField: "t" , metaField: "m" }}); db.repro.insertMany([ {t: new Date( "2024-01-01T00:00:00Z" ), m: "a" , x: 1}, {t: new Date( "2024-01-01T00:00:00Z" ), m: "a" , x: 2}, {t: new Date( "2024-01-01T00:01:00Z" ), m: "b" , x: 3}, ]); // Unhinted query: returns 3 documents (all have x >= 1) db.repro.find({x: {$gte: 1}}).toArray().length; // => 3 // Create a non-conforming index with mismatched min/max sort order via rawData db.runCommand({ createIndexes: "repro" , indexes: [{key: { "control.min.x" : 1, "control.max.x" : -1}, name: "mismatched_order_x" }], rawData: true }); // Hinted query using the non-conforming index by name: returns fewer results db.repro.find({x: {$gte: 1}}).hint( "mismatched_order_x" ).toArray().length; // => 2 (WRONG — should be 3)
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      It's possible to use rawData: true to create an index that produces a wrong answer when querying a time series collection. The index has to be specially created (multi-component in control.min/max with a descending 2nd component), and the query needs to request the index explicitly with a hint.

            Assignee:
            Unassigned
            Reporter:
            Chris Wolff
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: