Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7402081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:39:02+00:00 2026-05-29T04:39:02+00:00

I have a set of data from a table ( TableA ) which relates

  • 0

I have a set of data from a table (TableA) which relates to itself through TableB. Parents in TableA have children in TableA. Those children might also have children. Nothing amazing here.

I have a top-level set of rows from TableA that I need to operate on. Before I can operate on those rows, I must have each child row on hand. I must be able to operate on each top-level row of TableA (and it’s children) as fast as possible in my application.

I can’t find a way to do this.

Using a recursive CTE (TableA top-level set as anchor, TableB->TableA join as union), does not fulfill the requirements. The entire top-level set from TableA is returned in the CTE before it works on level 2 of the children. Then it works on level 3. Then level 4, etc. Since my top-level set is some 400,000 plus rows, my client application cannot begin working on rows until the ENTIRE dataset has been batched up on the server.

I need a better way to do this. I’ve tried streaming a flat set of top-level TableA rows to the client, and having the client issue the recursive CTE statement repeatedly for each top-level TableA row. This actually works. But there’s too much noise. The sustained row retrieval rate is too large due to the repeated reissuing of statements.

I need a creative solution.

Snippet of the per-record CTE I’m using. In this example, TableA is Member, and TableB is MemberReplacement. I ripped out most of the select statement in the middle, and most of the joins.

WITH T_MemberRecurse
(
    MemberId,
    IncludedMemberId,
    Level
) AS (
    SELECT      Member.Id,
                Member.Id,
                0
    FROM        MemberInput
    INNER JOIN  MemberInputItem
        ON      MemberInputItem.MemberInputId = MemberInput.Id
    INNER JOIN  Member
        ON      Member.Id = MemberInputItem.MemberId
    UNION ALL
    SELECT      T_MemberRecurse.MemberId,
                Member2.Id,
                Level + 1
    FROM        T_MemberRecurse
    INNER JOIN  Member
        ON      Member.Id = T_MemberRecurse.IncludedMemberId
    INNER JOIN  MemberReplacement
        ON      MemberReplacement.MemberId = Member.Id
    INNER JOIN  Member Member2
        ON      Member2.Id = MemberReplacement.OriginalMemberId
)
SELECT      Member.Id,
            T_MemberRecurse.IncludedMemberId,
            T_MemberRecurse.Level,

FROM        MemberInput
INNER JOIN  LotsOfTables
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:39:03+00:00Added an answer on May 29, 2026 at 4:39 am

    I’m thinking about this a bit right now, but first a stab in the dark that could help, due to experiences I’ve had with linked servers where forcing row-by-row operations improved performance by 2 orders of magnitude.

    Turn your CTE into a rowset-returning function with one parameter, the desired Member Id.

    Then:

    SELECT
       *
    FROM
       Member M
       CROSS APPLY dbo.MemberChildren(M.Id) C
    WHERE
       {Conditions for desired set of Members here}
    WITH (FAST 20);
    

    Please let me know if this works. The idea is to force the engine to traverse deep-first rather than wide-first. It might be lower overall server performance, but theoretically should let your client begin working with some rows of data.

    Update

    Second idea: get the parent and child information separately and perform, logically, a merge join in the client. (An ordered nested loop that only advances the ordered second/inner input until it mismatches.) Get smaller chunks at once using key ranges or row_number. Or get the entire parent set then get smaller set of child rows.

    Update 2

    Idea 3: Instead of a recursive CTE, use 5 plain vanilla joins to get all the data you need. It sounds awful, but should let you do FAST 100 to get started on the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of XSDs from which I generate data access classes, stored
I have the following Execution statement which creates a table (using data from another
I have two results from a data set. I want to add both results
I have a set of data points in 3D space which apparently all fall
I have a table:'Categories' which has two fields:Category_ID and Category. Data in Category_ID field
We have this set of data that we need to get the average of
I have a set of data that models a hierarchy of categories. A root
I have a set of data protected by 16bit checksums that I need to
I have a set of data that needs to be displayed as a crosstab
I have a set of data and I want to find the biggest and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.