You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix stale nested object array indexes on patch update - #2920
Replacing or deleting a nested object[] field could leave its flattened child values in the in-memory index.
For example, after patching {"reviewQueue":[]}, a filter such as reviewQueue.reviewerId:=9001 could still match the document even though the stored array was empty.
This change removes stale child indexes when an object array is replaced or deleted, including arrays inside nested objects such as wrapper.reviewQueue.
It also preserves unchanged child indexes: changing taskIds while retaining reviewerId keeps the document searchable by that reviewer under both UPDATE and UPSERT.
Implementation
Carry the full parent path through recursive update diffing.
Use root .flat metadata and root-level deletion output to remove flattened children missing from the update.
Leave supplied children to the existing diff logic, preserving unchanged values and reindexing changed values.
Restrict child scans to object parents and object arrays, and avoid copying flattened field names.
Validation
The two added regressions failed before the fix and passed afterward. Coverage includes:
Unchanged siblings under UPDATE and UPSERT.
Empty-array and null replacements inside nested objects.
Stored document values and preservation of unrelated nested fields.
The object check only looks at the first element. An array like [null, {"userId": 31}] is accepted on create, and after replacing it with [], userId:=31 still matches. Please check whether any element is an object, and add this case to the test.
Instead of scanning all of .flat for every replaced parent, we can use search_schema.equal_prefix_range() on the full path, the way the null branch already does. That also makes the existing top-level block in the null branch redundant, so it can be removed. In a debug build, an update that nulls 4,000 nested objects took about 25% longer with the scan, and with the prefix lookup it is back to the current cost.
When we remove a child, we should also erase it from new_doc. On an update, new_doc starts as a copy of the old document, and the missing-values index is computed from it, so a track_missing_values child still reads as present (a _missing filter on it doesn't match) until a restart.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change Summary
Replacing or deleting a nested object[] field could leave its flattened child values in the in-memory index.
For example, after patching
{"reviewQueue":[]}, a filter such asreviewQueue.reviewerId:=9001could still match the document even though the stored array was empty.This change removes stale child indexes when an object array is replaced or deleted, including arrays inside nested objects such as
wrapper.reviewQueue.It also preserves unchanged child indexes: changing taskIds while retaining reviewerId keeps the document searchable by that reviewer under both
UPDATEandUPSERT.Implementation
root .flatmetadata and root-level deletion output to remove flattened children missing from the update.Validation
The two added regressions failed before the fix and passed afterward. Coverage includes:
UPDATEandUPSERT.PR Checklist