[SERVER-33687] Sort order of array indexes can determine success of an update Created: 05/Mar/18  Updated: 06/Dec/22  Resolved: 15/Oct/20

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Justin Seyster Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 0
Labels: mql-semantics, query-44-grooming
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
duplicates SERVER-50778 "Cannot apply $bit" when $bit update ... Closed
is duplicated by SERVER-35220 Updating a document with dotted notat... Closed
Related
related to SERVER-31821 Update operator $min handles non-exis... Closed
Assigned Teams:
Query
Operating System: ALL
Participants:
Case:
Linked BF Score: 0

 Description   

A quirk of the update language is that when there are multiple updates that reference indexes in the same array, the updates are ordered by the lexicographic order of the indexes, rather than numerical order. For example, when updating indexes 2 and 10 the update to 10 applies first.

We noted this behavior in SERVER-31821, but we did not realize at the time that there are updates that would succeed if applied in ascending numerical order but fail because they are applied in lexicographic order.

Consider the update:
{$inc: {"array.2": 1, "array.10": 1}}

If "array" is initially empty, the update applies to "array.10" first, which creates an entry at slot 10 and extends the array with "null" for slots 0-9. The update for "array.2" then gets applied to a null value, causing it to fail. If these updates had been applied in the opposite order (numerically ascending), both would have succeeded.



 Comments   
Comment by Asya Kamsky [ 19/Oct/18 ]

Is this really the correct fix?  Do we consider it correct that updating missing and null fields have different behavior?

Comment by Ian Whalen (Inactive) [ 09/Mar/18 ]

Probably how we should fix this: update in the order of increasing numerical array indexes.

Generated at Thu Feb 08 04:34:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.