... Without looking closely, an index might help: student_id,assignment_id That'd avoid the sort, and maybe change the shape of the whole plan.
-- Justin
pgsql-performance by date:
Соглашаюсь с условиями обработки персональных данных