-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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: Faster address query with explicit joins (backport #20537) #20539
Merged
ankush
merged 2 commits into
version-13-hotfix
from
mergify/bp/version-13-hotfix/pr-20537
Mar 31, 2023
Merged
perf: Faster address query with explicit joins (backport #20537) #20539
ankush
merged 2 commits into
version-13-hotfix
from
mergify/bp/version-13-hotfix/pr-20537
Mar 31, 2023
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
This querry is particularly problamatic when there are OR conditions due to shared docs. ```sql ANALYZE SELECT `tabAddress`.name, `tabAddress`.city, `tabAddress`.country FROM `tabAddress` join `tabDynamic Link` on (`tabDynamic Link`.parent = `tabAddress`.name AND `tabDynamic Link`.parenttype = 'Address') WHERE `tabDynamic Link`.link_doctype = 'Customer' AND `tabDynamic Link`.link_name = 'CUSTOMER NAME' AND coalesce(`tabAddress`.disabled, 0) = 0 AND (`tabAddress`.`country` like '%%' OR `tabAddress`.`state` like '%%' OR `tabAddress`.`name` like '%%' OR `tabAddress`.`name` like '%%') AND ((((coalesce(`tabAddress`.`branch`, '')='' OR `tabAddress`.`branch` in ('something'))))) OR (`tabAddress`.name in ('SOME SHARED DOC')) ORDER BY if(locate('', `tabAddress`.name), locate('', `tabAddress`.name), 99999), `tabAddress`.idx DESC, `tabAddress`.name LIMIT 0, 20; ``` **Before:** Never terminates and reads entire table with millions of lines :LOL: **After:** Reads ~100 rows max. ``` *************************** 1. row *************************** id: 1 select_type: SIMPLE table: tabDynamic Link type: index_merge possible_keys: parent,link_doctype_link_name_index,link_name key: link_name,link_doctype_link_name_index,parent key_len: 563,1126,563 ref: NULL rows: 40 r_rows: 79.00 filtered: 100.00 r_filtered: 100.00 Extra: Using union(intersect(link_name,link_doctype_link_name_index),parent); Using where; Using temporary; Using filesort *************************** 2. row *************************** id: 1 select_type: SIMPLE table: tabAddress type: eq_ref possible_keys: PRIMARY,selco_branch key: PRIMARY key_len: 562 ref: _900a733bdc3bb9ed.tabDynamic Link.parent rows: 1 r_rows: 1.00 filtered: 100.00 r_filtered: 100.00 Extra: Using where 2 rows in set (0.001 sec) ``` <!-- Some key notes before you open a PR: 1. Select which branch should this PR be merged in? 2. PR name follows [convention](http://karma-runner.github.io/4.0/dev/git-commit-msg.html) 3. All tests pass locally, UI and Unit tests 4. All business logic and validations must be on the server-side 5. Update necessary Documentation 6. Put `closes #XXXX` in your comment to auto-close the issue that your PR fixes Also, if you're new here - Documentation Guidelines => https://github.com/frappe/erpnext/wiki/Updating-Documentation - Contribution Guide => https://github.com/frappe/frappe/blob/develop/.github/CONTRIBUTING.md - Pull Request Checklist => https://github.com/frappe/erpnext/wiki/Pull-Request-Checklist --> > Please provide enough information so that others can review your pull request: <!-- You can skip this if you're fixing a typo or updating existing documentation --> > Explain the **details** for making this change. What existing problem does the pull request solve? <!-- Example: When "Adding a function to do X", explain why it is necessary to have a way to do X. --> > Screenshots/GIFs <!-- Add images/recordings to better visualize the change: expected/current behviour --> (cherry picked from commit 09e32c3)
(cherry picked from commit fba3497)
586f98d
to
5907622
Compare
frappe-pr-bot
pushed a commit
that referenced
this pull request
Apr 4, 2023
# [13.52.0](v13.51.3...v13.52.0) (2023-04-04) ### Bug Fixes * better error logging while sending email ([#20570](#20570)) ([8ae4d55](8ae4d55)) * cannot restore cancelled document if workflow is active ([6206dc0](6206dc0)) * escape HTML instead of sanitizing ([68ad9cf](68ad9cf)) * fix address query for postgres ([616dd8b](616dd8b)), closes [/github.com//pull/20537#ref-pullrequest-1645575433](https://github.com//github.com/frappe/frappe/pull/20537/issues/ref-pullrequest-1645575433) * get workflow_state_fieldname instead of setting workflow_state to none ([3249aa2](3249aa2)) * removed unnecessary usage of `[@frappe](https://github.com/frappe).whitelist` ([#20503](#20503)) ([#20562](#20562)) ([08398cb](08398cb)) * rewrite query for postgres ([#20557](#20557)) ([#20558](#20558)) ([e400c5f](e400c5f)) ### Features * Disable Sharing globally ([#20318](#20318)) [backport] ([#20500](#20500)) ([758873c](758873c)) * make workflow state translatable ([#20412](#20412)) ([#20501](#20501)) ([1545fbd](1545fbd)) ### Performance Improvements * Faster address query with explicit joins (backport [#20537](#20537)) ([#20539](#20539)) ([955a723](955a723))
🎉 This PR is included in version 13.52.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
This is an automatic backport of pull request #20537 done by Mergify.
Cherry-pick of fba3497 has failed:
To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally
Mergify commands and options
More conditions and actions can be found in the documentation.
You can also trigger Mergify actions by commenting on this pull request:
@Mergifyio refresh
will re-evaluate the rules@Mergifyio rebase
will rebase this PR on its base branch@Mergifyio update
will merge the base branch into this PR@Mergifyio backport <destination>
will backport this PR on<destination>
branchAdditionally, on Mergify dashboard you can:
Finally, you can contact us on https://mergify.com