| If you are using a database which has case insensitive string comparisons (for example, MySQL with a collation order whose name ends in "_ci") and your client code calls SimpleExpression.ignoreCase(), currently Hibernate adda an unecessary lower(...) to the SQL generated, which can cause an unnecessary table scan and greatly slow down the query. This could be fixed by changing hibernate-core\src\main\java\org\hibernate\criterion\SimpleExpression.java toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) lines 75-76 from:
final boolean lower = ignoreCase && (sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR ||
sqlTypes[i] == Types.NVARCHAR || sqlTypes[i] == Types.NCHAR);
to:
final boolean lower = ignoreCase && !factory.getDialect().areStringComparisonsCaseInsensitive() &&
(sqlTypes[i] == Types.VARCHAR || sqlTypes[i] == Types.CHAR || sqlTypes[i] == Types.NVARCHAR ||
sqlTypes[i] == Types.NCHAR);
and getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) line 99 from:
final Object casedValue = ignoreCase ? value.toString().toLowerCase(Locale.ROOT) : value;
to:
final Object casedValue = ( ignoreCase &&
!criteriaQuery.getFactory().getDialect().areStringComparisonsCaseInsensitive() ) ?
value.toString().toLowerCase(Locale.ROOT) : value;
|