Analyzing Tempdb Spills and Usage Across Recursive Queries

  • Comments posted to this topic are about the item Analyzing Tempdb Spills and Usage Across Recursive Queries

  • I may be mistaken as I have not tested this out

    INSERT INTO @Hierarchy

    SELECT

    h.ID

    , h.ParentID

    , h.Name

    , @Level + 1

    FROM

    HierarchyBig h

    INNER JOIN @Hierarchy t

    ON h.ParentID = t.ID;

     

    For this and the temp table, wont this statement run indefinitely once it reaches the final level, if not for the max recursion setting?

    ----------------------------------------------------

  • Hi MMartin1,

    We need to seed the root node first.. This has come in screenshot but not in code.

    INSERT INTO @Hierarchy (ID, ParentID, Name, Level)

    SELECT ID, ParentID, Name, 1

    FROM HierarchyBig

    WHERE ParentID IS NULL;

     

    Thanks for pointing that out . I’ll request an update to reflect the correct version. Appreciate the feedback!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply