The fix for this seems to do the (possibly) expensive part twice - in future iterations I'd consider generating the filtered set to a temp table and doing the later two queries from that. OTOH we have no data on how this will really perform yet, but I expect it will be a substantial win over current code regardless.