summaryrefslogtreecommitdiff
path: root/src/mongo/db/query
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2014-10-27 12:37:50 -0400
committerDavid Storch <david.storch@10gen.com>2014-10-27 15:14:27 -0400
commitf786bf15bd9dc5100c53c7f8a5b2080a3a8cf476 (patch)
treed1795a930dd170d0bee9eda1da74d8a01c37b30a /src/mongo/db/query
parent9c1573b696246268f7b24b62391164451233283d (diff)
downloadmongo-f786bf15bd9dc5100c53c7f8a5b2080a3a8cf476.tar.gz
SERVER-15527 change explain index bounds format from verbose string format to BSON format
Diffstat (limited to 'src/mongo/db/query')
-rw-r--r--src/mongo/db/query/explain.cpp9
-rw-r--r--src/mongo/db/query/index_bounds.cpp65
-rw-r--r--src/mongo/db/query/index_bounds.h10
3 files changed, 16 insertions, 68 deletions
diff --git a/src/mongo/db/query/explain.cpp b/src/mongo/db/query/explain.cpp
index a9195365760..3ff7d7e8bbd 100644
--- a/src/mongo/db/query/explain.cpp
+++ b/src/mongo/db/query/explain.cpp
@@ -317,9 +317,12 @@ namespace mongo {
bob->appendBool("isMultiKey", spec->isMultiKey);
bob->append("direction", spec->direction > 0 ? "forward" : "backward");
- // Bounds can get large. Truncate to 1 MB.
- static const int kMaxBoundsSize = 1024 * 1024;
- bob->append("indexBounds", spec->indexBoundsVerbose.substr(0, kMaxBoundsSize));
+ if ((topLevelBob->len() + spec->indexBounds.objsize()) > kMaxStatsBSONSize) {
+ bob->append("warning", "index bounds omitted due to BSON size limit");
+ }
+ else {
+ bob->append("indexBounds", spec->indexBounds);
+ }
if (verbosity >= ExplainCommon::EXEC_STATS) {
bob->appendNumber("keysExamined", spec->keysExamined);
diff --git a/src/mongo/db/query/index_bounds.cpp b/src/mongo/db/query/index_bounds.cpp
index 446a3dc4e02..d7532c9a724 100644
--- a/src/mongo/db/query/index_bounds.cpp
+++ b/src/mongo/db/query/index_bounds.cpp
@@ -184,60 +184,6 @@ namespace mongo {
return ss;
}
- BSONObj IndexBounds::toLegacyBSON() const {
- BSONObjBuilder builder;
- if (isSimpleRange) {
- // TODO
- }
- else {
- for (vector<OrderedIntervalList>::const_iterator itField = fields.begin();
- itField != fields.end();
- ++itField) {
- BSONArrayBuilder fieldBuilder(builder.subarrayStart(itField->name));
- for (vector<Interval>::const_iterator itInterval = itField->intervals.begin();
- itInterval != itField->intervals.end();
- ++itInterval) {
- BSONArrayBuilder intervalBuilder;
-
- // Careful to output $minElement/$maxElement if we don't have bounds.
- if (itInterval->start.eoo()) {
- BSONObjBuilder minBuilder;
- minBuilder.appendMinKey("");
- BSONObj minKeyObj = minBuilder.obj();
- intervalBuilder.append(minKeyObj.firstElement());
- }
- else {
- intervalBuilder.append(itInterval->start);
- }
-
- if (itInterval->end.eoo()) {
- BSONObjBuilder maxBuilder;
- maxBuilder.appendMaxKey("");
- BSONObj maxKeyObj = maxBuilder.obj();
- intervalBuilder.append(maxKeyObj.firstElement());
- }
- else {
- intervalBuilder.append(itInterval->end);
- }
-
- fieldBuilder.append(
- static_cast<BSONArray>(intervalBuilder.arr().clientReadable()));
-
- // If the bounds object gets too large, truncate it.
- static const int kMaxBoundsSize = 1024 * 1024;
- if (builder.len() > kMaxBoundsSize) {
- intervalBuilder.doneFast();
- fieldBuilder.append(BSON("warning" << "bounds obj exceeds 1 MB"));
- fieldBuilder.doneFast();
- return builder.obj();
- }
- }
- }
- }
-
- return builder.obj();
- }
-
BSONObj IndexBounds::toBSON() const {
BSONObjBuilder bob;
vector<OrderedIntervalList>::const_iterator itField;
@@ -248,7 +194,16 @@ namespace mongo {
for (itInterval = itField->intervals.begin()
; itInterval != itField->intervals.end()
; ++itInterval) {
- fieldBuilder.append(itInterval->toString());
+ std::string intervalStr = itInterval->toString();
+
+ // Insulate against hitting BSON size limit.
+ if ((bob.len() + intervalStr.size()) > BSONObjMaxUserSize) {
+ fieldBuilder.append("warning: bounds truncated due to BSON size limit");
+ fieldBuilder.doneFast();
+ return bob.obj();
+ }
+
+ fieldBuilder.append(intervalStr);
}
fieldBuilder.doneFast();
diff --git a/src/mongo/db/query/index_bounds.h b/src/mongo/db/query/index_bounds.h
index 514070b9db4..e99754680b9 100644
--- a/src/mongo/db/query/index_bounds.h
+++ b/src/mongo/db/query/index_bounds.h
@@ -95,16 +95,6 @@ namespace mongo {
std::string toString() const;
/**
- * Legacy BSON format for explain. The format is an array of arrays for each field.
- *
- * TODO remove this function once the new explain format is on by default.
- *
- * Ex.
- * {a: [ [1, 1], [3, 10] ], b: [ [Infinity, 10] ] }
- */
- BSONObj toLegacyBSON() const;
-
- /**
* BSON format for explain. The format is an array of strings for each field.
* Each string represents an interval. The strings use "[" and "]" if the interval
* bounds are inclusive, and "(" / ")" if exclusive.