HHH-13521 Avoid excessive validation of enabled filters
This commit is contained in:
parent
ef242b283a
commit
98ee32415d
|
@ -319,7 +319,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 ( debugEnabled ) {
|
||||
LOG.debug( "Refusing to add to cache due to enabled filters" );
|
||||
|
|
|
@ -103,7 +103,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;
|
||||
|
|
|
@ -1794,6 +1794,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
|
||||
|
@ -1803,21 +1805,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
|
||||
|
@ -1828,11 +1830,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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -701,7 +702,7 @@ public abstract class AbstractCollectionPersister
|
|||
if ( subselectInitializer != null ) {
|
||||
return subselectInitializer;
|
||||
}
|
||||
else if ( session.getLoadQueryInfluencers().getEnabledFilters().isEmpty() ) {
|
||||
else if ( ! session.getLoadQueryInfluencers().hasEnabledFilters() ) {
|
||||
return initializer;
|
||||
}
|
||||
else {
|
||||
|
@ -1877,8 +1878,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() {
|
||||
|
|
|
@ -1343,11 +1343,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
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue