diff options
author | Hari Khalsa <hkhalsa@10gen.com> | 2013-10-24 12:08:41 -0400 |
---|---|---|
committer | Hari Khalsa <hkhalsa@10gen.com> | 2013-10-24 12:08:41 -0400 |
commit | 6332ae304a743abf86d47d92c12bf7f3f2169368 (patch) | |
tree | aa3d166372650e3cff6454ec7086ea568d65e555 | |
parent | c3019ad939da94e44689c49a92a86b357b8c2596 (diff) | |
download | mongo-6332ae304a743abf86d47d92c12bf7f3f2169368.tar.gz |
SERVER-11149 2dsphere handle sparse like other indices
-rw-r--r-- | jstests/geo_s2sparse.js | 39 | ||||
-rw-r--r-- | src/mongo/db/index/s2_access_method.cpp | 6 |
2 files changed, 40 insertions, 5 deletions
diff --git a/jstests/geo_s2sparse.js b/jstests/geo_s2sparse.js index ee5d41ac940..df1b1eb19e6 100644 --- a/jstests/geo_s2sparse.js +++ b/jstests/geo_s2sparse.js @@ -2,6 +2,40 @@ t = db.geo_s2sparse; t.drop(); +// +// Sparse on +// + +// Insert a doc. that is indexed +pointA = { "type" : "Point", "coordinates": [ 40, 5 ] } +t.insert( {geo : pointA , nonGeo: "pointA"}) +// Make a sparse index. +t.ensureIndex({geo: "2dsphere", otherNonGeo: 1}, {sparse: 1}); + +// Save the size of the index with one obj. +var sizeWithOneIndexedObj = t.stats().indexSizes.geo_2dsphere; + +// Insert a bunch of data that won't be indexed. +var N = 1000; +for (var i = 0; i < N; ++i) { + // Missing both. + t.insert( {nonGeo: "pointA"}) + // Missing geo. + t.insert( {geo: pointA}) + // Missing nonGeo. + t.insert( {otherNonGeo: "pointA"}) +} + +// The size should be the same as we don't index no-geo data. +var sizeAfter = t.stats().indexSizes.geo_2dsphere; +assert.eq(sizeAfter, sizeWithOneIndexedObj); + +// +// Sparse off +// + +t.drop(); + // Insert a doc. that is indexed pointA = { "type" : "Point", "coordinates": [ 40, 5 ] } t.insert( {geo : pointA , nonGeo: "pointA"}) @@ -17,6 +51,7 @@ for (var i = 0; i < N; ++i) { t.insert( {nonGeo: "pointA"}) } -// The size should be the same as we don't index the missing data. +// Since the index isn't sparse we have entries in the index for each insertion even though it's +// missing the geo key. var sizeAfter = t.stats().indexSizes.geo_2dsphere; -assert.eq(sizeAfter, sizeWithOneIndexedObj); +assert.gt(sizeAfter, sizeWithOneIndexedObj); diff --git a/src/mongo/db/index/s2_access_method.cpp b/src/mongo/db/index/s2_access_method.cpp index ebab9df183c..64cfd4cef55 100644 --- a/src/mongo/db/index/s2_access_method.cpp +++ b/src/mongo/db/index/s2_access_method.cpp @@ -102,11 +102,11 @@ namespace mongo { // false means Don't expand the last array, duh. obj.getFieldsDotted(e.fieldName(), fieldElements, false); + // If we're sparse and we're missing any field, bail out. + if (_descriptor->isSparse() && fieldElements.empty()) { return; } + BSONObjSet keysForThisField; if (IndexNames::GEO_2DSPHERE == e.valuestr()) { - // We can't ever return documents that don't have geometry so don't bother indexing - // them. - if (fieldElements.empty()) { return; } getGeoKeys(obj, fieldElements, &keysForThisField); } else { getLiteralKeys(fieldElements, &keysForThisField); |