title: Spring data JPA with SQL Server - lower() function causes full table scan
body: <p>In a simple SpringBoot (2.0.5) + JPA + SQL Server microservice with persistence via a <code>JpaRepository</code> implementation (no additional methods), we are seeing the transact-sql <code>lower()</code> function being injected into the generated SQL wrapping the queried column(s), which in turn causes a <strong>full table scan</strong> and therefore impacts performance on what would otherwise be a simple, fast index-supported query.</p>
  
  <p>Clearly this is to make the queries case-insensitive, however as SQL Server is case-insensitive by default there is no need for this function to be injected.  I can see from the Spring Data JPA docs that suffixing repository methods with <code>IgnoreCase</code> should make queries case-insensitive for DBs that are case-sensitive by default, however I can't see how to configure it to respect the incoming case..</p>
  
  <p>JPA config:</p>
  
  <pre><code>jpa:
    show-sql: true
    hibernate:
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
      dialect: org.hibernate.dialect.SQLServer2012Dialect
      ddl-auto: validate
  </code></pre>
  
  <p>Repository interface:</p>
  
  <pre><code>@Repository
  public interface MyRepo extends JpaRepository&lt;Thing, Long&gt;, QuerydslPredicateExecutor&lt;Thing&gt; {}
  </code></pre>
  
  <p>I have tried removing the <code>SQLServer2012Dialect</code> from the config - no difference.  I am unsure if the additional use of QueryDSL might be having an impact - I shall try temporarily removing that (although it is required).</p>