[SERVER-67678] Incorrect result is returned when there's a wildcard index and a filter like $and: [{field: {$type: 'object'}, {file: {$size: 1}}] Created: 29/Jun/22  Updated: 29/Oct/23  Resolved: 27/Jul/22

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

Type: Bug Priority: Major - P3
Reporter: Yoon Soo Kim Assignee: Denis Grebennicov
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Related
related to SERVER-69441 Pop only necessary iets while buildin... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v6.0
Sprint: QE 2022-07-11, QE 2022-07-25, QE 2022-08-08
Participants:
Linked BF Score: 12

 Description   

For repro:

https://jira.mongodb.org/browse/BF-25571?focusedCommentId=4646592&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-4646592

RCA:

https://jira.mongodb.org/browse/BF-25571?focusedCommentId=4648972&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-4648972

Yoonsoo' debug log:
The SBE $type doing wrong was my first theory but it didn’t turn out to be. Here’s how I concluded the issue is related to the SBE plan cache.
The plan that is generated when the feature is off has the following subtree which is for {$type: 'object'} match.

            [2] project [s25 = fillEmpty (typeMatch (s24, 8), false)]
            [2] limit 1
            [2] coscan

I made a breakpoint there and it got called and I found it passed. So, I don’t think the SBE typeMatch is doing something wrong.
The plan which is generated when the feature is on also has the above subtree.
It didn’t get called at all. So, I made another breakpoint at the following traverse.

        [2] traverse s45 s44 s43 [s42, s41] {s45 || s44} {s45}
        from
            [2] project [s43 = getField (s41, "a")]
            [2] nlj [] [s40, s6, s9, s12, s15]
                left
                    [1] unique [s40]
                    [1] branch {s39} [s6, s9, s12, s15, s40] // This branch is unnecessarily added

The above traverse is on top of branch. And I confirmed that traverse didn’t return anything (at the first getNext() call, it returned EOF) and so typeMatch didn’t get a chance to be evaluated.
The only difference between two plans was branch. So I suspected that branch part caused the issue



 Comments   
Comment by Githook User [ 27/Jul/22 ]

Author:

{'name': 'Denis Grebennicov', 'email': 'denis.grebennicov@mongodb.com', 'username': 'denis631'}

Message: SERVER-67678 Incorrect result is returned when there's a wildcard index and a filter like $and: [{field: {$type: 'object'}, {file: {$size: 1}}]
Branch: master
https://github.com/mongodb/mongo/commit/6d05f7a23d3cbe40d664fd1391386416fb667f26

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