Window Min/Max slow on CTE?
SET @Min=1, @Max=13;
WITH RECURSIVE cte AS (
SELECT @Min AS num
UNION ALL
SELECT num+1
FROM cte
WHERE cte.num <= @Max
UNION ALL
SELECT num+1
FROM cte
WHERE cte.num <= @Max
)
SELECT
cte.num -- 0.005s
# ,MAX(cte.num) OVER () AS 'Max' -- 12.307s
FROM cte
Can someone explain to me why Min/Max are slow in this example and whether or not there is a way to make it fast?
Posted Dec 25, 2019, 3:54 AM UTC
30