sql server - How to avoid sorting results, returned by Index Seek? -


Well, the question is not really "to avoid taxonomy" as it is necessary for business logic, but how to Do not use the initial index, and on the go.

I have a query plan:

  | - Sort (Top 5, Order By: ([This _]. [DateAdded] DESC). --Nested Loops (Join Inner, External References: ([this _] [id], [Expr1002]) Customized with unordered prefetch. --Index research (object: .. ([storm] [dbo ..] [item] [IX_Items_ByLocationSorted] as [this_]), looking: ([this _] [condition] = (1.) and [this _] [RegionId] = (32) and [this _] [LocationId] = .. (32001)), where: [[storm] [dbo] [item] [SubcategoryTypeId] as [this _] [SubcategoryTypeId] = (88 ....) and ([storm] [dbo] [item] [......... IsHidden] as [this _] [IsHidden] & lt; (1) or [storm] [Dbo] [Item] [IsHidden] as ordered [this _] [IsHidden]> (1))) forward | - Search the clustered index (object: [[storm] [dbo] [item] [PK_Items] as [this_]), search: ... ([this _] [id] = [hurricane] [dbo] [... items]. [ID] [ID_]. [ID]) Lookup order forward)   

You can see that a set of index seek operation lines Returns a key lookup to retrieve the entire line in comparison to the query optimizer (because it must be returned anyway), and the column associated with the date column Doors to all rows. This is a clear and absolutely legitimate practice. But it is really slow (depending on up to 40 seconds), depending on the number of rows returning from index seek (30 max maximum).

PS: This query table has approximately 3 million lines, and has been updated frequently. This page may be due to locking, but I do not think those locks can last 40 seconds

query:. Select

  from Top 5 * items where SubcategoryTypeId = 88 and regionId = 32 and locationID = 32001 and no (IsHidden = 1 and status = 1) Order date date    

Depending on your description and how the SQL Server handles the index, no.

Sorting is an essential step, and there is no "intuitive" order for SQL Server data, is but sorted based on the construction script for the indexed data index, but it seems That you will have a resort regardless.

As the GBN correctly states, a cover index will help you do something but you have established it in the comments that you are not interested in doing so, But you are not able to stop without requiring or changing your data structure.

Comments