• Okay. First I'd try an update stats on the base table to make sure all the estimates are right.

    Those aren't really duplicates based on the logic in the query. Notice the data in the typ column, on the rows where there are duplicates there is a row with a value of "blocked" and row with a value of "blocking". So the query needs to be changed to either not include the typ column in the final output or only include "blocked" in the UNION ALL section of the CTE.