[SERVER-51886] $lookup + $merge pipeline may fail to resolve views correctly when collection names collide Created: 30/Oct/20  Updated: 29/Oct/23  Resolved: 04/Dec/20

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 4.2.0, 4.4.0
Fix Version/s: 4.9.0, 4.2.12, 4.4.4

Type: Bug Priority: Major - P3
Reporter: Max Hirschhorn Assignee: Mihai Andrei
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
is related to SERVER-13201 Allow new Aggregation $merge stage to... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.4, v4.2
Sprint: Query 2020-11-30, Query 2020-12-14
Participants:

 Description   

Getting the namespace involved in a cross-database $merge stage causes the StringMap<ResolvedNamespace> to store a key for the target collection name with an empty pipeline. But that collection name may also be the name for a collection or view in the database the aggregate command is being run against. For certain pipelines, this may cause a $lookup on a view to instead act as if it were performing the $lookup on an empty collection without erroring.

if (involvedNs.db() != request.getNamespaceString().db()) {
    // If the involved namespace is not in the same database as the aggregation, it must be
    // from a $merge to a collection in a different database. Since we cannot write to
    // views, simply assume that the namespace is a collection.
    resolvedNamespaces[involvedNs.coll()] = {involvedNs, std::vector<BSONObj>{}};

Note that because LiteParsedPipeline::getInvolvedNamespaces() returns a stdx::unordered_set<NamespaceString> that namespaces may be resolved in different orders across multiple aggregate command executions. And also note that because resolveInvolvedNamespaces() skips resolving a namespace if its collection name already exists in the StringMap, this issue would only manifest if the $merge namespace was resolved before the $lookup namespace.



 Comments   
Comment by Githook User [ 04/Jan/21 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-51886 $lookup + $merge pipeline may fail to resolve views correctly when collection names collide

(cherry picked from commit 045829020fb4a3972b316b1ad60e9ed2f285b092)
(cherry picked from commit dcd06945691b7cdd520b4c28428d941ee685104d)
Branch: v4.2
https://github.com/mongodb/mongo/commit/e490b04a5e2511e042660c1e1d60b0636f5a14bd

Comment by Githook User [ 16/Dec/20 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-51886 Fix typo in jstest

(cherry picked from commit 7ee29eedb7029d4e3563057b6329678f9102996a)
Branch: v4.4
https://github.com/mongodb/mongo/commit/631c9aea291ca5438622fe21c2fea10231301c8b

Comment by Githook User [ 15/Dec/20 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-51886 Fix typo in jstest
Branch: master
https://github.com/mongodb/mongo/commit/7ee29eedb7029d4e3563057b6329678f9102996a

Comment by Githook User [ 10/Dec/20 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-51886 $lookup + $merge pipeline may fail to resolve views correctly when collection names collide

(cherry picked from commit 045829020fb4a3972b316b1ad60e9ed2f285b092)
Branch: v4.4
https://github.com/mongodb/mongo/commit/dcd06945691b7cdd520b4c28428d941ee685104d

Comment by Githook User [ 03/Dec/20 ]

Author:

{'name': 'Mihai Andrei', 'email': 'mihai.andrei@10gen.com', 'username': 'mtandrei'}

Message: SERVER-51886 $lookup + $merge pipeline may fail to resolve views correctly when collection names collide
Branch: master
https://github.com/mongodb/mongo/commit/045829020fb4a3972b316b1ad60e9ed2f285b092

Generated at Thu Feb 08 05:26:43 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.