HHH-13521 Avoid excessive validation of enabled filters

This commit is contained in:
Sanne Grinovero 2019-07-29 18:31:20 +01:00 committed by Sanne Grinovero
parent ae176223b2
commit c35bce15f9
5 changed files with 18 additions and 13 deletions

View File

@ -326,7 +326,7 @@ public class CollectionLoadContext {
LOG.debugf( "Caching collection: %s", MessageHelper.collectionInfoString( persister, lce.getCollection(), lce.getKey(), session ) );
}
if ( !session.getLoadQueryInfluencers().getEnabledFilters().isEmpty() && persister.isAffectedByEnabledFilters( session ) ) {
if ( session.getLoadQueryInfluencers().hasEnabledFilters() && persister.isAffectedByEnabledFilters( session ) ) {
// some filters affecting the collection are enabled on the session, so do not do the put into the cache.
if ( LOG.isDebugEnabled() ) {
LOG.debug( "Refusing to add to cache due to enabled filters" );

View File

@ -105,7 +105,7 @@ public class DefaultInitializeCollectionEventListener implements InitializeColle
PersistentCollection collection,
SessionImplementor source) {
if ( !source.getLoadQueryInfluencers().getEnabledFilters().isEmpty()
if ( source.getLoadQueryInfluencers().hasEnabledFilters()
&& persister.isAffectedByEnabledFilters( source ) ) {
LOG.trace( "Disregarding cached version (if any) of collection due to enabled filters" );
return false;

View File

@ -1814,6 +1814,8 @@ public final class SessionImpl
final CollectionPersister roleBeforeFlush = ( entry == null ) ? null : entry.getLoadedPersister();
FilterQueryPlan plan = null;
final Map<String, Filter> enabledFilters = getLoadQueryInfluencers().getEnabledFilters();
final SessionFactoryImplementor factory = getFactory();
if ( roleBeforeFlush == null ) {
// if it was previously unreferenced, we need to flush in order to
// get its state into the database in order to execute query
@ -1823,21 +1825,21 @@ public final class SessionImpl
if ( roleAfterFlush == null ) {
throw new QueryException( "The collection was unreferenced" );
}
plan = getFactory().getQueryPlanCache().getFilterQueryPlan(
plan = factory.getQueryPlanCache().getFilterQueryPlan(
filter,
roleAfterFlush.getRole(),
shallow,
getLoadQueryInfluencers().getEnabledFilters()
enabledFilters
);
}
else {
// otherwise, we only need to flush if there are in-memory changes
// to the queried tables
plan = getFactory().getQueryPlanCache().getFilterQueryPlan(
plan = factory.getQueryPlanCache().getFilterQueryPlan(
filter,
roleBeforeFlush.getRole(),
shallow,
getLoadQueryInfluencers().getEnabledFilters()
enabledFilters
);
if ( autoFlushIfRequired( plan.getQuerySpaces() ) ) {
// might need to run a different filter entirely after the flush
@ -1848,11 +1850,11 @@ public final class SessionImpl
if ( roleAfterFlush == null ) {
throw new QueryException( "The collection was dereferenced" );
}
plan = getFactory().getQueryPlanCache().getFilterQueryPlan(
plan = factory.getQueryPlanCache().getFilterQueryPlan(
filter,
roleAfterFlush.getRole(),
shallow,
getLoadQueryInfluencers().getEnabledFilters()
enabledFilters
);
}
}

View File

@ -18,6 +18,7 @@ import java.util.Set;
import org.hibernate.AssertionFailure;
import org.hibernate.FetchMode;
import org.hibernate.Filter;
import org.hibernate.HibernateException;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
@ -716,7 +717,7 @@ public abstract class AbstractCollectionPersister
if ( subselectInitializer != null ) {
return subselectInitializer;
}
else if ( session.getLoadQueryInfluencers().getEnabledFilters().isEmpty() ) {
else if ( ! session.getLoadQueryInfluencers().hasEnabledFilters() ) {
return initializer;
}
else {
@ -1891,8 +1892,9 @@ public abstract class AbstractCollectionPersister
@Override
public boolean isAffectedByEnabledFilters(SharedSessionContractImplementor session) {
return filterHelper.isAffectedBy( session.getLoadQueryInfluencers().getEnabledFilters() ) ||
( isManyToMany() && manyToManyFilterHelper.isAffectedBy( session.getLoadQueryInfluencers().getEnabledFilters() ) );
final Map<String, Filter> enabledFilters = session.getLoadQueryInfluencers().getEnabledFilters();
return filterHelper.isAffectedBy( enabledFilters ) ||
( isManyToMany() && manyToManyFilterHelper.isAffectedBy( enabledFilters ) );
}
public boolean isSubselectLoadable() {

View File

@ -1363,11 +1363,12 @@ public abstract class AbstractProducedQuery<R> implements QueryImplementor<R> {
entityGraphHintedQueryPlan = null;
}
else {
final SharedSessionContractImplementor producer = getProducer();
entityGraphHintedQueryPlan = new HQLQueryPlan(
hql,
false,
getProducer().getLoadQueryInfluencers().getEnabledFilters(),
getProducer().getFactory(),
producer.getLoadQueryInfluencers().getEnabledFilters(),
producer.getFactory(),
entityGraphQueryHint
);
}