SQL CTE性能非常慢

时间:2018-09-19 13:45:44

标签: sql-server common-table-expression

我有一个有关SQL Server中通用表表达式的性能问题。我的查询如下

;WITH tempCTE (VolumeID,YZMWF,lvl)
    AS
    ( 
        select DISTINCT  VolumeID, YZMWF ,0 as lvl  from YZMDGT where YZMWF=@WorkID
        union  all
        select e.VolumeID, e.YZMWF , cte.lvl + 1 lvl  from YZMDGT e inner join tempCTE cte on e.YZMWF=cte.VolumeID and e.VolumeID<>e.YZMWF

    ) 

    select  DISTINCT * into #dgt from tempCTE

工作时间5分钟。如何快速查询?我的执行计划如下 enter image description here

0 个答案:

没有答案