diff options
author | ruslan.abdulkhalikov <ruslan.abdulkhalikov@mongodb.com> | 2022-05-17 00:48:27 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-05-17 02:02:30 +0000 |
commit | 252235fda4d45e85db342bb6437b1587b980b1ed (patch) | |
tree | 7622b604fa7a79579c3139f9f98dd97e2d2e11e0 /jstests | |
parent | 4ad4646e089410bee0926806d10f809baab9fbe9 (diff) | |
download | mongo-252235fda4d45e85db342bb6437b1587b980b1ed.tar.gz |
SERVER-65884 $lookup from ts optimize $sequentialCache
(cherry picked from commit a672dcd5658bdb7117de384e50e1747e610a5684)
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/core/timeseries/timeseries_lookup.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/jstests/core/timeseries/timeseries_lookup.js b/jstests/core/timeseries/timeseries_lookup.js index 75a80a48177..d95bf137f5a 100644 --- a/jstests/core/timeseries/timeseries_lookup.js +++ b/jstests/core/timeseries/timeseries_lookup.js @@ -85,6 +85,99 @@ TimeseriesTest.run((insert) => { assert.eq({host: "host_" + i, matchedB: entryCountPerHost[i]}, results[i], results); } + // Equality Match With Let (uncorrelated) + // Make sure injected $sequentialDocumentCache (right after unpack bucket stage) + // in the inner pipeline is removed. + results = collA.aggregate([ + { + $lookup: { + from: collB.getName(), + let: {"outer_hostname": "$tags.hostname"}, + pipeline: [ + // $match will be pushed before unpack bucket stage + {$match: {$expr: {$eq: ["$$outer_hostname", hosts[0].tags.hostname]}}}, + ], + as: "matchedB" + } + }, { + $project: { + _id: 0, + host: "$tags.hostname", + matchedB: { + $size: "$matchedB" + } + } + }, + {$sort: {host: 1}} + ]).toArray(); + assert.eq(numHosts, results.length, results); + for (let i = 0; i < numHosts; i++) { + const matched = i === 0 ? numDocs : 0; + assert.eq({host: "host_" + i, matchedB: matched}, results[i], results); + } + + // Equality Match With Let (uncorrelated) + // Make sure injected $sequentialDocumentCache in the inner pipeline is removed. + // $sequentialDocumentCache is not located right after unpack bucket stage. + results = collA.aggregate([ + { + $lookup: { + from: collB.getName(), + let: {"outer_hostname": "$tags.hostname"}, + pipeline: [ + {$match: {$expr: {$eq: ["$$outer_hostname", hosts[0].tags.hostname]}}}, + {$set: {foo: {$const: 123}}}, // uncorrelated + ], + as: "matchedB" + } + }, { + $project: { + _id: 0, + host: "$tags.hostname", + matchedB: { + $size: "$matchedB" + } + } + }, + {$sort: {host: 1}} + ]).toArray(); + assert.eq(numHosts, results.length, results); + for (let i = 0; i < numHosts; i++) { + const matched = i === 0 ? numDocs : 0; + assert.eq({host: "host_" + i, matchedB: matched}, results[i], results); + } + + // Equality Match With Let (correlated, no $match re-order) + // Make sure injected $sequentialDocumentCache in the inner pipeline is removed. + // $sequentialDocumentCache is located at the very end of pipeline. + results = collA.aggregate([ + { + $lookup: { + from: collB.getName(), + let: {"outer_hostname": "$tags.hostname"}, + pipeline: [ + {$match: {$expr: {$eq: ["$$outer_hostname", hosts[0].tags.hostname]}}}, + {$set: {foo: "$$outer_hostname"}}, // correlated + ], + as: "matchedB" + } + }, { + $project: { + _id: 0, + host: "$tags.hostname", + matchedB: { + $size: "$matchedB" + } + } + }, + {$sort: {host: 1}} + ]).toArray(); + assert.eq(numHosts, results.length, results); + for (let i = 0; i < numHosts; i++) { + const matched = i === 0 ? numDocs : 0; + assert.eq({host: "host_" + i, matchedB: matched}, results[i], results); + } + // Unequal joins results = collA.aggregate([ { |