We have a fairly large machine with a memory capacity of 100 GB + and 8+ cores. MAXDOP server = 8.
T_SEQ_FF rowcount = 61692209, size = 2991152 KB
UPD 1: Table T_SEQ_FF has two indexes:
1) create index idx_1 on T_SEQ_FF (first_num) 2) create index idx_2 on T_SEQ_FF (second_num)
The T_SEQ_FF table has first_num , second_num pairs numbers that should contain the 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 the plan of the serial request without Parallelism. If I remove the second part of the CTE from the request 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 the request plan becomes Parallel using Repartition and Gather Streams.
Therefore, I can summarize that this is related to recurisve . CTE SQL Server does not use Parallelism when processing this query.
I believe that on such a large machine with tons of free resources, Parallelism should help complete the request faster.
While it works for ~ 40-50 minutes.
Could you please advise to use as many resources as possible in order to complete the request faster?
CTE is the only option because we need to populate sequences from the first_num - second_num , and these sequences can be of any length.