[SERVER-33054] Add ability to produce covered plans when shard key is a subfield of a provided/covered field Created: 01/Feb/18  Updated: 06/Dec/22

Status: Backlog
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Charlie Swanson Assignee: Backlog - Query Optimization
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: File repro.js    
Issue Links:
Related
Assigned Teams:
Query Optimization
Backwards Compatibility: Fully Compatible
Participants:

 Description   

When the shard key is something like {"_id.a": 1, "_id.b": 1}, we technically have enough information from the _id index to perform shard filtering. We are not currently prepared to do so though.

Adding support for this would likely involve changing IndexScanNode::hasField to report that it "has" a field if the index includes a prefix of that field (subject to some multi key checks). After that, we would likely have to modify the shard filtering logic to be prepared to have to search for the field it's looking for within another field (things didn't "just work" after the above change in a POC).

See the attached repro.js , which also requires this brief patch to the shell:

diff --git a/src/mongo/shell/shardingtest.js b/src/mongo/shell/shardingtest.js
index 4dd72ef..30d066b 100644
--- a/src/mongo/shell/shardingtest.js
+++ b/src/mongo/shell/shardingtest.js
@@ -656,7 +656,7 @@ var ShardingTest = function(params) {
         return shards;
     };
 
-    this.shardColl = function(collName, key, split, move, dbName, waitForDelete) {
+    this.shardColl = function({collName, key, split, move, dbName, waitForDelete}) {
         split = (split != false ? (split || key) : split);
         move = (split != false && move != false ? (move || split) : false);


Generated at Thu Feb 08 04:32:08 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.