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

Prevent dropping shard key index when only remaining compatible index is multikey

    XMLWordPrintableJSON

Details

    • Fully Compatible
    • Sharding 2022-08-08, Sharding 2022-08-22
    • 2

    Description

      While it is safe (correct) for chunk migration and range deletion to use a multikey index to scan through a chunk range, there can be a negative performance consequence to the shard key compatible index being multikey. The shard key fields themselves are guaranteed to never cause the index to be multikey because the shard key value cannot be an array. However, chunk migration and range deletion may need to scan through multiple index keys for the same document when there's a suffix in the index key pattern which causes the index to be multikey.

      As a follow on to the work done in SERVER-6491 we should have the dropIndexes command prevent the only remaining shard key compatible index from being a multikey index.


      (function() {
      "use strict";
       
      const st = new ShardingTest({mongos: 1, config: 1, shards: 1, rs: {nodes: 1}});
       
      assert.commandWorked(st.s.adminCommand({enableSharding: "test"}));
      assert.commandWorked(st.s.adminCommand({shardCollection: "test.test", key: {a: 1}}));
      assert.commandWorked(st.s.getCollection("test.test").insert({a: 1, b: [1, 2]}));
      assert.commandWorked(st.s.getCollection("test.test").createIndex({a: 1, b: 1}));
      assert.commandFailedWithCode(st.s.getCollection("test.test").dropIndex({a: 1}),
                                   ErrorCodes.CannotDropShardKeyIndex);
       
      st.stop();
      })();
      

      Attachments

        Activity

          People

            nandini.bhartiya@mongodb.com Nandini Bhartiya
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: