[SERVER-73045] Preserve the original filter in the write phase for updateOne/deleteOne/findAndModify without shard key Created: 19/Jan/23  Updated: 29/Oct/23  Resolved: 10/Feb/23

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

Type: Task Priority: Major - P3
Reporter: Cheahuychou Mao Assignee: Jason Zhang
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
is duplicated by SERVER-73044 Preserve the original filter in the w... Closed
Related
is related to SERVER-72084 Handle properly assigning sample ids Closed
Assigned Teams:
Sharding NYC
Backwards Compatibility: Fully Compatible
Sprint: Sharding NYC 2023-02-06, Sharding NYC 2023-02-20
Participants:

 Description   

Currently, in the write phase for updateOne/deleteOne/findAndModify without shard key, mongos replaces the original filter from the client with the _id of the document that it finds in the find phase. The fact that the target shard doesn't receive the original filter is problematic for the purpose of query sampling and shard key analysis.

Consider a collection containing documents with two fields "x" and "y". The user workload involves only updateOne that filters by "y". However, they didn't know about that and sharded the collection on {x: 1}. So now every write is an updateOne without shard key. Due to the overwriting of filter, every write that a shard receives has the filter {_id: ...} and that's what gets written down to the config.sampledQueries collection. Now when the user runs analyzeShardKey to analyze the shard key {y: 1}, they would see that every write is a scatter gather and single write without shard key and conclude that the shard key is bad. Or more generally, in this scenario, all shard keys except {_id: 1} would have equally bad metrics.

Given this, the write phase should set the filter to the _id plus the original filter.

 



 Comments   
Comment by Githook User [ 10/Feb/23 ]

Author:

{'name': 'Jason Zhang', 'email': 'jason.zhang@mongodb.com', 'username': 'jz1242'}

Message: SERVER-73045 Preserve the original filter in the write phase for updateOne/deleteOne/findAndModify without shard key
Branch: master
https://github.com/mongodb/mongo/commit/d293bee5122e7d0582e73c86d0fe567baf36f64e

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