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 6149999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:32:55+00:00 2026-05-23T19:32:55+00:00

We have rather Big machine 100GB+ memory and 8+ cores in it. Server wide

  • 0

We have rather Big machine 100GB+ memory and 8+ cores in it. Server wide MAXDOP=8.

T_SEQ_FF rowcount = 61692209, size = 2991152 KB  

UPD 1:
Table T_SEQ_FF have two indexes:

1) create index idx_1 on T_SEQ_FF (first_num)
2) create index idx_2 on T_SEQ_FF (second_num)

Table T_SEQ_FF have first_num, second_num pairs of nums that should provide a sequence after cte:

;with first_entity as ( 
    select first_num from  T_SEQ_FF a  where not exists (select 1 from  T_SEQ_FF b  where a.first_num = b.second_num) 
) ,
cte as ( 
select a.first_num, a.second_num, a.first_num as first_key, 1 as sequence_count 
from  T_SEQ_FF a  inner join first_entity b on a.first_num = b.first_num 
union all 
select a.first_num, a.second_num, cte.first_key, cte.sequence_count + 1 
from  T_SEQ_FF a  
inner join cte on a.first_num = cte.second_num 
) 
select * 
from cte 
option (maxrecursion 0); 

But when I run this query – I only see serial query plan without Parallelism.
If I remove 2nd part of CTE from query above:

union all 
    select a.first_num, a.second_num, cte.first_key, cte.sequence_count + 1 
    from  T_SEQ_FF a  
    inner join cte on a.first_num = cte.second_num 

then I could see that query plan becomes Parallelized using Repartition and Gather Streams.

So I can summarize that it is because of recurisve CTE SQL Server is not using Parallelism when processing this query.

I believe that on such big machine with tons of free resources Parallelism should help to finish query faster.

For now it runs for ~40-50mins.

Could you advice how to use as much resources as we can to finish the query faster?

CTE is the only option because we need to populate sequences from first_num - second_num pairs and those sequences could be of any length.

  • 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-23T19:32:55+00:00Added an answer on May 23, 2026 at 7:32 pm

    I would try rewriting the CTE to remove one of the steps i.e.

    ;cte as ( 
    select a.first_num, a.second_num, a.first_num as first_key, 1 as sequence_count 
    from  T_SEQ_FF a  where not exists (select 1 from  T_SEQ_FF b  where a.first_num = b.second_num) 
    union all 
    select a.first_num, a.second_num, cte.first_key, cte.sequence_count + 1 
    from  T_SEQ_FF a  
    inner join cte on a.first_num = cte.second_num 
    ) 
    select * 
    from cte 
    option (maxrecursion 0);
    

    If there is only one root element it would be better to pass this into the query as a variable so the value can be used by the query optimizer.

    Another thing to try is change the query to get the root elements without a subquery i.e. second_num is null or first_num = second_num.

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

Sidebar

Related Questions

I have a rather big number of small bitmaps (100+, size about 40x40) each
I have a rather big number of source files that I need parse and
I’m in the situation that I have to design and implement a rather big
Rather than have everything in one big dialog, I'm looking at being able to
I have a simple importer, it goes through each line of a rather big
I have a rather big php site, which was written for php4 and register_globals
I have rather big form where a user can choose any number of parameters
I have a rather big php script that uses the foreach loop pretty often.
I have to do some find and replace tasks on a rather big file
I have a rather big if statement: if (!$result_spam) { $confrim_spam = FAILED; }

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.