0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-57000 Fix handling of correlated pipeline with facet

This commit is contained in:
Svilen Mihaylov 2021-05-11 09:06:49 -04:00 committed by Evergreen Agent
parent 234c529c34
commit ff89dc4d80
3 changed files with 30 additions and 1 deletions

View File

@ -77,4 +77,22 @@ cursor.toArray().forEach(user => {
assert.eq(1, joinedDocs.length);
assert.eq(user['_id'], joinedDocs[0].owner);
});
// SERVER-57000: Test handling of lack of correlation (addFields with empty set of columns)
assert.doesNotThrow(() => testColl.aggregate([
{
$lookup: {
as: 'items_check',
from: joinColl.getName(),
pipeline: [
{$addFields: {}},
{
$facet: {
all: [{$match: {}}],
},
},
],
},
},
]));
})();

View File

@ -120,12 +120,15 @@ Pipeline::SourceContainer::iterator DocumentSourceSequentialDocumentCache::doOpt
// Iterate through the pipeline stages until we find one which cannot be cached.
// A stage cannot be cached if it either: 1. depends on a variable defined in this scope, or
// 2. generates random numbers.
DocumentSource* lastPtr = nullptr;
for (; prefixSplit != container->end(); ++prefixSplit) {
(*prefixSplit)->getDependencies(&deps);
if (deps.hasVariableReferenceTo(varIDs) || deps.needRandomGenerator) {
break;
}
lastPtr = prefixSplit->get();
}
// The 'prefixSplit' iterator is now pointing to the first stage of the correlated suffix. If
@ -138,6 +141,8 @@ Pipeline::SourceContainer::iterator DocumentSourceSequentialDocumentCache::doOpt
// If the cache has been populated and is serving results, remove the non-correlated prefix.
if (_cache->isServing()) {
// Need to dispose last stage to be removed.
lastPtr->dispose();
container->erase(container->begin(), prefixSplit);
}

View File

@ -58,6 +58,10 @@ const char* DocumentSourceSingleDocumentTransformation::getSourceName() const {
}
DocumentSource::GetNextResult DocumentSourceSingleDocumentTransformation::doGetNext() {
if (!_parsedTransform) {
return DocumentSource::GetNextResult::makeEOF();
}
// Get the next input document.
auto input = pSource->getNext();
if (!input.isAdvanced()) {
@ -69,7 +73,9 @@ DocumentSource::GetNextResult DocumentSourceSingleDocumentTransformation::doGetN
}
intrusive_ptr<DocumentSource> DocumentSourceSingleDocumentTransformation::optimize() {
_parsedTransform->optimize();
if (_parsedTransform) {
_parsedTransform->optimize();
}
return this;
}