[SERVER-5162] getShardsForQuery should filter prior $or clause scan ranges using shard key Created: 01/Mar/12  Updated: 11/Jul/16  Resolved: 02/May/14

Status: Closed
Project: Core Server
Component/s: Performance, Sharding
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Aaron Staple Assignee: Siyuan Zhou
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-4555 check and clean sharding utilization ... Closed
Participants:

 Description   

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.



 Comments   
Comment by Siyuan Zhou [ 02/May/14 ]

With the new query framework, this problem doesn't exist any more. In the example case:

// shard key { a: 1 }
coll.find({
    $or: [
        { a: { $gt:0, $lt:1 } },
        { b: 1 },
    ]
});

Planner outputs 0 indexed solution, so we fall back to target to all shards.

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