QUERY PLAN
Limit (cost=5126.15..5126.20 rows=20 width=323)
-> Sort (cost=5126.15..5126.21 rows=26 width=323)
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=5125.08..5125.54 rows=26 width=323)
Group Key: s.id, lin.id, lout.id, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END)
-> Sort (cost=5125.08..5125.15 rows=26 width=307)
Sort Key: s.id, lin.id, lout.id, (CASE WHEN (rvr.status = 0) THEN 1 ELSE 0 END) DESC
-> Hash Join (cost=2291.26..5124.47 rows=26 width=307)
Hash Cond: (s.id = rvr2.work_log_id)
-> Hash Left Join (cost=2123.41..4733.29 rows=35681 width=307)
Hash Cond: (s.id = ccr.work_log_id)
-> Hash Left Join (cost=1861.83..4066.06 rows=35681 width=307)
Hash Cond: (s.id = rvr.work_log_id)
-> Hash Left Join (cost=1633.05..3532.71 rows=35681 width=303)
Hash Cond: (s.location_out_id = lout.id)
-> Hash Left Join (cost=816.53..2622.52 rows=35681 width=299)
Hash Cond: (s.location_in_id = lin.id)
-> Seq Scan on tbl_work_logs s (cost=0.00..1712.33 rows=35681 width=295)
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=144.59..144.59 rows=9359 width=4)
-> Seq Scan on tbl_work_log_carbon_copy_rels ccr (cost=0.00..144.59 rows=9359 width=4)
-> 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))