QUERY PLAN
Limit (cost=697.80..697.80 rows=1 width=285)
-> Sort (cost=697.80..697.80 rows=1 width=285)
Sort Key: c.updated_at DESC
-> HashAggregate (cost=697.78..697.79 rows=1 width=285)
Group Key: c.id
-> Merge Left Join (cost=517.59..672.74 rows=10017 width=285)
Merge Cond: (c.last_engineer = egr.engineer_id)
-> Sort (cost=375.04..377.50 rows=982 width=285)
Sort Key: c.last_engineer
-> Hash Right Join (cost=258.30..326.24 rows=982 width=285)
Hash Cond: (sgr.sales_id = c.deduct_points_from)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..30.40 rows=2040 width=4)
-> Hash (cost=257.14..257.14 rows=93 width=285)
-> Hash Left Join (cost=208.43..257.14 rows=93 width=285)
Hash Cond: (c.id = cccr.case_id)
Filter: ((c.deduct_points_from = 5493) OR (c.deduct_points_from IS NULL) OR (c.last_engineer = 5495) OR (crr.user_id = 5495) OR (hashed SubPlan 1) OR (cccr.user_id = 5495) OR (c.created_by = 5495))
-> Hash Right Join (cost=117.01..155.29 rows=23 width=293)
Hash Cond: (crr.remind_date_id = crd.id)
-> Seq Scan on tbl_case_remind_receivers crr (cost=0.00..30.40 rows=2040 width=8)
-> Hash (cost=116.77..116.77 rows=19 width=293)
-> Hash Right Join (cost=79.61..116.77 rows=19 width=293)
Hash Cond: (crd.case_id = c.id)
-> Seq Scan on tbl_case_remind_dates crd (cost=0.00..26.60 rows=1660 width=8)
-> Hash (cost=79.57..79.57 rows=3 width=289)
-> Nested Loop Left Join (cost=51.57..79.57 rows=3 width=289)
Join Filter: (client.id = c.client_id)
-> Hash Right Join (cost=51.44..71.37 rows=3 width=285)
Hash Cond: (cb.case_id = c.id)
-> Seq Scan on tbl_callback_records cb (cost=0.00..17.20 rows=720 width=4)
-> Hash (cost=51.42..51.42 rows=1 width=285)
-> Hash Right Join (cost=38.11..51.42 rows=1 width=285)
Hash Cond: (ps.case_id = c.id)
-> Seq Scan on tbl_pre_sales ps (cost=0.00..12.40 rows=240 width=4)
-> Hash (cost=38.10..38.10 rows=1 width=285)
-> Hash Right Join (cost=26.44..38.10 rows=1 width=285)
Hash Cond: (iri.implement_record_id = i.id)
-> Seq Scan on tbl_implement_items iri (cost=0.00..11.20 rows=120 width=4)
-> Hash (cost=26.43..26.43 rows=1 width=289)
-> Hash Right Join (cost=13.26..26.43 rows=1 width=289)
Hash Cond: (i.case_id = c.id)
-> Seq Scan on tbl_implement_records i (cost=0.00..12.50 rows=250 width=8)
-> Hash (cost=13.25..13.25 rows=1 width=285)
-> Seq Scan on tbl_cases c (cost=0.00..13.25 rows=1 width=285)
Filter: (client_id = 1)
-> Materialize (cost=0.14..8.16 rows=1 width=4)
-> Index Only Scan using tbl_clients_pkey on tbl_clients client (cost=0.14..8.15 rows=1 width=4)
Index Cond: (id = 1)
-> Hash (cost=30.40..30.40 rows=2040 width=8)
-> Seq Scan on tbl_case_carbon_copy_rels cccr (cost=0.00..30.40 rows=2040 width=8)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)
-> Sort (cost=142.54..147.64 rows=2040 width=4)
Sort Key: egr.engineer_id
-> Seq Scan on tbl_engineer_group_relationships egr (cost=0.00..30.40 rows=2040 width=4)