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

Bucket-level $group rewrite on sharded TS collection is not performed on shards

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Query Integration
    • ALL
    • Hide
      import {ShardingTest} from "jstests/libs/shardingtest.js";
      
      const dbName = 'testDB';
      const collName = 'testColl';
      const st = new ShardingTest({shards: 2, rs: {nodes: 2}});
      const sDB = st.s.getDB(dbName);
      assert.commandWorked(sDB.adminCommand({enableSharding: dbName, primaryShard: st.shard0.shardName}));
      
      assert.commandWorked(sDB.adminCommand({
          shardCollection: `${dbName}.${collName}`,
          key: {meta: 1, time: 1},
          timeseries: {timeField: 'time', metaField: 'meta', granularity: "hours"}
      }));
      
      const coll = sDB.getCollection(collName);
      assert.commandWorked(coll.insert({time: new Date(), m: 1}));
      jsTestLog(coll.explain().aggregate([{$group: {_id: '$meta', max: {$max: '$time'}}}]))
      // Shows no $group rewrite on the shards
      
      st.stop();
      
      Show
      import {ShardingTest} from "jstests/libs/shardingtest.js" ; const dbName = 'testDB' ; const collName = 'testColl' ; const st = new ShardingTest({shards: 2, rs: {nodes: 2}}); const sDB = st.s.getDB(dbName); assert .commandWorked(sDB.adminCommand({enableSharding: dbName, primaryShard: st.shard0.shardName})); assert .commandWorked(sDB.adminCommand({ shardCollection: `${dbName}.${collName}`, key: {meta: 1, time: 1}, timeseries: {timeField: 'time' , metaField: 'meta' , granularity: "hours" } })); const coll = sDB.getCollection(collName); assert .commandWorked(coll.insert({time: new Date(), m: 1})); jsTestLog(coll.explain().aggregate([{$group: {_id: '$meta' , max: {$max: '$time' }}}])) // Shows no $group rewrite on the shards st.stop();
    • QI 2025-02-03, QI 2025-02-17

      In the repro provided in the shards section of the explain, the $group fields are not rewritten to reference the bucket-level fields. This is done as a performance optimization.

      This issue began in SERVER-93874, but after reviewing the logic I don't see why the rewrite doesn't occur. After investigating I found that on the shards this condition returns false because the _fieldSet in the bucket spec doesn't contain the meta field. This is odd because the unpack bucket stage shows us including the meta field as output.

            Assignee:
            chris.wolff@mongodb.com Chris Wolff
            Reporter:
            matt.boros@mongodb.com Matt Boros
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: