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

getShardsForQuery should filter prior $or clause scan ranges using shard key

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Performance, Sharding
    • Labels:
      None

      If a $or clause is { a:

      { $gt:0, $lt:1 }

      , b:1 } and the shard key is

      { a:1 }

      , the a range 0 < a < 1 can be eliminated from subsequent field range sets. Currently only the combined range 0 < a < 1 AND b = 1 is eliminated, because the shard key is not supplied when advancing to the next $or clause.

                  if (!org.orRangesExhausted())
                      org.popOrClauseSingleKey();
      

      We'd want something like popOrClause, but which takes a shard key instead of a real index and applies it to the single key field range set.

              /** Iterates to the next $or clause by removing the current $or clause. */
              void popOrClause( NamespaceDetails *nsd, int idxNo, const BSONObj &keyPattern );
              void popOrClauseSingleKey();
      

      This filtering can reduce the overlap of chunk ranges that need to be scanned to determine the set of target shards. In simple cases this change will not likely provide much of a performance improvement, but it would make the sharded and unsharded uses of OrRangeGenerator a bit more uniform.

            Assignee:
            siyuan.zhou@mongodb.com Siyuan Zhou
            Reporter:
            aaron Aaron Staple
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: