summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Evans <jacob.evans@10gen.com>2021-08-23 18:20:30 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-11-04 20:26:00 +0000
commit0bbd2f406a857b98d733993c621806bbf90c2f80 (patch)
treed95a4264d4bccf54a3567bfe4447e1d165274aec
parentbf031c7246810e873d7d9db14c57de1d771f1e56 (diff)
downloadmongo-0bbd2f406a857b98d733993c621806bbf90c2f80.tar.gz
SERVER-59432 tassert for group system var optimize
(cherry picked from commit 5cf8a293567989fcc970fb21cde4a1af111c8b58)
-rw-r--r--src/mongo/db/pipeline/document_source_group.cpp4
-rw-r--r--src/mongo/db/pipeline/expression.cpp9
2 files changed, 11 insertions, 2 deletions
diff --git a/src/mongo/db/pipeline/document_source_group.cpp b/src/mongo/db/pipeline/document_source_group.cpp
index fdcacba50e5..f5a187ed7fc 100644
--- a/src/mongo/db/pipeline/document_source_group.cpp
+++ b/src/mongo/db/pipeline/document_source_group.cpp
@@ -832,7 +832,9 @@ DocumentSourceGroup::rewriteGroupAsTransformOnFirstDocument() const {
// each document has a unique _id, it will just return the entire collection). We only
// apply the rewrite when grouping by a single field, so we cannot apply it in this case,
// where we are grouping by the entire document.
- invariant(fieldPath.getFieldName(0) == "CURRENT" || fieldPath.getFieldName(0) == "ROOT");
+ tassert(5943200,
+ "Optimization attempted on group by always-dissimilar system variable",
+ fieldPath.getFieldName(0) == "CURRENT" || fieldPath.getFieldName(0) == "ROOT");
return nullptr;
}
diff --git a/src/mongo/db/pipeline/expression.cpp b/src/mongo/db/pipeline/expression.cpp
index 8f03f21c2f9..599837bb631 100644
--- a/src/mongo/db/pipeline/expression.cpp
+++ b/src/mongo/db/pipeline/expression.cpp
@@ -2348,7 +2348,14 @@ intrusive_ptr<ExpressionFieldPath> ExpressionFieldPath::createVarFromString(
ExpressionFieldPath::ExpressionFieldPath(ExpressionContext* const expCtx,
const string& theFieldPath,
Variables::Id variable)
- : Expression(expCtx), _fieldPath(theFieldPath), _variable(variable) {}
+ : Expression(expCtx), _fieldPath(theFieldPath), _variable(variable) {
+ const auto varName = theFieldPath.substr(0, theFieldPath.find('.'));
+ tassert(5943201,
+ std::string{"Variable with $$ROOT's id is not $$CURRENT or $$ROOT as expected, "
+ "field path is actually '"} +
+ theFieldPath + "'",
+ _variable != Variables::kRootId || varName == "CURRENT" || varName == "ROOT");
+}
intrusive_ptr<Expression> ExpressionFieldPath::optimize() {
if (_variable == Variables::kRemoveId) {