Skip to content

HHH-19498 - improve upserts on MySQL and Maria #10275

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jrenaat
Copy link
Member

@jrenaat jrenaat commented Jun 3, 2025


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.


https://hibernate.atlassian.net/browse/HHH-19498

@jrenaat jrenaat changed the title HHH-19498 - improve upserts on MySQL and Maria HHH-19498 - improve upserts on MySQL and Maria - WIP Jun 3, 2025
@jrenaat jrenaat force-pushed the HHH-19498_mysqlupsertimprovement branch 2 times, most recently from 918613e to 4a39789 Compare June 18, 2025 18:41
@jrenaat jrenaat force-pushed the HHH-19498_mysqlupsertimprovement branch 3 times, most recently from 517ce5f to 8c07fc9 Compare June 20, 2025 18:02
@jrenaat jrenaat marked this pull request as ready for review June 20, 2025 19:39
@jrenaat jrenaat requested a review from gavinking June 20, 2025 19:39
@jrenaat jrenaat changed the title HHH-19498 - improve upserts on MySQL and Maria - WIP HHH-19498 - improve upserts on MySQL and Maria Jun 20, 2025
private void renderVersionRestriction(String tableName, List<ColumnValueBinding> optimisticLockBindings, int index) {
final String operator = index == 0 ? ":=" : "";
final String versionVariable = "@oldversion" + operator;
for (int i = 0; i < optimisticLockBindings.size(); i++) {
Copy link
Member

Choose a reason for hiding this comment

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

The way this written now you must assert optimisticLockBindings.size() == 1

Copy link
Member Author

@jrenaat jrenaat Jun 27, 2025

Choose a reason for hiding this comment

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

Yes, I know, I left that pending.
There is however a bigger problem with this issue, in that we don't seem to have a way to distinguish a new insert (returned rowcount == 1), from a potential stale upsert (rowcount is 1 as well), which is why I invalidated that test.
Said test shouldn't have been invalidated however, as Gavin pointed out, since knowing that a stale upsert was attempted is important.

@gavinking
Copy link
Member

I think what we need to do here is fall back to the "dumb" approach (with an update then an insert) in the case that we have a version number.

We can still use this new strategy when there is no version to check.

Signed-off-by: Jan Schatteman <jschatte@redhat.com>
@jrenaat jrenaat force-pushed the HHH-19498_mysqlupsertimprovement branch from 8c07fc9 to 9ad84bd Compare June 27, 2025 22:08
return customExpectation;
}

private class MySQLRowCountExpectation implements Expectation {

Check notice

Code scanning / CodeQL

Inner class could be static Note

MySQLRowCountExpectation should be made static, since the enclosing instance is not used.
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