Slow performance running ordered query on SQL Server table with hierarchyid field -
I have a tree of classes stored in the table, which is currently a traditional The following query is successfully sorted by a depth level in the format of data needed and by their depth and category name: The display of this query is unfortunately, not really great, there are only 319 categories in the actual table, and 89 of them To The time for that query is as follows: Now one third of the other, I find this kind of small amount of data very strange It looks like there is no indexed one side of the package PK one in the table. Is it a way to rewrite it so that it's fast? Do I just need to add appropriate indexes? Should I collect a hierarchical order to generate with the above question, whenever the categories or their structure changes? Should I see class trees at the application level in caching? My stomach tells me that this question should not be taken until it is not, and it is probably missing a trick, but I < Div> text "itemprop =" text "> Processing time seems appropriate for me that it has a union query, some functions and one with with to take the sub-query processing time into account by using> parentcategoryId field And a hierarchy area called
Eclllon
with q as c (c.Id, c.Name, c.Echelon, c.Echelon selection, NewEchelon as category c Zero is Zero and ParentCategoryId Zero Unions select all c2.Id, c2.Name, c2.Echelon, hierarchyid :: Parser (q.NewEchelon.ToString () + (more than ROW_NUMBER (). By order) NVARCHAR (max) + '/') from q to c2.Deleted include c2 class c2 and c2.Echelon.IsDescendantOf (q.Echelon) = 1 and c2.Echelon.GetLevel () = Q.Echelon.GetLevel () +1) Select * New order from the order by NewEchelon
Deletion of has been removed soft with a non-null value in the column.
Compile SQL Server's parse and time: CPU time = 0 ms, time passed = 0 ms (230 lines (S) Affected) SQL Server Execution Time: CPU time = 218 ms, elapsed time = 321 ms
Comments
Post a Comment