[SERVER-66119] INLJ can output the same record twice when value is present by itself and in an array Created: 02/May/22  Updated: 29/Oct/23  Resolved: 06/May/22

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 6.0.0-rc5, 6.1.0-rc0

Type: Bug Priority: Major - P3
Reporter: Mihai Andrei Assignee: Irina Yatsenko (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Gantt Dependency
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.0
Sprint: QE 2022-05-16
Participants:

 Description   

Script:

(function () {
'use strict';
const collName = "fuzzer_coll";
const aggregationList = [
{"$lookup":{ "from": collName, "localField": "foo", "foreignField": "bar", "as": "array" }}];
const documentList = [{ "_id" : 49, "foo": [1, [1]], "bar": 1, }];
 
const coll = db[collName];
coll.drop();
assert.commandWorked(coll.insert(documentList));
const indexList = [\{bar: 1}];
assert.commandWorked(coll.createIndexes(indexList));
 
assert.commandWorked(db.adminCommand({setParameter: 1, internalQuerySlotBasedExecutionDisableLookupPushdown: false}));
const sberes = coll.aggregate(aggregationList).toArray();
jsTestLog("123123 sbe result " + tojson(sberes));
 
assert.commandWorked(db.adminCommand({setParameter: 1, internalQuerySlotBasedExecutionDisableLookupPushdown: true}));
const classicres = coll.aggregate(aggregationList).toArray();
jsTestLog("123123 classic result " + tojson(classicres));
assert.commandWorked(db.adminCommand({setParameter: 1, internalQuerySlotBasedExecutionDisableLookupPushdown: false}));
 
assert.eq(sberes, classicres);
})();

Output:

[[
     {
         "_id" : 49,
         "foo" : [
             1,
             [
                 1
             ]
         ],
         "bar" : 1,
         "array" : [
             {
                 "_id" : 49,
                 "foo" : [
                     1,
                     [
                         1
                     ]
                 ],
                 "bar" : 1
             },
             {
                 "_id" : 49,
                 "foo" : [
                     1,
                     [
                         1
                     ]
                 ],
                 "bar" : 1
             }
         ]
     }
 ]] != [[
     {
         "_id" : 49,
         "foo" : [
             1,
             [
                 1
             ]
         ],
         "bar" : 1,
         "array" : [
             {
                 "_id" : 49,
                 "foo" : [
                     1,
                     [
                         1
                     ]
                 ],
                 "bar" : 1
             }
         ]
     }
 ]] 



 Comments   
Comment by Githook User [ 09/May/22 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-66119 Avoid duplicated seek into index for local fields with nested arrays

(cherry picked from commit 96b8052c9e34423534ac610fcb5b11bca7239d12)
Branch: v6.0
https://github.com/mongodb/mongo/commit/5a4e56115f8ffa057c8e7fda5fb0980e85fdb28b

Comment by Githook User [ 05/May/22 ]

Author:

{'name': 'Irina Yatsenko', 'email': 'irina.yatsenko@mongodb.com', 'username': 'IrinaYatsenko'}

Message: SERVER-66119 Avoid duplicated seek into index for local fields with nested arrays
Branch: master
https://github.com/mongodb/mongo/commit/2b8d2c722b4801e733f49ece64df07bae681e38d

Comment by Irina Yatsenko (Inactive) [ 03/May/22 ]

It's fascinating, the duplication happens only if the repeated key value is the first value of the nested array:

db.s.aggregate({$lookup: {from: "t", localField:"k", foreignField:"k", as:"matched"}})
{ "_id" : 4, "k" : [ 2, [ 1, 2 ] ], "matched" : [ { "_id" : 1, "k" : 2 } ] }
{ "_id" : 5, "k" : [ 2, [ 2, 1 ] ], "matched" : [ { "_id" : 1, "k" : 2 }, { "_id" : 1, "k" : 2 } ] }

Generated at Thu Feb 08 06:04:32 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.