parameter-sniffing

How do I control parameter sniffing and/or query hints in entity framework?

馋奶兔 提交于 2019-11-28 13:32:17
Update: I've created a suggestion to implement hint control in a future version of EF. Go here to vote for it. I have a problem where one of my Entity Framework (EF) queries is taking a very long time to execute in Sql Server, although when I copy-and-paste the generated TSQL into Sql Server Management Studio (SSMS) it runs extremely fast. After some investigation I found that I was experiencing a parameter sniffing issue, and the correct way to fix it is to insert one of many query hints (OPTIMIZE FOR, RECOMPILE, and so on). How do I insert these hints into my EF queries? Related questions

How do I control parameter sniffing and/or query hints in entity framework?

不想你离开。 提交于 2019-11-27 07:54:23
问题 Update: I've created a suggestion to implement hint control in a future version of EF. Go here to vote for it. I have a problem where one of my Entity Framework (EF) queries is taking a very long time to execute in Sql Server, although when I copy-and-paste the generated TSQL into Sql Server Management Studio (SSMS) it runs extremely fast. After some investigation I found that I was experiencing a parameter sniffing issue, and the correct way to fix it is to insert one of many query hints

SQL poor stored procedure execution plan performance - parameter sniffing

女生的网名这么多〃 提交于 2019-11-27 01:38:28
I have a stored procedure that accepts a date input that is later set to the current date if no value is passed in: CREATE PROCEDURE MyProc @MyDate DATETIME = NULL AS IF @MyDate IS NULL SET @MyDate = CURRENT_TIMESTAMP -- Do Something using @MyDate I'm having problems whereby if @MyDate is passed in as NULL when the stored procedure is first compiled, the performance is always terrible for all input values ( NULL or otherwise), wheras if a date / the current date is passed in when the stored procedure is compiled performance is fine for all input values ( NULL or otherwise). What is also

SQL Server - parameter sniffing

纵然是瞬间 提交于 2019-11-26 22:53:09
I've read many articles about parameter sniffing, but it's not clear if this is good or bad. Can anyone explain this with a simple example. Is there a way to automatically detect that wrong plan was assigned to a specific statement? Thanks in advance. It is good but can be bad sometimes. Parameter sniffing is about the query optimizer using the value of the provided parameter to figure out the best query plan possible. One of many choices and one that is pretty easy to understand is if the entire table should be scanned to get the values or if it will be faster using index seeks. If the value

Entity Framework 4.2 exec sp_executesql does not use indexes (parameter sniffing)

只谈情不闲聊 提交于 2019-11-26 22:50:27
I'm encountering some major performance problems with simple SQL queries generated by the Entity Framework (4.2) running against SQL Server 2008 R2. In some situations (but not all), EF uses the following syntax: exec sp_executesql 'DYNAMIC-SQL-QUERY-HERE', @param1... In other situations is simply executes the raw SQL with the provided parameters baked into the query. The problem I'm encountering is that queries executed with the sp_executesql are ignoring all indexes on my target tables, resulting in an extremely poor performing query (confirmed by examining the execution plan in SSMS). After

SQL poor stored procedure execution plan performance - parameter sniffing

独自空忆成欢 提交于 2019-11-26 09:44:55
问题 I have a stored procedure that accepts a date input that is later set to the current date if no value is passed in: CREATE PROCEDURE MyProc @MyDate DATETIME = NULL AS IF @MyDate IS NULL SET @MyDate = CURRENT_TIMESTAMP -- Do Something using @MyDate I\'m having problems whereby if @MyDate is passed in as NULL when the stored procedure is first compiled, the performance is always terrible for all input values ( NULL or otherwise), wheras if a date / the current date is passed in when the stored

SQL Server - parameter sniffing

╄→гoц情女王★ 提交于 2019-11-26 08:27:48
问题 I\'ve read many articles about parameter sniffing, but it\'s not clear if this is good or bad. Can anyone explain this with a simple example. Is there a way to automatically detect that wrong plan was assigned to a specific statement? Thanks in advance. 回答1: It is good but can be bad sometimes. Parameter sniffing is about the query optimizer using the value of the provided parameter to figure out the best query plan possible. One of many choices and one that is pretty easy to understand is if

Entity Framework 4.2 exec sp_executesql does not use indexes (parameter sniffing)

自古美人都是妖i 提交于 2019-11-26 08:27:17
问题 I\'m encountering some major performance problems with simple SQL queries generated by the Entity Framework (4.2) running against SQL Server 2008 R2. In some situations (but not all), EF uses the following syntax: exec sp_executesql \'DYNAMIC-SQL-QUERY-HERE\', @param1... In other situations is simply executes the raw SQL with the provided parameters baked into the query. The problem I\'m encountering is that queries executed with the sp_executesql are ignoring all indexes on my target tables,