diff options
Diffstat (limited to 'src/mongo/db/query/index_bounds_builder.h')
-rw-r--r-- | src/mongo/db/query/index_bounds_builder.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/mongo/db/query/index_bounds_builder.h b/src/mongo/db/query/index_bounds_builder.h index 0453df842cb..7f141600837 100644 --- a/src/mongo/db/query/index_bounds_builder.h +++ b/src/mongo/db/query/index_bounds_builder.h @@ -208,6 +208,36 @@ public: BSONObj* endKey, bool* endKeyInclusive); + /** + * Appends the startKey and endKey of the given "all values" 'interval' (which is either + * [MinKey, MaxKey] or [MaxKey, MinKey] interval) to the 'startBob' and 'endBob' respectively, + * handling inclusivity of each bound through the relevant '*KeyInclusive' parameter. + * + * If the 'interval' is not an "all values" interval, does nothing. + * + * Precondition: startBob and endBob should contain one or more leading intervals which are not + * "all values" intervals, to make the constructed interval valid. + * + * The decision whether to append MinKey or MaxKey value either to startBob or endBob is based + * on the interval type (min -> max or max -> min), and inclusivity flags. + * + * As an example, consider the index {a:1, b:1} and a count for {a: {$gt: 2}}. Our start key + * isn't inclusive (as it's $gt: 2) and looks like {"":2} so far. Because {a: 2, b: MaxKey} + * sorts *after* any real-world data pair {a: 2, b: anything}, setting it as the start value + * ensures that the first index entry we encounter will be the smallest key with a > 2. + * + * Same logic applies if the end key is not inclusive. Consider the index {a:1, b:1} and a count + * for {a: {$lt: 2}}. Our end key isn't inclusive as ($lt: 2) and looks like {"":2} so far. + * Because {a: 2, b: MinKey} sorts *before* any real-world data pair {a: 2, b: anything}, + * setting it as the end value ensures that the final index entry we encounter will be the last + * key with a < 2. + */ + static void appendTrailingAllValuesInterval(const Interval& interval, + bool startKeyInclusive, + bool endKeyInclusive, + BSONObjBuilder* startBob, + BSONObjBuilder* endBob); + private: /** * Performs the heavy lifting for IndexBoundsBuilder::translate(). |