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

Add ability to produce covered plans when shard key is a subfield of a provided/covered field

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Querying
    • None
    • Query Optimization
    • Fully Compatible

      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:

      Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      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);
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            charlie.swanson@mongodb.com Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated: