diff options
author | David Storch <david.storch@10gen.com> | 2015-11-12 16:36:42 -0500 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2015-11-17 13:04:54 -0500 |
commit | 8c0443a33249b3aec2f94fc97017e1314ef3d53f (patch) | |
tree | 76b48915a444ca38efc4fc7f370bba78843a00bf /src/mongo/s/shard_key_pattern.cpp | |
parent | fdd0ce979f615ca199ea443b1e10301e933ec18b (diff) | |
download | mongo-8c0443a33249b3aec2f94fc97017e1314ef3d53f.tar.gz |
SERVER-21441 faster shard targeting for equality queries on the shard key
Diffstat (limited to 'src/mongo/s/shard_key_pattern.cpp')
-rw-r--r-- | src/mongo/s/shard_key_pattern.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/mongo/s/shard_key_pattern.cpp b/src/mongo/s/shard_key_pattern.cpp index 30dbc63ee72..67d2743ac22 100644 --- a/src/mongo/s/shard_key_pattern.cpp +++ b/src/mongo/s/shard_key_pattern.cpp @@ -265,7 +265,6 @@ StatusWith<BSONObj> ShardKeyPattern::extractShardKeyFromQuery(const BSONObj& bas if (!isValid()) return StatusWith<BSONObj>(BSONObj()); - // Extract equalities from query auto statusWithCQ = CanonicalQuery::canonicalize(NamespaceString(""), basicQuery, ExtensionsCallbackNoop()); if (!statusWithCQ.isOK()) { @@ -273,13 +272,21 @@ StatusWith<BSONObj> ShardKeyPattern::extractShardKeyFromQuery(const BSONObj& bas } unique_ptr<CanonicalQuery> query = std::move(statusWithCQ.getValue()); + return extractShardKeyFromQuery(*query); +} + +StatusWith<BSONObj> ShardKeyPattern::extractShardKeyFromQuery(const CanonicalQuery& query) const { + if (!isValid()) + return StatusWith<BSONObj>(BSONObj()); + + // Extract equalities from query. EqualityMatches equalities; // TODO: Build the path set initially? FieldRefSet keyPatternPathSet(_keyPatternPaths.vector()); // We only care about extracting the full key pattern paths - if they don't exist (or are // conflicting), we don't contain the shard key. Status eqStatus = - pathsupport::extractFullEqualityMatches(*query->root(), keyPatternPathSet, &equalities); + pathsupport::extractFullEqualityMatches(*query.root(), keyPatternPathSet, &equalities); // NOTE: Failure to extract equality matches just means we return no shard key - it's not // an error we propagate if (!eqStatus.isOK()) |