I've digged a little further and came to the following surprising fact. When I hard-code the named parameters as follows:
Code:
ISQLQuery query = session.CreateSQLQuery( "SELECT CODE_PART FROM COMPOSITION " +
"WHERE CODE_PART LIKE '<T><U>%</U><I>ERI0011WTF</I><T>' " +
"CONNECT BY PRIOR CODE_PART = CODE_COMPOSITE " +
"START WITH CODE_COMPOSITE = '<U>ERI0008WTF</U>'" );
query.AddScalar( "CODE_PART", NHibernateUtil.String );
string returnValue = query.UniqueResult<string>();
The response time drops to a very comfortable 0.3 seconds.
It confuses me and our dbas to no end. This is what the log tells me when running WITH named parameters:
Code:
2007-06-13 12:32:08,418 [9 ] DEBUG NHibernate.Impl.SessionFactoryImpl - Instantiated session factory
2007-06-13 12:32:08,434 [9 ] DEBUG NHibernate.Impl.SessionImpl - opened session
2007-06-13 12:32:08,449 [9 ] DEBUG NHibernate.Loader.Custom.SQLCustomQuery - starting processing of sql query [SELECT CODE_PART FROM COMPOSITION WHERE CODE_PART LIKE :part CONNECT BY PRIOR CODE_PART = CODE_COMPOSITE START WITH CODE_COMPOSITE = :root]
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - flushing session
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - Flushing entities and processing referenced collections
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - Processing unreferenced collections
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - scheduling collection removes/(re)creates/updates
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - Flushed: 0 insertions, 0 updates, 0 deletions to 0 objects
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
2007-06-13 12:32:08,465 [9 ] DEBUG NHibernate.Impl.SessionImpl - dont need to execute flush
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Impl.BatcherImpl - Opened new IDbCommand, open IDbCommands: 1
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Impl.BatcherImpl - Building an IDbCommand object for the SqlString: SELECT CODE_PART FROM COMPOSITION WHERE CODE_PART LIKE ? CONNECT BY PRIOR CODE_PART = CODE_COMPOSITE START WITH CODE_COMPOSITE = ?
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Loader.Loader - BindNamedParameters() <U>ERI0008WTF</U> -> root [1]
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Type.StringType - binding '<U>ERI0008WTF</U>' to parameter: 1
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Loader.Loader - BindNamedParameters() <T><U>%</U><I>ERI0011WTF</I><T> -> part [0]
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Type.StringType - binding '<T><U>%</U><I>ERI0011WTF</I><T>' to parameter: 0
2007-06-13 12:32:08,480 [9 ] INFO NHibernate.Loader.Loader - SELECT CODE_PART FROM COMPOSITION WHERE CODE_PART LIKE :p0 CONNECT BY PRIOR CODE_PART = CODE_COMPOSITE START WITH CODE_COMPOSITE = :p1
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.SQL - SELECT CODE_PART FROM COMPOSITION WHERE CODE_PART LIKE :p0 CONNECT BY PRIOR CODE_PART = CODE_COMPOSITE START WITH CODE_COMPOSITE = :p1; :p0 = '<T><U>%</U><I>ERI0011WTF</I><T>', :p1 = '<U>ERI0008WTF</U>'
2007-06-13 12:32:08,480 [9 ] DEBUG NHibernate.Connection.DriverConnectionProvider - Obtaining IDbConnection from Driver
2007-06-13 12:32:08,605 [9 ] DEBUG NHibernate.Impl.BatcherImpl - Opened IDataReader, open IDataReaders: 1
2007-06-13 12:32:08,605 [9 ] DEBUG NHibernate.Loader.Loader - processing result set
2007-06-13 12:32:12,965 [9 ] DEBUG NHibernate.Loader.Loader - result set row: 0
2007-06-13 12:32:12,965 [9 ] DEBUG NHibernate.Loader.Loader - result row:
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Type.StringType - returning '<T><U>ERI0010WTF</U><I>ERI0011WTF</I><T>' as column: CODE_PART
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Loader.Loader - done processing result set (1 rows)
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.BatcherImpl - Closed IDataReader, open IDataReaders :0
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.BatcherImpl - Closed IDbCommand, open IDbCommands: 0
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.ConnectionManager - aggressively releasing database connection
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Connection.ConnectionProvider - Closing connection
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.SessionImpl - initializing non-lazy collections
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.ConnectionManager - after autocommit
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.ConnectionManager - aggressively releasing database connection
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.SessionImpl - transaction completion
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.SessionImpl - closing session
2007-06-13 12:32:12,980 [9 ] DEBUG NHibernate.Impl.BatcherImpl - running BatcherImpl.Dispose(true)