Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Found workaround here: <a href="http://connect.microsoft.com/SQLServer/feedback/details/532406/performance-issue-with-hierarchyid-fun-isdescendantof-in-where-clause#" rel="nofollow noreferrer">http://connect.microsoft.com/SQLServer/feedback/details/532406/performance-issue-with-hierarchyid-fun-isdescendantof-in-where-clause#</a></p> <p>Just reminding that I started with a <code>heirarchyID</code> passed in from the application and my goal is to retrieve any and all relatives of that value (both Ancestors and Descendants).</p> <p>In my specific example, I had to add the following declarations before the <code>SELECT</code> statement:</p> <pre><code>declare @topNode hierarchyid = (select @messageID.GetAncestor((@messageID.GetLevel()-1))) declare @topNodeParent hierarchyid = (select @topNode.GetAncestor(1)) declare @leftNode hierarchyid= (select @topNodeParent.GetDescendant (null, @topNode)) declare @rightNode hierarchyid= (select @topNodeParent.GetDescendant (@topNode, null)) </code></pre> <p>The <code>WHERE</code> clause has been changed to:</p> <pre><code>messageid.IsDescendantOf(@topNode)=1 AND (messageid &gt; @leftNode ) AND (messageid &lt; @rightNode ) </code></pre> <p>The querying performance increase is very significant:</p> <p>For every result passed in, seek time is now 20ms on average (was from 120 to 420).</p> <p>When querying 25 values, it previously took 25 - 35 seconds to return all related nodes (in some cases each value had many relatives, in some there were none). It now takes only 2 seconds.</p> <p>Thank you very much to all who have contributed to this issue on this site and on others. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload