sql - Improve Performance of execution time on 20k rows -


i using following code on 20k rows , takes 3 min, how can improve ?

;with  abcd         (               -- anchor             select  topicid, [description], parentid,topicgroupfk, topicgroupfk "groupfk",                     cast(([description]) varchar(1000)) "path"                accounting.topics               parentid='0' , financialperiodfk=1             union               --recursive member             select  t.topicid, t.[description], t.parentid,t.topicgroupfk,a.groupfk "groupfk",                     cast((a.path + '/' + t.description) varchar(1000)) "path"                accounting.topics t                              join abcd                       on t.parentid = a.topicid                          t.financialperiodfk=1            ) select *  abcd parentid>=0 

  • what datatype of [parentid]?

i bet (hope) int or bigint. therefore can remove quote , implicit cast here:

where   parentid='0' 
  • what datatype of [description]?

if varchar(1000), can remove 2 cast varchar(1000). if smaller, consider changing varchar(1000) , remove 2 casts.

  • do have covering index on [parentid] including [financialperiodfk] clause on [financialperiodfk] = 1?

  • where parentid>=0 not needed

  • is [topicgroupfk] integer?

  • you can try reduce size , scope of recursive cte , them later

    you need topicid, parentid , path in cte , try other columns later join on topicid in main select


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -