8000 HHH-18818 Fix ID conflicts between CTE batch inserts and optimizer strategies by stringintech · Pull Request #9232 · hibernate/hibernate-orm · GitHub
[go: up one dir, main page]

Skip to content

HHH-18818 Fix ID conflicts between CTE batch inserts and optimizer strategies #9232

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

stringintech
Copy link
Contributor
@stringintech stringintech commented Nov 10, 2024

This PR resolves an ID conflict in Hibernate's CteInsertHandler batch insert implementation when using sequence-based ID generation with the PooledOptimizer. The issue arises from a misalignment between the batch insert ID generation strategy and the PooledOptimizer strategy, which can lead to ID conflicts.

The fix ensures that CteInsertHandler correctly integrates with the PooledOptimizer's ID allocation strategy by properly handling the next database-generated sequence value as the "hi" value, thereby maintaining consistent ID allocation across all insert operations.

A unit test (CteInsertStrategyWithPooledOptimizerTest) is included to validate the fix.


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-18818

@beikov
Copy link
Member
beikov commented Dec 27, 2024

Thanks a lot for the test and fix. I just now realized that other optimizer strategies might also run into this problem.
I think it would be best to extend Optimizer to allow generating the AST for the low/base value, since e.g. the HiLoOptimizer has a completely different approach that isn't as simple as conditionally subtracting the increment.

Would you be willing to implement that and also add tests for the other optimizers?

Expression createLowValueExpression(Expression databaseValue, SessionFactoryImplementor sessionFactory);

@stringintech
Copy link
Contributor Author

@beikov Thanks for the feedback. I'd be happy to do it. I'll go over the different optimizer strategies, and I'll reach out if I have any questions during implementation.

@stringintech stringintech changed the title HHH-18818 Fix ID 8000 conflicts between CTE batch inserts and PooledOptimizer sequence allocation HHH-18818 Fix ID conflicts between CTE batch inserts and optimizer strategies Jan 1, 2025
@stringintech
Copy link
Contributor Author

@beikov I've implemented the requested createLowValueExpression() method in the Optimizer interface, along with corresponding tests for proper ID allocation behavior across optimizer strategies. I'd appreciate your review and am ready to make adjustments based on your feedback.

@yrodiere
Copy link
Member

Hey @beikov, it seems this is waiting for your feedback?

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
0