[SERVER-78650] Change stream oplog rewrite of $nor hits empty-array validation if no children are eligible for rewrite Created: 03/Jul/23  Updated: 29/Oct/23  Resolved: 15/Aug/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 6.0.0, 7.0.0-rc0
Fix Version/s: 7.1.0-rc0, 6.0.10, 7.0.2

Type: Bug Priority: Major - P3
Reporter: Bernard Gorman Assignee: Milena Ivanova
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Depends
Issue split
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0, v6.0
Participants:
Linked BF Score: 57

 Description   

When a $nor is rewritten as part of the change stream oplog filter and none of its children are eligible for a rewrite, an empty $nor is left in the MatchExpression tree. We do the same for $and, but in that case our subsequent call to MatchExpression::optimize when the filter is complete removes the empty $ands (and any empty $ors, though our rewrites do not produce these) from the tree. However, we don't perform any such optimization for empty $nor. Therefore, when we subsequently run the rewritten filter through parseTreeTopLevel, we end up throwing when it sees the empty $nor array.

The symptoms are worsened by the fact that we also rewrite the user $match into the buildTransactionFilter, but only a very limited set of fields. This means that even if the children of the $nor are generally eligible for rewrites (e.g. operationType), they may be excluded from this second rewrite, and thus will end up producing an empty $nor.

The bug doesn't manifest if the $nor only has a single child, because the initial optimization pass will unwrap the $nor into a $not of the child predicate, and so we never attempt to rewrite the $nor.

To fix this issue, we could perform a similar optimization-away of empty $nor as is already done for $and and $or.



 Comments   
Comment by Githook User [ 25/Aug/23 ]

Author:

{'name': 'Peter Volk', 'email': 'peter.volk@mongodb.com', 'username': 'HCSPete'}

Message: SERVER-78650 Change stream oplog rewrite of $nor hits empty-array validation if no children are eligible for rewrite
Branch: v6.0
https://github.com/mongodb/mongo/commit/c632985995e35f7d3fc285901166b4c99a02c21b

Comment by Githook User [ 24/Aug/23 ]

Author:

{'name': 'Peter Volk', 'email': 'peter.volk@mongodb.com', 'username': 'HCSPete'}

Message: SERVER-78650 Change stream oplog rewrite of $nor hits empty-array validation

if no children are eligible for rewrite
Branch: v7.0
https://github.com/mongodb/mongo/commit/19ef1b240adafb7fda568a2b6b140a668ffb3c51

Comment by Githook User [ 02/Aug/23 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-78650 Change stream oplog rewrite of $nor hits empty-array validation
if no children are eligible for rewrite

Exclude test from multiversion lts suites
Branch: minh.luu-no_compile_sys-perf
https://github.com/mongodb/mongo/commit/1e00cf6a84c15444ed0df965fada1f3ca1526a9a

Comment by Githook User [ 01/Aug/23 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-78650 Change stream oplog rewrite of $nor hits empty-array validation
if no children are eligible for rewrite

Exclude test from multiversion lts suites
Branch: master
https://github.com/mongodb/mongo/commit/1e00cf6a84c15444ed0df965fada1f3ca1526a9a

Comment by Githook User [ 01/Aug/23 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-78650 Change stream oplog rewrite of $nor hits empty-array validation
if no children are eligible for rewrite
Branch: minh.luu-no_compile_sys-perf
https://github.com/mongodb/mongo/commit/a70be4be932dec9024ae228c72b1d86330c6edb5

Comment by Githook User [ 31/Jul/23 ]

Author:

{'name': 'Milena Ivanova', 'email': 'milena.ivanova@mongodb.com', 'username': 'mivanova3'}

Message: SERVER-78650 Change stream oplog rewrite of $nor hits empty-array validation
if no children are eligible for rewrite
Branch: master
https://github.com/mongodb/mongo/commit/a70be4be932dec9024ae228c72b1d86330c6edb5

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