Можно использовать window-функцию row_number() для минимизации обращения к таблице
with max_m_ep as
( select tue.user_id, te.material_id, max(tue.episode_id) AS "_ep" from user_episode tue
left join episode te ON te.id = tue.episode_id
group by tue.user_id, te.material_id )
select * from
(
select e.*, row_number() OVER (partition by e.material_id order by e.id) AS ep_order
from episode e
left join max_m_ep mx ON mx.material_id = e.material_id and mx.user_id = 2
where e.id >= mx._ep
or mx._ep is null
order by e.id
) data
where ep_order < 5;