We are using hibernate with oracle (11) and have severe performance problems due to the usage of 'ilike', the case insensitive 'like'.
The java / hibernate code looks like:
c1.add( Restrictions.ilike("address", address) );
which results in a sql statement like
select * from ACCOUNT where lower(ADDRESS_1) = ?
The 'lower' function makes it impossible for oracle to use an index which results in a full table scan.
I was thinking about introducing a new column to the db table that contains the lower case content of address. I could then use :
c1.add( Restrictions.ilike("addressLCase", address.toLowerCase()) );
... but I really don't like the idea to store the content twice...
Then I thought of creating an index with lower case
CREATE INDEX ADDRESS_1_IDX ON ACCOUNT lower( ADDRESS_1 ) ;
but this didn't work, since I cannot convince the optimizer to use this index...
So what can I do to create a fast query with hibernate criteria API and 'ilike' ?
The function based index would be my choice. Just remember:
Excerpt from this article.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With