Improve consent deletion when a realm is removed #31071
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.
Closes #30992
The PR adds an index in table
USER_CONSENT_CLIENT_SCOPEto improve performance of deleting consents consents when a client scope (or the full realm) is removed. We also need the mariadb/mysql trick to avoid sub-queries (issue https://jira.mariadb.org/browse/MDEV-21012). There are a lot of delete queries with this format, so we can be affected by this in other places. The HHH-14796 issue was fixed long ago so I also improved the custom queries to just define the specific ones. Now the queries are defined via annotations in code normally but they can be overridden in the db properties file.I create several realms to a total of 0.5M consents in
USER_CONSENT_CLIENT_SCOPE. 100K inUSER_CONSENT. And removing a new realm was improved from 8.18s to 0.8s. With an empty database the deletion time is around 0.4s. So we are reducing times by ten. As commented we have more queries (delete ones mainly) that follow the same subquery sntax (mainly they cannot be rewritten because its how hibernate constructs them when there is a join in the delete statement).Finally it was decided to include the index in 18.x for backports. Release notes created for 25.0.2. If we don't reach that release I will move to the next version.
@ahus1 FYI.