QUERY PLAN
Unique (cost=602.97..616.14 rows=85 width=539)
-> Sort (cost=602.97..603.18 rows=85 width=539)
Sort Key: c.name, c.abbr, c.pinyin_shortcut, c.description, c.corp_rep, c.website, c.capital, c.established_at, c.headcount, c.reg_address, c.working_address, c.telephone, c.fax, c.scale, c.branch, c.purchase_scale_per_yr, c.purchase_freq, c.company_nature, c.client_class, c.client_industry, c.client_type, c.sales_rep, c.main_contact, c.created_by, c.created_at, c.updated_at, c.main_business, c.deleted, c.capital_currency, c.invoice_info, c.logo, c.en_name, c.pick_at, c.it_budget, c.deployment_mode, c.it_per_num, c.public_relations_difficulty, c.it_status, c.decision_process, c.coach, c.competitor, c.peers, c.supplier, c.main_product, c.client_base_info_count, c.client_key_info_count, c.contact_count, c.visit_count, c.cooperate_count, c.case_pre_sales_count, c.case_implement_count, c.is_overdue_remind, c.from_contact, c.tax_no, (CASE WHEN (c.sales_rep IS NULL) THEN 0 ELSE c.sales_rep END), (CASE WHEN (c.sales_rep IS NULL) THEN 0 ELSE 1 END), (CASE WHEN (p.id IS NULL) THEN false ELSE true END), ((date_part('epoch'::text, (now() - max(tbl_work_logs_1.end_at))) / '86400'::double precision)), ((date_part('epoch'::text, (now() - max(tbl_work_logs.end_at))) / '86400'::double precision)), (max(tbl_work_logs_1.end_at)), cc.notice_days
-> Nested Loop Left Join (cost=14.70..600.24 rows=85 width=539)
Join Filter: (tbl_work_logs_1.client_id = c.id)
-> Nested Loop Left Join (cost=9.73..311.91 rows=1 width=518)
Join Filter: (cc.id = c.client_class)
-> Nested Loop Left Join (cost=9.73..310.82 rows=1 width=516)
Join Filter: (p.client_id = c.id)
-> Nested Loop Left Join (cost=5.32..255.51 rows=1 width=512)
Join Filter: (tbl_work_logs.client_id = c.id)
-> Index Scan using tbl_clients_pkey on tbl_clients c (cost=0.28..8.29 rows=1 width=504)
Index Cond: (id = 2128)
Filter: (NOT deleted)
-> GroupAggregate (cost=5.04..247.19 rows=1 width=12)
Group Key: tbl_work_logs.client_id
-> Bitmap Heap Scan on tbl_work_logs (cost=5.04..247.16 rows=1 width=12)
Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 2128))
Filter: ((NOT is_draft) AND (location_in_id IS NOT NULL) AND (location_out_id IS NOT NULL))
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..5.04 rows=75 width=0)
Index Cond: ((client_id IS NOT NULL) AND (client_id = 2128))
-> Bitmap Heap Scan on tbl_projects p (cost=4.41..55.20 rows=9 width=8)
Recheck Cond: (client_id = 2128)
Filter: (project_status = 3)
-> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.41 rows=17 width=0)
Index Cond: (client_id = 2128)
-> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=6)
-> GroupAggregate (cost=4.97..287.46 rows=85 width=20)
Group Key: tbl_work_logs_1.client_id
-> Bitmap Heap Scan on tbl_work_logs tbl_work_logs_1 (cost=4.97..285.10 rows=88 width=12)
Recheck Cond: (client_id = 2128)
-> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..4.95 rows=88 width=0)
Index Cond: (client_id = 2128)