Skip to content

Conversation

ghgh415263
Copy link
Contributor

Issue link: #1978

Add deleteAllByQuery method to JdbcAggregateOperations

This method enables deleting aggregates based on a query by performing the following steps:

  1. Select root IDs matching the query with a SELECT ... FOR UPDATE to lock the rows.
  2. Delete all sub-entities associated with the selected root IDs.
  3. Delete the root entities identified by the selected IDs.

see
#1978

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 12, 2025
@ghgh415263
Copy link
Contributor Author

I’ve opened a draft PR for #1978. If you have any suggestions for improvement or spot any issues, I’d be glad to make the necessary changes. Thank you for reviewing it!

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 14, 2025
Copy link
Contributor

@schauder schauder left a comment

Choose a reason for hiding this comment

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

Most of this looks pretty good.
I have on major concern though: We should not transfer the ids from the locking select to the client and use it for follow up deletes.

Instead the locking select should execute on the server only, and the delete operations should be based on the query directly.

The reason for this that this operation is very attractive for large amounts of data. In such cases transporting and converting the ids creates serious load on network and memory.

And if someone prefers to select the ids first and then delete based on these ids they can still do that using multiple methods.

@ghgh415263
Copy link
Contributor Author

Thanks for review

i Changed the steps as follows:

  1. Lock the target rows using SELECT ... FOR UPDATE based on the query conditions.
  2. Delete sub-entities by leveraging a subquery that selects the matching root rows.
  3. Delete the root entities using the query conditions.

@ghgh415263 ghgh415263 requested a review from schauder July 17, 2025 07:26
@ghgh415263
Copy link
Contributor Author

Hello

It looks like other commits were merged and now my previous PR has a conflict. Should I resolve it and push again?. and I can also make any improvements to my PR.

@schauder
Copy link
Contributor

Hello

It looks like other commits were merged and now my previous PR has a conflict. Should I resolve it and push again?. and I can also make any improvements to my PR.

That would be awesome

Issue link: spring-projects#1978

Add deleteAllByQuery method to JdbcAggregateOperations

This method enables deleting aggregates based on a query by performing the following steps:
1. Lock the target rows using SELECT ... FOR UPDATE based on the query conditions.
2. Delete sub-entities by leveraging a subquery that selects the matching root rows.
3. Delete the root entities using the query conditions.

But if the query has no criteria, deletion is performed in the same way as deleteAll method of JdbcAggregateOperations

Signed-off-by: JaeYeon Kim <[email protected]>
@ghgh415263
Copy link
Contributor Author

hello !
I’ve resolved the conflicts and made some minor adjustments before pushing again.

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

Successfully merging this pull request may close these issues.

4 participants