[SERVER-78541] Remove unneeded [isArray] check on sharding key Created: 29/Jun/23  Updated: 29/Oct/23  Resolved: 09/Aug/23

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

Type: Improvement Priority: Minor - P4
Reporter: Richard Hausman (Inactive) Assignee: Ivan Fefer
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query Execution
Backwards Compatibility: Fully Compatible
Participants:

 Description   

In sbe_stage_builders.cpp, there is a point during the creation of the SBE plan in which we need to create a plan to retrieve the shard key in order to create the ShardFilterer. At this point, we add an if expression which makes sure that the shard key is not an array. However, this check is not needed and adds an extra stage to the plan because writing an array to the shard key is already prohibited, so this scenario will never arise.

Example SBE plan generated by using find() on a sharded collection with shard key "x":

"slotBasedPlan":{    
"slots": ...
"stages":
"[2] filter {    
let [        l1.0 = (s6 ?: null)     ]     in 
shardFilter(s5, 
     if isArray(l1.0) then Nothing else // This part is not needed 
    makeBsonObj(MakeObjSpec(drop, [], [\"x\"]), Nothing, l1.0) // spec,  root, projection values   ) } ...



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

Author:

{'name': 'Ivan Fefer', 'email': 'ivan.fefer@mongodb.com', 'username': 'Fefer-Ivan'}

Message: SERVER-78541 Remove isArray checks from SBE shard filter
Branch: master
https://github.com/mongodb/mongo/commit/dc4d0d956605d46e717252c3a720fdca4c7e248b

Comment by Ivan Fefer [ 08/Aug/23 ]

Currently the generated SBE code is written to mimic the behavior of ShardKeyPattern::extractShardKeyFromDocumentKey

This function returns empty BSONObj in case it finds an array. SBE code returns Nothing.

Now, when SBE is used only for reads,  we can omit IsArray, but in the future, when we may encounter this code for writes, we should not forget to support possible arrays.

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