QUERY PLAN
Aggregate (cost=5074.40..5074.41 rows=1 width=8)
-> Sort (cost=5074.01..5074.08 rows=26 width=179)
Sort Key: s.is_draft DESC, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END) DESC, s.end_at, s.updated_at DESC NULLS LAST, s.created_at DESC
-> Group (cost=5073.01..5073.40 rows=26 width=179)
Group Key: s.id, lin.id, lout.id, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END)
-> Sort (cost=5073.01..5073.08 rows=26 width=41)
Sort Key: s.id, lin.id, lout.id, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END) DESC
-> Hash Join (cost=4188.02..5072.40 rows=26 width=41)
Hash Cond: (s.id = rvr2.work_log_id)
-> Hash Left Join (cost=4020.18..4681.23 rows=35681 width=41)
Hash Cond: (s.id = rvr.work_log_id)
-> Hash Left Join (cost=3791.40..4147.88 rows=35681 width=37)
Hash Cond: (s.location_out_id = lout.id)
-> Hash Left Join (cost=2974.87..3237.69 rows=35681 width=37)
Hash Cond: (s.location_in_id = lin.id)
-> Hash Right Join (cost=2158.34..2327.50 rows=35681 width=37)
Hash Cond: (ccr.work_log_id = s.id)
-> Seq Scan on tbl_work_log_carbon_copy_rels ccr (cost=0.00..144.59 rows=9359 width=4)
-> Hash (cost=1712.33..1712.33 rows=35681 width=49)
-> Seq Scan on tbl_work_logs s (cost=0.00..1712.33 rows=35681 width=49)
Filter: (NOT is_draft)
-> Hash (cost=556.79..556.79 rows=20779 width=4)
-> Seq Scan on tbl_location lin (cost=0.00..556.79 rows=20779 width=4)
-> Hash (cost=556.79..556.79 rows=20779 width=4)
-> Seq Scan on tbl_location lout (cost=0.00..556.79 rows=20779 width=4)
-> Hash (cost=126.68..126.68 rows=8168 width=8)
-> Seq Scan on tbl_work_log_verify_rels rvr (cost=0.00..126.68 rows=8168 width=8)
-> Hash (cost=167.52..167.52 rows=26 width=4)
-> Seq Scan on tbl_work_log_verify_rels rvr2 (cost=0.00..167.52 rows=26 width=4)
Filter: ((user_id IS NOT NULL) AND (user_id = 1001) AND (status = 0))