In web-app hibernate criteria taking too long against oracle db. I enable the log4j.logger.org.hibernate.SQL=debug SQL and run the sql query with same bind variable in sql plus the result is instance. Enabling hibernate logging and going through the logs. What cause hibernate to take too long rub a query? Any suggestions?
Update 1:
It appears that oracle use different execution plan when i run through the SQLPlus the same query which hibernate generates. SQL Query From Hibernate:
select count(*) as y0_ from SUMMARY_VIEW this_ where this_.ser_id like :1 and this_.TYPE=:2 and this_.TIME_LOCAL>=:3 and this_.TIME_LOCAL<=:4
SQL Query Run on SQLPlus:
select count(*) as y0_ from SUMMARY_VIEW this_ where this_.ser_id like :ser_id and this_.TYPE=:type and this_.TIME_LOCAL>=:startdate and this_.TIME_LOCAL<=:enddate
Update 2: Further Investigation reveled that that startdate and endate bind variable passed as varchar2 from sqlplus but these passed as timestamp from app ( :) ). Due to this execution plans are different.
select sql_text, v.sql_id, name, value_string, datatype_string from v$sql_bind_capture vbc join v$sql v using (hash_value) where v.sql_id in (?)
Does bind variable type affect execution plan? if so, Is there any other tools to pass date variable as a bind parameter to query?
Update 3: The performance issue due to incompatible data types. It appears that column data type(DATE) and hibernate data type(TIMESTAMP) mismatch causes implicit data type conversion. Oracle uses INTERNAL_FUNCTION to transfer date column to match the passed bind variable hibernate data type TimeStamp.
Similar issues :
Non-negligible execution plan difference with Oracle when using jdbc Timestamp or Date
Why is Oracle so slow when I pass a java.sql.Timestamp for a DATE column?