New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: Perform db.set_value
with single query only
#18305
Merged
Merged
Conversation
This file contains 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
ankush
changed the title
perf: single query
perf: Perform Oct 6, 2022
db.set_value
db.set_value
with single query only
- Only delete a single doc if we know which doc changed - Drop all docs other wise (kinda bad, but this isn't used frequently, will fix when visiting entire caching system again)
ankush
force-pushed
the
set_value_simple
branch
from
October 6, 2022 13:10
7fe4c59
to
6436e67
Compare
...will delay backport by a week or so. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## develop #18305 +/- ##
===========================================
- Coverage 62.72% 62.55% -0.18%
===========================================
Files 746 746
Lines 67307 67709 +402
Branches 5966 5966
===========================================
+ Hits 42218 42354 +136
- Misses 21587 21853 +266
Partials 3502 3502
Flags with carried forward coverage won't be shown. Click here to find out more. |
ankush
added a commit
that referenced
this pull request
Oct 11, 2022
…#18349) * perf: single query `db.set_value` (cherry picked from commit cee2b50) * fix: better cache validation - Only delete a single doc if we know which doc changed - Drop all docs other wise (kinda bad, but this isn't used frequently, will fix when visiting entire caching system again) (cherry picked from commit bfa6a5f) Co-authored-by: Ankush Menat <ankush@frappe.io>
frappe-pr-bot
pushed a commit
that referenced
this pull request
Oct 18, 2022
# [14.12.0](v14.11.1...v14.12.0) (2022-10-18) ### Bug Fixes * add flags to set_permission for docshares ([#18416](#18416)) ([#18429](#18429)) ([a2ba0aa](a2ba0aa)) * correct import for markupsafe.escape ([c2f1c57](c2f1c57)) * **dx:** resolve_class ([#18417](#18417)) ([#18421](#18421)) ([c47de0d](c47de0d)) * explicitly set doctype in queries ([#18403](#18403)) ([#18405](#18405)) ([6848ee9](6848ee9)) * format currency value as float while grid upload ([5eb803c](5eb803c)) * google calendar sync times ([#18384](#18384)) ([#18394](#18394)) ([7c9ee6d](7c9ee6d)) * Notifications. Get Alerts for Today button [#18423](#18423) ([#18428](#18428)) ([63e3c61](63e3c61)) * progress bar not disappearing ([#18375](#18375)) ([#18392](#18392)) ([e0d6d0b](e0d6d0b)) * reshuffle __newname field to accommodate under 1st Tab Break ([#18406](#18406)) ([#18427](#18427)) ([f833e5d](f833e5d)) * Show error page even when routing fails ([#18437](#18437)) ([#18438](#18438)) ([5d3e97a](5d3e97a)) * **UI:** child table custom horizontal scroll ([ec09123](ec09123)) * **UI:** Child table responsive ([cb866f9](cb866f9)) * **UI:** consider 2px border at grid end ([c85fb2d](c85fb2d)) * **UI:** lesser margin if cell is focused ([f3ad63a](f3ad63a)) ### Features * allow syncing new fields in Doctype Layout ([#18408](#18408)) ([c73e2e2](c73e2e2)) * search in translated title, if we show title ([#17828](#17828)) ([#18395](#18395)) ([73758d7](73758d7)) ### Performance Improvements * Perform `db.set_value` with single query only (backport [#18305](#18305)) ([#18349](#18349)) ([23caa1f](23caa1f))
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Concludes #15560 by making all set_value calls to non-single doctypes run with 1 query only.
Explanation:
Previously we were fetching all the primary keys which need to be updated and then updating separately.
Before:
After:
QB can already do single update query without much fuss. The last reason for keeping this appears to be
for update
which locks the rows before updating them.Why remove
for_update
completely?This was added to make sure that N+1 queries that happen don't cause inconsistencies during the time queries are ran. Now that set_value is 1-1 translated to single
UPDATE
query there's no point in locking rows before updating them.UPDATE
locks rows automatically.Before:
1.02 ms ± 166 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
After:
530 µs ± 144 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)
Roughly 2x faster. This will be much better on queries that end up affecting more than 1 row.
TODO:
evict only doctype(deferred, needs design change in cache keys)ERPNext CI: https://github.com/frappe/erpnext/actions/runs/3197465411 ✅