-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: 6.1.0-rc0
-
Component/s: Query Planning
-
None
-
Fully Compatible
-
ALL
-
v6.0
-
-
QO 2022-05-16, QO 2022-05-30, QO 2022-06-13
In order to execute a positional projection, the corresponding match expression must run to find the first matching element of the array. Internally, this is implemented by keeping a MatchExpressionASTNode inside the projection AST. The MatchExpressionASTNode holds onto a copy of the MatchExpression. This match expression is created by re-parsing the BSON representation provided by the user, and it is implemented in such a way that no input parameter markers are added to the resulting MatchExpression tree.
When the projection is compiled to an SBE plan by the SBE stage builders, the resulting plan inlines any constants in the match expression because it has no parameter markers. This is true even if the match expression was auto-parameterized! Also, note that the MatchExpressionASTNode is an internal construct which is not reflected in the SBE plan cache key – we currently encode the user's projection verbatim into the key, and the positional projection does not syntactically contain the match expression. The consequence is that we have a parameterized plan cache entry which accidentally embeds particular constants into the SBE plan for executing the projection. When this cache entry is reused for a new query with different parameter values, it can result in missing or incorrect query results.