summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Studer <greg@10gen.com>2014-08-21 17:19:57 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2014-09-18 17:33:39 -0400
commit1eaf5a41ba94c5787e72fe92ef4a91ac63f6a744 (patch)
treee9a22de1470823848e84200f933f19344a9ec744
parentc7ee53ba9bf48dd958baa4cbc45ec5d6f3683072 (diff)
downloadmongo-1eaf5a41ba94c5787e72fe92ef4a91ac63f6a744.tar.gz
SERVER-14981 don't generate cell ids > coarsestIndexedLevel when building covering
(cherry picked from commit 6e90ddf91fdbbc578e499fcb736365498e47f55a) Conflicts: src/mongo/db/query/expression_index.cpp
-rwxr-xr-xjstests/core/geo_s2index.js8
-rw-r--r--src/mongo/db/index/expression_index.h29
2 files changed, 21 insertions, 16 deletions
diff --git a/jstests/core/geo_s2index.js b/jstests/core/geo_s2index.js
index 11d86a3bf2f..60a3e795e3d 100755
--- a/jstests/core/geo_s2index.js
+++ b/jstests/core/geo_s2index.js
@@ -69,7 +69,7 @@ t.save({loc: [0,0]})
assert.throws(function() { return t.count({loc: {$foo:[0,0]}}) })
assert.throws(function() { return t.find({ "nonGeo": "pointA",
"geo" : { "$geoIntersects" : { "$geometry" : somepoly},
- "$near": {"$geometry" : somepoly }}}).count()})
+ "$near": {"$geometry" : somepoly }}}).count()})
// If we specify a datum, it has to be valid (WGS84).
t.drop()
@@ -97,6 +97,9 @@ t.drop();
t.save({loc: [0,0]})
res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 17, coarsestIndexedLevel: 5 });
assert.commandWorked(res);
+// Ensure the index actually works at a basic level
+assert.neq(null,
+ t.findOne({ loc : { $geoNear : { $geometry : { type: 'Point', coordinates: [0, 0] } } } }));
t.drop();
t.save({loc: [0,0]})
@@ -107,6 +110,9 @@ t.drop();
t.save({loc: [0,0]})
res = t.ensureIndex({ loc: "2dsphere" }, { finestIndexedLevel: 30, coarsestIndexedLevel: 0 });
assert.commandWorked(res);
+//Ensure the index actually works at a basic level
+assert.neq(null,
+ t.findOne({ loc : { $geoNear : { $geometry : { type: 'Point', coordinates: [0, 0] } } } }));
t.drop();
t.save({loc: [0,0]})
diff --git a/src/mongo/db/index/expression_index.h b/src/mongo/db/index/expression_index.h
index 3806b1e1c4b..672f78457f1 100644
--- a/src/mongo/db/index/expression_index.h
+++ b/src/mongo/db/index/expression_index.h
@@ -77,19 +77,13 @@ namespace mongo {
// Look at the cells we cover and all cells that are within our covering and finer.
// Anything with our cover as a strict prefix is contained within the cover and should
// be intersection tested.
- bool considerCoarser = false;
set<string> intervalSet;
+ set<string> exactSet;
for (size_t i = 0; i < cover.size(); ++i) {
- intervalSet.insert(cover[i].toString());
- // If any of our covers could be covered by something in the index, we have
- // to look at things coarser.
- if (cover[i].level() > coarsestIndexedLevel) {
- considerCoarser = true;
- }
- }
- set<string> exactSet;
- if (considerCoarser) {
+ S2CellId coveredCell = cover[i];
+ intervalSet.insert(coveredCell.toString());
+
// Look at the cells that cover us. We want to look at every cell that contains the
// covering we would index on if we were to insert the query geometry. We generate
// the would-index-with-this-covering and find all the cells strictly containing the
@@ -103,11 +97,16 @@ namespace mongo {
// And we've already looked at points with the cell id 211111 from the regex search
// created above, so we only want things where the value of the last digit is not
// stored (and therefore could be 1).
- for (size_t i = 0; i < cover.size(); ++i) {
- for (S2CellId id = cover[i].parent(); id.level() >= coarsestIndexedLevel;
- id = id.parent()) {
- exactSet.insert(id.toString());
- }
+
+ while (coveredCell.level() > coarsestIndexedLevel) {
+
+ // Add the parent cell of the currently covered cell since we aren't at the
+ // coarsest level yet
+ // NOTE: Be careful not to generate cells strictly less than the
+ // coarsestIndexedLevel - this can result in S2 failures when level < 0.
+
+ coveredCell = coveredCell.parent();
+ exactSet.insert(coveredCell.toString());
}
}