Issue Type: Improvement Improvement
Affects Versions: 3.6.9
Assignee: Unassigned
Attachments: IncrementGenerator.patch
Components: core
Created: 24/Oct/12 11:31 AM
Description:

the IncrementGenerator uses to following statement to retrieve the highest ID currently in the database:

select max(ids_.ID) from ( select ID from table1 union select ID from table2) as ids_

This is very inefficient, if there are lots of records in the tables (> millions), above select will actually retrieve all IDS and then max them. I have about 1.5 mio records and the query takes almost a minute to execute.

Below query is much faster:

select max(ids_.mx) from ( select max(ID) as mx from table1 union select max(ID) as mx from table2 ) ids_

I attached a patch for the class org.hibernate.id.IncrementGenerator which implements above suggested change.

Andy

Environment: MySql, Windows 7, Quad-Core
Project: Hibernate ORM
Priority: Minor Minor
Reporter: Andy flury
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira