[Draft] Batch updated by key groups#303
Open
suddendust wants to merge 2 commits into
Open
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #303 +/- ##
============================================
- Coverage 81.68% 81.51% -0.18%
Complexity 1532 1532
============================================
Files 241 241
Lines 7420 7503 +83
Branches 718 726 +8
============================================
+ Hits 6061 6116 +55
- Misses 912 938 +26
- Partials 447 449 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Batch updates by key groups for
bulkUpdateProblem
The previous
bulkUpdateimplementation inFlatPostgresCollectionexecuted a separate SQL UPDATE per key, even when multiple keys shared identical update operations (same columns, operators, and paths). For bulk updates with N keys, this meant N individual database round-trips — each preparing and executing its ownPreparedStatement.This is inefficient when many keys receive the same type of update, which is a common pattern in practice.
Solution
Keys are now grouped by their "update shape" — a canonical key derived from the sorted combination of
column:operator:path— and each group is executed as a single JDBC batch usingPreparedStatement.addBatch()/executeBatch().New components
groupKeysByUpdateShape()— Iterates over all(Key, Collection<SubDocumentUpdate>)entries, validates and resolves columns, then buckets keys into groups that share the same shape key.computeUpdateShapeKey()— Builds a deterministic string signature by sorting updates by path and concatenatingcolumn:operator:path;for each. Keys with identical signatures share a SQL template.KeyUpdateGroup(inner class) — Holds the resolved columns, list of keys, and per-key update values for a single group.executeBatchUpdate()— Builds onePreparedStatementfrom the group's SQL template, then loops over all keys in the group: binds per-key parameter values (including thelastUpdatedTscolumn), callsaddBatch(), and finallyexecuteBatch()in a single round-trip.What changed in the existing flow
bulkUpdate→ loop per key →updateSingleKey()→executeKeyUpdate()bulkUpdate→groupKeysByUpdateShape()→ loop per group →executeBatchUpdate()Set<Key>intfromexecuteBatch()resultsupdateSingleKey()methodError handling is preserved: failures in one group are logged and skipped; other groups continue (no cross-group atomicity).
Files changed
FlatPostgresCollection.java(+189 / −41) — Core implementation: replaced per-key loop with grouping and JDBC batching. AddedgroupKeysByUpdateShape(),computeUpdateShapeKey(),executeBatchUpdate(), andKeyUpdateGroupinner class. RemovedupdateSingleKey().FlatCollectionWriteTest.java(+118) — New integration testtestBulkUpdateMultipleGroupsComplexOperationsthat exercises 3 distinct update groups across 7 keys:SETon primitive field +APPEND_TO_LISTon arraySETon nested JSONB fieldsADDon numeric field +REMOVE_ALL_FROM_LISTon arrayPerformance Improvements
TBD