Our application issues an SQL query generated by NHibernate. At runtime, the application takes about 12 seconds to work with the SQL Server database. SQL Profiler shows over 500,000 views.
However, if I commit the query text using SQL Profiler and run it again from SQL Studio, it takes 5 seconds and displays less than 4600 records.
The query uses several parameters, the values ββof which are given at the end of the SQL text, and I read a little about sniffing parameters and inefficient query plans, but I thought that this was related to stored procedures. Perhaps NHibernate maintains open results when it creates instances of its entities, which can explain the longer duration, but what can explain the additional 494,000 βreadsβ for the same query as NHibernate? (No additional queries are displayed in the SQL Profiler trace.)
The query is defined as a LINQ query using the NHibernate 3.1 LINQ tool. I did not include the query itself, because it seems like a basic philosophical question: what can explain such a dramatic difference?
In case this is appropriate, the varbinary (max) column is also present in the results, but in our situation it always contains null.
Any insight is greatly appreciated!
source share