query-hints

Experience with when to use OPTIMIZE FOR UNKNOWN

别说谁变了你拦得住时间么 提交于 2020-01-21 10:08:17
问题 I have read the theory and views behind SQL Server 2008's "OPTIMIZE FOR UNKNOWN" query plan option. I understand what it does well enough. I did some limited experiments and found that with a warm cache, it only was of benefit on > 100k rows. However, this was on a simple table and query with no joins, filtering, etc. On a cold cache, the picture would undoubtedly be much more in its favor. I don't currently have a production system to bench the before/after. So I am curious if anyone has

How can I use the READPAST hint in NHibernate?

蹲街弑〆低调 提交于 2019-12-24 03:16:31
问题 Is there any way I can get NHibernate to use the READPAST hint when selecting data from SQL Server? 回答1: Option #1 Easy way: SQL query Session.CreateSQLQuery("select * from YourEntityTable with (readpast) where SomeColumn = :col") .AddEntity(typeof(YourEntity)) .SetString("col", value) .UniqueResult<YourEntity>(); Option #2 Requires more work: If you're not using one of NHibernate.LockMode you can override dialect's AppendLockHint() to something like: public override string AppendLockHint

SQL Server : the maximum recursion 100 has been exhausted before statement completion

我的未来我决定 提交于 2019-12-11 01:48:01
问题 I have a query that is returning an error with the maximum levels of recursion exceeded. I know how to fix this by adding OPTION (maxrecursion 0) to the query however, I have tried adding this at various places in the query and I cant find where to put it where the syntax is valid. Can anyone give me any pointers as to where in my view the query hint needs to be inserted? /****** Object: View [dbo].[SiconCFMContractLinesDetailByDayView] Script Date: 16/12/2016 12:02:35 ******/ SET ANSI_NULLS

How to use the NOEXPAND hint with Linq to SQL?

和自甴很熟 提交于 2019-12-05 07:19:53
I have an indexed view that I need to specify the noexpand hint for in order for it to perform reasonably. Unfortunately as seen with regard to modifying the Linq to SQL generated T-SQL query from the NOLOCK hint it appears that there is no easy way to take advantage of these hints directly or is there? My thought is that it would make sense to allow customization of this stuff through the use of attributes or declaratively through the dbml. Also since Linq to SQL seems to only work targeting SQL Server it only makes sense that we are also able to leverage these advanced features (if they

Should I use Query Hint Fast number_rows / FASTFIRSTROW?

余生长醉 提交于 2019-12-01 16:28:18
问题 I was reading over the documentation for query hints: http://msdn.microsoft.com/en-us/library/ms181714(SQL.90).aspx And noticed this: FAST number_rows Specifies that the query is optimized for fast retrieval of the first number_rows. This is a nonnegative integer. After the first number_rows are returned, the query continues execution and produces its full result set. So when I'm doing a query like: Select Name from Students where ID = 444 Should I bother with a hint like this? Assuming SQL

Stored procedures and OPTIMIZE FOR UNKNOWN

こ雲淡風輕ζ 提交于 2019-11-30 10:23:02
I've read up on the SQL Server 2008 OPTIMIZE FOR UNKNOWN query hint. I understand how it works. However, I have a question on where and when to use it. It cannot be specified inside a UDF. It can be specified inside a stored proc. However, this MSDN blog post states the following: 4.Moving a query into a stored procedure can put it into a separate procedural context and can be a good way to get that value visible to the optimizer (Note: this works in SQL 2000 as well) That seems to me to be saying that any parameter passed to a stored proc will be "sniffed", thereby helping SQL Server to

SELECT TOP is slow, regardless of ORDER BY

[亡魂溺海] 提交于 2019-11-29 16:23:52
问题 I have a fairly complex query in SQL Server running against a view, in the form: SELECT * FROM myview, foo, bar WHERE shared=1 AND [joins and other stuff] ORDER BY sortcode; The query plan as shown above shows a Sort operation just before the final SELECT , which is what I would expect. There are only 35 matching records, and the query takes well under 2 seconds. But if I add TOP 30 , the query takes almost 3 minutes! Using SET ROWCOUNT is just as slow. Looking at the query plan, it now

Stored procedures and OPTIMIZE FOR UNKNOWN

走远了吗. 提交于 2019-11-29 15:36:32
问题 I've read up on the SQL Server 2008 OPTIMIZE FOR UNKNOWN query hint. I understand how it works. However, I have a question on where and when to use it. It cannot be specified inside a UDF. It can be specified inside a stored proc. However, this MSDN blog post states the following: 4.Moving a query into a stored procedure can put it into a separate procedural context and can be a good way to get that value visible to the optimizer (Note: this works in SQL 2000 as well) That seems to me to be

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