Improve envers query performance by using new REVEND column
Description
Attachments
- 07 Sep 2010, 01:00 PM
- 07 Sep 2010, 12:02 PM
- 09 Jul 2010, 03:48 PM
Activity
Steve EbersoleMarch 21, 2011 at 7:09 PM
Bulk closing stale resolved issues
AdamASeptember 7, 2010 at 3:53 PM
Great patch - thanks a lot!
The only thing I changed is not to pass the AuditConfiguration object but the individual components, as it was passed not fully initialized, which could have caused weird issues in the future.
This can probably be solved much nicer by using some component/DI system but that's something for the future.
Erik-Berndt ScheperSeptember 7, 2010 at 1:00 PM
Same patch file, but with Unix line endings.
Erik-Berndt ScheperSeptember 7, 2010 at 12:24 PM
And I almost forgot: I have also updated the comments on the updated methods.
Erik-Berndt ScheperSeptember 7, 2010 at 12:20 PM
First of all: great news; thanks for reviewing the initial patch!
I have attached a new patch file which resolves the issues mentioned above.
In order to achieve this, I have changed the following:
1. The org.hibernate.envers.strategy.AuditStrategy interface has been extended with the following methods:
void addEntityAtRevisionRestriction(AuditConfiguration auditCfg, QueryBuilder rootQueryBuilder,
String revisionProperty, String revisionEndProperty, boolean addAlias, MiddleIdData idData,
String revisionPropertyPath, String originalIdPropertyName, String alias1, String alias2);
void addAssociationAtRevisionRestriction(QueryBuilder rootQueryBuilder, String revisionProperty,
String revisionEndProperty, boolean addAlias, MiddleIdData referencingIdData,
String versionsMiddleEntityName, String eeOriginalIdPropertyPath, String revisionPropertyPath,
String originalIdPropertyName, MiddleComponentData... componentDatas);
These have been implemented in the DefaultAuditStrategy and the ValidTimeAuditStrategy using Matthew's code (thanks).
The DefaultAuditStrategy uses subqueries, whereas the ValidTimeAuditStrategy uses the new end-revision column which greatly improves performance.
2. The class org.hibernate.envers.entities.mapper.relation.query.QueryGeneratorTools has been removed.
This code is now implemented in the two AuditStrategy implementations
3. All code-duplicates of the subquery creation / end-revision where clause have been replaced by calls to the AuditStrategy
4. The 'ugly class check' against ValidTimeAuditStrategy has been removed. This required some minor changes in the initial configuration, including AuditConfiguration, EntitiesConfigurator, AuditMetadataGenerator, CollectionMetadataGenerator, QueryGeneratorBuilder.
5. A subquery builder is only created when it is used (in DefaultAuditStrategy).
Hopefully this issue can now be resolved; but as always: further improvements are welcome!
When the ValidTimeAuditStrategy is enabled: <property name="org.hibernate.envers.audit_strategy">org.hibernate.envers.strategy.ValidTimeAuditStrategy</property>, it would be desirable to have the Envers API leverage the useful REVEND columns to avoid slow subselects.