summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/interval.cpp
diff options
context:
space:
mode:
authorIan Boros <ian.boros@10gen.com>2018-07-02 18:44:05 -0400
committerIan Boros <ian.boros@10gen.com>2018-07-31 13:33:34 -0400
commit7f442763c791873d74bea5c0c6e01812933deb38 (patch)
treef6872777be64613465e89c5826301293db639cc7 /src/mongo/db/query/interval.cpp
parent21c25ecaaaabe6ad4d7e8a2eb261dad1e2eb90df (diff)
downloadmongo-7f442763c791873d74bea5c0c6e01812933deb38.tar.gz
SERVER-34846 Forwardize IndexBounds before intersectizing their OILs
Diffstat (limited to 'src/mongo/db/query/interval.cpp')
-rw-r--r--src/mongo/db/query/interval.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/mongo/db/query/interval.cpp b/src/mongo/db/query/interval.cpp
index df80321eb60..187d0704a20 100644
--- a/src/mongo/db/query/interval.cpp
+++ b/src/mongo/db/query/interval.cpp
@@ -66,6 +66,19 @@ bool Interval::isNull() const {
return (!startInclusive || !endInclusive) && 0 == start.woCompare(end, false);
}
+Interval::Direction Interval::getDirection() const {
+ if (isEmpty() || isPoint() || isNull()) {
+ return Direction::kDirectionNone;
+ }
+
+ // 'false' to not consider the field name.
+ const int res = start.woCompare(end, false);
+
+ invariant(res != 0);
+ return res < 0 ? Direction::kDirectionAscending : Direction::kDirectionDescending;
+}
+
+
//
// Comparison
//
@@ -93,6 +106,17 @@ bool Interval::equals(const Interval& other) const {
}
bool Interval::intersects(const Interval& other) const {
+ if (kDebugBuild) {
+ // This function assumes that both intervals are ascending (or are empty/point intervals).
+ // Determining this may be expensive, so we only do these checks when in a debug build.
+ const auto thisDir = getDirection();
+ invariant(thisDir == Direction::kDirectionAscending ||
+ thisDir == Direction::kDirectionNone);
+ const auto otherDir = other.getDirection();
+ invariant(otherDir == Direction::kDirectionAscending ||
+ otherDir == Direction::kDirectionNone);
+ }
+
int res = this->start.woCompare(other.end, false);
if (res > 0) {
return false;
@@ -261,4 +285,15 @@ void Interval::reverse() {
std::swap(startInclusive, endInclusive);
}
+Interval Interval::reverseClone() const {
+ Interval reversed;
+ reversed.start = end;
+ reversed.end = start;
+ reversed.startInclusive = endInclusive;
+ reversed.endInclusive = startInclusive;
+ reversed._intervalData = _intervalData;
+
+ return reversed;
+}
+
} // namespace mongo