JAMES-2586 Optimize some postgres query #1984
Merged
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.
The query to increase the current value of the quota is frequently executed. The current SQL query is as follows:
This query is verbose and incurs overhead due to constraint checking.
=> The reality is the INSERT statement should be executed only once during initialization, and subsequent operations should use the UPDATE statement.
=> James can handle the INSERT and UPDATE cases appropriately.
The query searches for
mailbox.mailbox_name
usingLIKE
: :james-project/mailbox/postgres/src/main/java/org/apache/james/mailbox/postgres/mail/dao/PostgresMailboxDAO.java
Line 186 in 542e495
Although the mailbox table already has an index for the trio
(MAILBOX_NAME, USER_NAME, MAILBOX_NAMESPACE)
, theLIKE "prefix%"
query slows it down.=> Create one more index for the composite
(USER_NAME, MAILBOX_NAMESPACE)
result:
before
after