Skip to content
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

Optimise deleteByTypeAndClient method #43

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

daveking-tw
Copy link
Collaborator

@daveking-tw daveking-tw commented Apr 29, 2022

❓ Context

On applications with large idempotent_action tables, deleteByTypeAndClient can be optimised by removing the need to sort actions before delete

πŸš€ Changes

  • add index definition for deleteByTypeAndClient queries
  • removed sort in deleteByTypeAndClient queries to let db return/delete records in natural order without the overhead of sorting

Considerations

Actions will no longer be deleted oldest first

@daveking-tw daveking-tw changed the title Tune deleteByTypeAndClient Tune deleteByTypeAndClient method Apr 29, 2022
@daveking-tw daveking-tw changed the title Tune deleteByTypeAndClient method Optimise deleteByTypeAndClient method Apr 29, 2022
@@ -0,0 +1,2 @@
CREATE INDEX IF NOT EXISTS IDX_IDEMPOTENT_ACTION_TYPE_CLIENT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just googling to see if there's a mariadb equivalent of concurrently - looks like adding ALGORITHM=INPLACE LOCK=NONE may do the trick?

@@ -137,7 +137,6 @@ public int[] deleteByIds(List<ActionId> actionIdList) {
"DELETE FROM idempotent_action " +
"WHERE type = :type " +
" AND client = :client " +
"ORDER BY created_at ASC " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a good spot - it's not necessary for this to be deterministic!

Copy link
Contributor

@phildobsontw phildobsontw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! πŸš€

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants