[SERVER-67299] Prevent dropping shard key index when only remaining compatible index is multikey Created: 15/Jun/22  Updated: 29/Oct/23  Resolved: 08/Aug/22

Status: Closed
Project: Core Server
Component/s: Sharding
Affects Version/s: None
Fix Version/s: 6.1.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Nandini Bhartiya
Resolution: Fixed Votes: 0
Labels: sharding-nyc-subteam1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to SERVER-6491 Prevent dropping shard key index when... Closed
Backwards Compatibility: Fully Compatible
Sprint: Sharding 2022-08-08, Sharding 2022-08-22
Participants:
Story Points: 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();
})();



 Comments   
Comment by Githook User [ 04/Aug/22 ]

Author:

{'name': 'nandinibhartiyaMDB', 'email': 'nandini.bhartiya@mongodb.com', 'username': 'nandinibhartiyaMDB'}

Message: SERVER-67299: Dropping shard key index fails if only multikey index left

This patch ensures that the dropIndex command will fail to drop the
shard key index if the only remaning compatible index is multikey
Branch: master
https://github.com/mongodb/mongo/commit/17d9615fdfa2d2b931d241bf1bfe97eaaf812816

Comment by Max Hirschhorn [ 15/Jun/22 ]

I believe the work involved here would be to have isLastShardKeyIndex() set requireSingleKey=true.

Generated at Thu Feb 08 06:07:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.