######## rep_busiest_professor ########
Sort  (cost=11894.77..11895.22 rows=181 width=68) (actual time=115.101..115.107 rows=20.00 loops=1)
  Sort Key: a.year, (CASE a.type WHEN 'summer'::semester_type THEN 1 ELSE 2 END)
  Sort Method: quicksort  Memory: 26kB
  Buffers: shared hit=1082, temp read=282 written=283
  CTE professor_load
    ->  GroupAggregate  (cost=10376.15..11600.15 rows=2400 width=32) (actual time=83.574..107.280 rows=2400.00 loops=1)
          Group Key: es.semester_id, ss.professor_id
          Buffers: shared hit=1021, temp read=282 written=283
          ->  Sort  (cost=10376.15..10576.15 rows=80000 width=20) (actual time=83.558..93.708 rows=80000.00 loops=1)
                Sort Key: es.semester_id, ss.professor_id, ss.subjects_id
                Sort Method: external merge  Disk: 2256kB
                Buffers: shared hit=1021, temp read=282 written=283
                ->  Hash Left Join  (cost=2131.00..3861.07 rows=80000 width=20) (actual time=14.299..47.876 rows=80000.00 loops=1)
                      Hash Cond: (ss.id = ps.enrolled_id)
                      Buffers: shared hit=1021
                      ->  Hash Join  (cost=514.00..2034.06 rows=80000 width=16) (actual time=3.780..23.831 rows=80000.00 loops=1)
                            Hash Cond: (ss.enrolled_semesters_id = es.id)
                            Buffers: shared hit=664
                            ->  Seq Scan on semesters_subjects ss  (cost=0.00..1310.00 rows=80000 width=16) (actual time=0.009..4.194 rows=80000.00 loops=1)
                                  Buffers: shared hit=510
                            ->  Hash  (cost=314.00..314.00 rows=16000 width=8) (actual time=3.736..3.736 rows=16000.00 loops=1)
                                  Buckets: 16384  Batches: 1  Memory Usage: 753kB
                                  Buffers: shared hit=154
                                  ->  Seq Scan on enrolled_semesters es  (cost=0.00..314.00 rows=16000 width=8) (actual time=0.009..2.092 rows=16000.00 loops=1)
                                        Buffers: shared hit=154
                      ->  Hash  (cost=917.00..917.00 rows=56000 width=8) (actual time=10.421..10.421 rows=56000.00 loops=1)
                            Buckets: 65536  Batches: 1  Memory Usage: 2700kB
                            Buffers: shared hit=357
                            ->  Seq Scan on passed_subjects ps  (cost=0.00..917.00 rows=56000 width=8) (actual time=0.012..4.723 rows=56000.00 loops=1)
                                  Buffers: shared hit=357
  ->  Nested Loop Left Join  (cost=79.73..287.83 rows=181 width=68) (actual time=108.848..115.089 rows=20.00 loops=1)
        Buffers: shared hit=1082, temp read=282 written=283
        ->  Hash Right Join  (cost=79.45..204.42 rows=181 width=36) (actual time=108.755..114.922 rows=20.00 loops=1)
              Hash Cond: (pl.semester_id = a.id)
              Buffers: shared hit=1022, temp read=282 written=283
              ->  Hash Anti Join  (cost=78.00..198.12 rows=1811 width=32) (actual time=108.727..114.880 rows=20.00 loops=1)
                    Hash Cond: (pl.semester_id = pl1.semester_id)
                    Join Filter: ((pl.enrolled_students < pl1.enrolled_students) OR ((pl.enrolled_students = pl1.enrolled_students) AND (pl.graded_students < pl1.graded_students)) OR ((pl.enrolled_students = pl1.enrolled_students) AND (pl.graded_students = pl1.graded_students) AND (pl.professor_id > pl1.professor_id)))
                    Rows Removed by Join Filter: 40595
                    Buffers: shared hit=1021, temp read=282 written=283
                    ->  CTE Scan on professor_load pl  (cost=0.00..48.00 rows=2400 width=32) (actual time=83.576..83.800 rows=2400.00 loops=1)
                          Storage: Memory  Maximum Storage: 164kB
                          Buffers: shared hit=1021, temp read=282 written=283
                    ->  Hash  (cost=48.00..48.00 rows=2400 width=24) (actual time=24.861..24.861 rows=2400.00 loops=1)
                          Buckets: 4096  Batches: 1  Memory Usage: 173kB
                          ->  CTE Scan on professor_load pl1  (cost=0.00..48.00 rows=2400 width=24) (actual time=0.001..24.500 rows=2400.00 loops=1)
                                Storage: Memory  Maximum Storage: 164kB
              ->  Hash  (cost=1.20..1.20 rows=20 width=12) (actual time=0.023..0.023 rows=20.00 loops=1)
                    Buckets: 1024  Batches: 1  Memory Usage: 9kB
                    Buffers: shared hit=1
                    ->  Seq Scan on active_semesters a  (cost=0.00..1.20 rows=20 width=12) (actual time=0.014..0.016 rows=20.00 loops=1)
                          Buffers: shared hit=1
        ->  Index Scan using users_pkey on users u  (cost=0.28..0.45 rows=1 width=26) (actual time=0.005..0.005 rows=1.00 loops=20)
              Index Cond: (id = pl.professor_id)
              Index Searches: 20
              Buffers: shared hit=60
Planning:
  Buffers: shared hit=340
Planning Time: 11.753 ms
Execution Time: 124.648 ms
-- OK explain_rep_busiest_professor.sql
