| HashAggregate (cost=989.00..993.44 rows=444 width=539) |
| Group Key: c.id, 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, sl_agg.lost_contact_days, ((date_part('epoch'::text, (now() - max(tbl_work_logs.end_at))) / '86400'::double precision)), sl_agg.last_contact, cc.notice_days |
| -> Nested Loop Left Join (cost=15.80..920.18 rows=444 width=539) |
| Join Filter: (sl_agg.client_id = c.id) |
| -> Nested Loop Left Join (cost=10.29..458.49 rows=3 width=518) |
| Join Filter: (tbl_work_logs.client_id = c.id) |
| -> Nested Loop Left Join (cost=4.67..59.73 rows=1 width=510) |
| Join Filter: (cc.id = c.client_class) |
| -> Nested Loop Left Join (cost=4.67..58.64 rows=1 width=508) |
| Join Filter: (p.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 = 2032) |
| Filter: (NOT deleted) |
| -> Bitmap Heap Scan on tbl_projects p (cost=4.39..50.24 rows=8 width=8) |
| Recheck Cond: (client_id = 2032) |
| Filter: (project_status = 3) |
| -> Bitmap Index Scan on tbl_projects_client_id_idx (cost=0.00..4.39 rows=15 width=0) |
| Index Cond: (client_id = 2032) |
| -> Seq Scan on tbl_client_classes cc (cost=0.00..1.04 rows=4 width=6) |
| -> GroupAggregate (cost=5.62..398.72 rows=3 width=12) |
| Group Key: tbl_work_logs.client_id |
| -> Bitmap Heap Scan on tbl_work_logs (cost=5.62..398.64 rows=3 width=12) |
| Recheck Cond: ((client_id IS NOT NULL) AND (client_id = 2032)) |
| 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.62 rows=133 width=0) |
| Index Cond: ((client_id IS NOT NULL) AND (client_id = 2032)) |
| -> Materialize (cost=5.51..461.60 rows=148 width=20) |
| -> Subquery Scan on sl_agg (cost=5.51..460.86 rows=148 width=20) |
| -> GroupAggregate (cost=5.51..459.38 rows=148 width=20) |
| Group Key: tbl_work_logs_1.client_id |
| -> Bitmap Heap Scan on tbl_work_logs tbl_work_logs_1 (cost=5.51..455.24 rows=157 width=12) |
| Recheck Cond: (client_id = 2032) |
| -> Bitmap Index Scan on tbl_work_logs_client_id_idx (cost=0.00..5.47 rows=157 width=0) |
| Index Cond: (client_id = 2032) |