I have a view that returns 2 ints from a table using a CTE. If I query the view like this it runs in less than a second
SELECT * FROM view1 WHERE ID = 1
Came across this same issue myself and it turned out to be a missing index involving a (left) join on the result of a subquery.
select * from foo A left outer join ( select x, count(*) from bar group by x ) B on A.x = B.x
Added an index named bar_x for bar.x