Add hql execution to Statistics

This commit is contained in:
Andrea Boriero 2021-09-24 18:23:51 +02:00
parent e62b3710a8
commit d43b9940b9
5 changed files with 17 additions and 15 deletions

View File

@ -102,11 +102,6 @@ public class QueryOptionsImpl implements MutableQueryOptions, AppliedGraph {
return limit;
}
@Override
public boolean hasQueryExecutionToBeAddedToStatistics() {
return true;
}
@Override
public LockOptions getLockOptions() {
return lockOptions;

View File

@ -161,15 +161,6 @@ public interface QueryOptions {
return explicit != null ? explicit : Limit.NONE;
}
/**
* Determine if the query execution has to be considered by the {@link org.hibernate.stat.Statistics}.
*
* @return true if the query execution has to be added to the {@link org.hibernate.stat.Statistics}, false otherwise.
*/
default boolean hasQueryExecutionToBeAddedToStatistics() {
return false;
}
/**
* Did the application explicitly request paging limits?
*

View File

@ -858,4 +858,10 @@ public class QuerySqmImpl<R>
getHints()
);
}
@Override
public boolean hasQueryExecutionToBeAddedToStatistics() {
return !CRITERIA_HQL_STRING.equals( hqlString );
}
}

View File

@ -184,7 +184,7 @@ public class JdbcSelectExecutorStandardImpl implements JdbcSelectExecutor {
final boolean stats;
long startTime = 0;
final StatisticsImplementor statistics = executionContext.getSession().getFactory().getStatistics();
if ( executionContext.getQueryOptions().hasQueryExecutionToBeAddedToStatistics()
if ( executionContext.hasQueryExecutionToBeAddedToStatistics()
&& jdbcValues instanceof JdbcValuesResultSetImpl ) {
stats = statistics.isStatisticsEnabled();
if ( stats ) {

View File

@ -74,4 +74,14 @@ public interface ExecutionContext {
default void afterStatement(LogicalConnectionImplementor logicalConnection) {
logicalConnection.afterStatement();
}
/**
* Determine if the query execution has to be considered by the {@link org.hibernate.stat.Statistics}.
*
* @return true if the query execution has to be added to the {@link org.hibernate.stat.Statistics}, false otherwise.
*/
default boolean hasQueryExecutionToBeAddedToStatistics() {
return false;
}
}