QUERY PLAN
Limit (cost=684.29..684.31 rows=10 width=523)
-> Sort (cost=684.29..687.33 rows=1219 width=523)
Sort Key: s.is_complete, s.end_at DESC, s.created_at DESC
-> HashAggregate (cost=639.66..657.94 rows=1219 width=523)
Group Key: s.id
-> Hash Left Join (cost=27.57..636.61 rows=1219 width=519)
Hash Cond: (s.id = ccr.schedule_id)
Filter: ((((s.is_public = 1) AND (s.created_by <> 1000)) OR (s.created_by = 1000) OR (ccr.user_id = 1000)) AND ((s.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])) OR (ccr.user_id = 1000)))
-> Hash Join (cost=8.03..598.33 rows=2149 width=519)
Hash Cond: (s.created_by = u.id)
-> Seq Scan on tbl_schedules s (cost=0.00..551.29 rows=14431 width=519)
Filter: is_complete
-> Hash (cost=7.76..7.76 rows=21 width=4)
-> Seq Scan on tbl_users u (cost=0.00..7.76 rows=21 width=4)
Filter: (department_id = 2)
-> Hash (cost=10.91..10.91 rows=691 width=8)
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.91 rows=691 width=8)