Skip to content

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?

"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.

3 participants