QUERY PLAN
Aggregate (cost=4717.74..4717.75 rows=1 width=8)
-> Sort (cost=4717.32..4717.39 rows=28 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=4716.23..4716.65 rows=28 width=179)
Group Key: s.id, lin.id, lout.id, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END)
-> Sort (cost=4716.23..4716.30 rows=28 width=41)
Sort Key: s.id, lin.id, lout.id, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END) DESC
-> Hash Join (cost=3874.11..4715.56 rows=28 width=41)
Hash Cond: (s.id = rvr2.work_log_id)
-> Hash Left Join (cost=3719.03..4350.08 rows=33607 width=41)
Hash Cond: (s.id = rvr.work_log_id)
-> Hash Left Join (cost=3507.44..3852.72 rows=33607 width=37)
Hash Cond: (s.location_out_id = lout.id)
-> Hash Left Join (cost=2768.99..3026.05 rows=33607 width=37)
Hash Cond: (s.location_in_id = lin.id)
-> Hash Right Join (cost=2030.54..2199.38 rows=33607 width=37)
Hash Cond: (ccr.work_log_id = s.id)
-> Seq Scan on tbl_work_log_carbon_copy_rels ccr (cost=0.00..144.34 rows=9334 width=4)
-> Hash (cost=1610.45..1610.45 rows=33607 width=49)
-> Seq Scan on tbl_work_logs s (cost=0.00..1610.45 rows=33607 width=49)
Filter: (NOT is_draft)
-> Hash (cost=503.20..503.20 rows=18820 width=4)
-> Seq Scan on tbl_location lin (cost=0.00..503.20 rows=18820 width=4)
-> Hash (cost=503.20..503.20 rows=18820 width=4)
-> Seq Scan on tbl_location lout (cost=0.00..503.20 rows=18820 width=4)
-> Hash (cost=116.82..116.82 rows=7582 width=8)
-> Seq Scan on tbl_work_log_verify_rels rvr (cost=0.00..116.82 rows=7582 width=8)
-> Hash (cost=154.73..154.73 rows=28 width=4)
-> Seq Scan on tbl_work_log_verify_rels rvr2 (cost=0.00..154.73 rows=28 width=4)
Filter: ((user_id IS NOT NULL) AND (user_id = 1001) AND (status = 0))