diff options
author | Eric Cox <eric.cox@mongodb.com> | 2022-07-10 05:22:03 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-07-10 05:47:20 +0000 |
commit | 39ef61c583b47d764872acc9f3d4c4c168377b5b (patch) | |
tree | 743fad93dc9d30edc53b3bd6ac8d22ceb5a40832 | |
parent | e3813f4ed0abe013ba3635c5249e4106cf18ae52 (diff) | |
download | mongo-39ef61c583b47d764872acc9f3d4c4c168377b5b.tar.gz |
SERVER-57938 Skip validation for stored geometry if a 2dsphere index exists
cherry-picks 85cf0f4bdb5763514df90653a677cf8fa0100305
-rw-r--r-- | jstests/core/geo_s2intersection.js | 7 | ||||
-rw-r--r-- | src/mongo/db/exec/geo_near.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/geo/geoparser.cpp | 5 |
3 files changed, 13 insertions, 3 deletions
diff --git a/jstests/core/geo_s2intersection.js b/jstests/core/geo_s2intersection.js index 3c841d85f50..958da005a9f 100644 --- a/jstests/core/geo_s2intersection.js +++ b/jstests/core/geo_s2intersection.js @@ -1,3 +1,9 @@ +/** + * Tests $geoIntersect basic functionality. + */ +(function() { +"use strict"; + var t = db.geo_s2intersectinglines; t.drop(); t.createIndex({geo: "2dsphere"}); @@ -158,3 +164,4 @@ assert.eq(result.count(), 1); // two $geoIntersects should as well. result = t.find({$and: [{a: {$geoIntersects: firstPoint}}, {a: {$geoIntersects: secondPoint}}]}); assert.eq(result.count(), 1); +})(); diff --git a/src/mongo/db/exec/geo_near.cpp b/src/mongo/db/exec/geo_near.cpp index 0c07e090a8a..9dd45cfe05d 100644 --- a/src/mongo/db/exec/geo_near.cpp +++ b/src/mongo/db/exec/geo_near.cpp @@ -150,7 +150,9 @@ static double computeGeoNearDistance(const GeoNearParams& nearParams, WorkingSet CRS queryCRS = nearParams.nearQuery->centroid->crs; - // Extract all the geometries out of this document for the near query + // Extract all the geometries out of this document for the near query. Note that the NearStage + // stage can only be run with an existing index. Therefore, it is always safe to skip geometry + // validation. std::vector<std::unique_ptr<StoredGeometry>> geometries; extractGeometries(member->doc.value().toBson(), nearParams.nearQuery->field, &geometries); diff --git a/src/mongo/db/geo/geoparser.cpp b/src/mongo/db/geo/geoparser.cpp index 380c17ffd0e..ecb1d59452d 100644 --- a/src/mongo/db/geo/geoparser.cpp +++ b/src/mongo/db/geo/geoparser.cpp @@ -211,7 +211,8 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem, loops.push_back(std::make_unique<S2Loop>(points)); S2Loop* loop = loops.back().get(); - // Check whether this loop is valid. + // Check whether this loop is valid if vaildation hasn't been already done on 2dSphere index + // insertion which is controlled by the 'skipValidation' flag. // 1. At least 3 vertices. // 2. All vertices must be unit length. Guaranteed by parsePoints(). // 3. Loops are not allowed to have any duplicate vertices. @@ -224,7 +225,7 @@ static Status parseGeoJSONPolygonCoordinates(const BSONElement& elem, // Check the first loop must be the exterior ring and any others must be // interior rings or holes. - if (loops.size() > 1 && !loops[0]->Contains(loop)) { + if (!skipValidation && loops.size() > 1 && !loops[0]->Contains(loop)) { return BAD_VALUE( "Secondary loops not contained by first exterior loop - " "secondary loops must be holes: " |