[SERVER-75356] explain command for a find with $expr and let parameters fails if the collection is sharded Created: 27/Mar/23  Updated: 29/Oct/23  Resolved: 13/Apr/23

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

Type: Bug Priority: Major - P3
Reporter: Cheahuychou Mao Assignee: David Storch
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Related
related to SERVER-76037 Write commands using updateOne withou... Closed
is related to SERVER-71636 Explain executionStats does not work ... Closed
is related to SERVER-75927 Shards see different values for 'let'... Closed
Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v7.0, v6.3, v6.0, v5.0
Sprint: QE 2023-04-17
Participants:

 Description   

For an unsharded collection, the following explain command runs successfully.

{
        explain: {find: collName, filter: {$expr: {$eq: ["$x", "$$var"]}}, let : {var : 1}}
} 

However, for a sharded collection, it fails with the following error:

{"ok" : 0, "errmsg" : "Use of undefined variable: var", "code" : 17276, "codeName" : "Location17276"}

The behavior is the same on the 6.0 branch.



 Comments   
Comment by Githook User [ 18/Apr/23 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}

Message: SERVER-75356 Fix sharded explain path's handling of 'let' parameters

(cherry picked from commit 7ed14a4b2c043c639d1c6aa4d22f80f30ca44d97)
Branch: v6.0
https://github.com/mongodb/mongo/commit/4d0da2a1bf761fa871b0ddd101f67c37791d2007

Comment by Githook User [ 17/Apr/23 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}

Message: SERVER-75356 Fix sharded explain path's handling of 'let' parameters

(cherry picked from commit 33e6eec5978a20a4b227c36f26b0ae909e8e6728)
Branch: v7.0
https://github.com/mongodb/mongo/commit/7ed14a4b2c043c639d1c6aa4d22f80f30ca44d97

Comment by Githook User [ 13/Apr/23 ]

Author:

{'name': 'David Storch', 'email': 'david.storch@mongodb.com', 'username': 'dstorch'}

Message: SERVER-75356 Fix sharded explain path's handling of 'let' parameters
Branch: master
https://github.com/mongodb/mongo/commit/33e6eec5978a20a4b227c36f26b0ae909e8e6728

Comment by David Storch [ 06/Apr/23 ]

I spent a little bit of time debugging this. The spurious error gets produced on mongos before the operation is ever forwarded to the shards. It happens as we are parsing the query with an incompletely initialized ExpressionContext for the purpose of shard targeting. Specifically, the error happens while we are creating a CanonicalQuery in this code path:

https://github.com/mongodb/mongo/blob/84d1e35168bd516da60ce7a81b5871fef0181688/src/mongo/s/shard_key_pattern_query_util.cpp#L426-L432

It's a similar problem to SERVER-71636 but it looks like it will require a different fix. I'm actually not quite sure how to fix it yet, but I'm hoping that hana.pearlman@mongodb.com can be the reviewer given the context that carries over from SERVER-71636.

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