| Limit (cost=1964.01..1964.06 rows=20 width=785) |
| -> Sort (cost=1964.01..1964.62 rows=247 width=785) |
| Sort Key: (CASE WHEN (tmp1.budgets IS NULL) THEN '0'::numeric ELSE tmp1.budgets END) DESC, c.created_at DESC |
| -> Group (cost=1942.61..1957.43 rows=247 width=785) |
| Group Key: c.id, (CASE WHEN (tmp1.budgets IS NULL) THEN '0'::numeric ELSE tmp1.budgets END), (CASE WHEN (tmp1.profits IS NULL) THEN '0'::numeric ELSE tmp1.profits END), (CASE WHEN (tmp1.count IS NULL) THEN '0'::bigint ELSE tmp1.count END), (CASE WHEN ((tmp1.budgets IS NULL) OR (tmp1.budgets = '0'::numeric)) THEN '0'::numeric ELSE (tmp1.profits / tmp1.budgets) END), (CASE WHEN ((sum(p_1.budget)) IS NULL) THEN '0'::numeric ELSE (sum(p_1.budget)) END), (CASE WHEN ((count(p_1.id)) IS NULL) THEN '0'::bigint ELSE (count(p_1.id)) END), (CASE WHEN ((sum(p_2.budget)) IS NULL) THEN '0'::numeric ELSE (sum(p_2.budget)) END), (CASE WHEN ((count(p_2.id)) IS NULL) THEN '0'::bigint ELSE (count(p_2.id)) END), tmp1.last_bargain_date, tmp1.count, ci.id, ct.id, (CASE WHEN (tmp1.collected IS NULL) THEN '0'::numeric ELSE tmp1.collected END), (CASE WHEN (tmp1.un_collected IS NULL) THEN '0'::numeric ELSE tmp1.un_collected END), (CASE WHEN (tmp10.invoices IS NULL) THEN '0'::numeric ELSE tmp10.invoices END), (CASE WHEN (tmp10.un_invoices IS NULL) THEN '0'::numeric ELSE tmp10.un_invoices END), (CASE WHEN (tmp11.count IS NULL) THEN '0'::bigint ELSE tmp11.count END), (CASE WHEN ((sum(puc.budget)) IS NULL) THEN '0'::numeric ELSE (sum(puc.budget)) END), (CASE WHEN (tmp13.budgets IS NULL) THEN '0'::numeric ELSE tmp13.budgets END), (CASE WHEN (tmp13.profits IS NULL) THEN '0'::numeric ELSE tmp13.profits END) |
| -> Sort (cost=1942.61..1943.23 rows=247 width=785) |
| Sort Key: c.id, (CASE WHEN (tmp1.budgets IS NULL) THEN '0'::numeric ELSE tmp1.budgets END) DESC, (CASE WHEN (tmp1.profits IS NULL) THEN '0'::numeric ELSE tmp1.profits END), (CASE WHEN (tmp1.count IS NULL) THEN '0'::bigint ELSE tmp1.count END), (CASE WHEN ((tmp1.budgets IS NULL) OR (tmp1.budgets = '0'::numeric)) THEN '0'::numeric ELSE (tmp1.profits / tmp1.budgets) END), (CASE WHEN ((sum(p_1.budget)) IS NULL) THEN '0'::numeric ELSE (sum(p_1.budget)) END), (CASE WHEN ((count(p_1.id)) IS NULL) THEN '0'::bigint ELSE (count(p_1.id)) END), (CASE WHEN ((sum(p_2.budget)) IS NULL) THEN '0'::numeric ELSE (sum(p_2.budget)) END), (CASE WHEN ((count(p_2.id)) IS NULL) THEN '0'::bigint ELSE (count(p_2.id)) END), tmp1.last_bargain_date, tmp1.count, ci.id, ct.id, (CASE WHEN (tmp1.collected IS NULL) THEN '0'::numeric ELSE tmp1.collected END), (CASE WHEN (tmp1.un_collected IS NULL) THEN '0'::numeric ELSE tmp1.un_collected END), (CASE WHEN (tmp10.invoices IS NULL) THEN '0'::numeric ELSE tmp10.invoices END), (CASE WHEN (tmp10.un_invoices IS NULL) THEN '0'::numeric ELSE tmp10.un_invoices END), (CASE WHEN (tmp11.count IS NULL) THEN '0'::bigint ELSE tmp11.count END), (CASE WHEN ((sum(puc.budget)) IS NULL) THEN '0'::numeric ELSE (sum(puc.budget)) END), (CASE WHEN (tmp13.budgets IS NULL) THEN '0'::numeric ELSE tmp13.budgets END), (CASE WHEN (tmp13.profits IS NULL) THEN '0'::numeric ELSE tmp13.profits END) |
| -> Hash Left Join (cost=1717.12..1932.80 rows=247 width=785) |
| Hash Cond: (ca.engineer_id = egr.engineer_id) |
| -> Hash Left Join (cost=1715.51..1926.56 rows=247 width=749) |
| Hash Cond: (c.client_type = ct.id) |
| -> Hash Left Join (cost=1714.37..1924.33 rows=247 width=603) |
| Hash Cond: (c.id = tmp13.client_id) |
| -> Hash Right Join (cost=1514.06..1723.37 rows=247 width=539) |
| Hash Cond: (ca.case_id = cas.id) |
| -> Seq Scan on tbl_case_assignments ca (cost=0.00..174.70 rows=8570 width=8) |
| -> Hash (cost=1511.00..1511.00 rows=245 width=539) |
| -> Hash Right Join (cost=1209.48..1511.00 rows=245 width=539) |
| Hash Cond: (cas.client_id = c.id) |
| -> Seq Scan on tbl_cases cas (cost=0.00..267.14 rows=8514 width=8) |
| -> Hash (cost=1208.75..1208.75 rows=58 width=535) |
| -> Hash Left Join (cost=1206.21..1208.75 rows=58 width=535) |
| Hash Cond: (c.client_industry = ci.id) |
| -> Merge Left Join (cost=1204.65..1207.02 rows=58 width=389) |
| Merge Cond: (c.id = puc.used_client) |
| -> Merge Left Join (cost=1005.32..1006.02 rows=58 width=357) |
| Merge Cond: (c.id = p_2.used_client) |
| -> Merge Left Join (cost=813.10..813.47 rows=58 width=317) |
| Merge Cond: (c.id = p_1.used_client) |
| -> Sort (cost=621.32..621.47 rows=58 width=277) |
| Sort Key: c.id |
| -> Hash Left Join (cost=522.67..619.62 rows=58 width=277) |
| Hash Cond: (c.id = tmp11.client_id) |
| -> Hash Left Join (cost=514.29..611.09 rows=58 width=269) |
| Hash Cond: (c.id = tmp10.client_id) |
| -> Hash Left Join (cost=265.49..362.13 rows=58 width=205) |
| Hash Cond: (c.id = tmp1.client_id) |
| -> Nested Loop (cost=14.46..110.95 rows=58 width=65) |
| -> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.77 rows=1 width=4) |
| Filter: ((sales_id = 1001) AND (group_id = 1)) |
| -> Bitmap Heap Scan on tbl_clients c (cost=14.46..108.61 rows=58 width=69) |
| Recheck Cond: (sales_rep = 1001) |
| Filter: (NOT deleted) |
| -> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.78 rows=67 width=0) |
| Index Cond: (sales_rep = 1001) |
| -> Hash (cost=248.53..248.53 rows=200 width=144) |
| -> Subquery Scan on tmp1 (cost=242.53..248.53 rows=200 width=144) |
| -> HashAggregate (cost=242.53..246.53 rows=200 width=144) |
| Group Key: p.used_client |
| -> HashAggregate (cost=227.68..231.39 rows=297 width=58) |
| Group Key: p.id, ps.id |
| -> Hash Right Join (cost=204.92..225.45 rows=297 width=58) |
| Hash Cond: (pucp.project_used_client_id = p.id) |
| -> Seq Scan on tbl_project_used_client_payments pucp (cost=0.00..15.50 rows=550 width=36) |
| -> Hash (cost=202.78..202.78 rows=171 width=26) |
| -> Hash Join (cost=9.13..202.78 rows=171 width=26) |
| Hash Cond: (ps.id = p.project_id) |
| -> Seq Scan on tbl_projects ps (cost=0.00..185.55 rows=1703 width=8) |
| Filter: (project_status = 3) |
| -> Hash (cost=5.17..5.17 rows=317 width=22) |
| -> Seq Scan on tbl_project_used_clients p (cost=0.00..5.17 rows=317 width=22) |
| -> Hash (cost=246.31..246.31 rows=200 width=68) |
| -> Subquery Scan on tmp10 (cost=241.31..246.31 rows=200 width=68) |
| -> HashAggregate (cost=241.31..244.31 rows=200 width=68) |
| Group Key: sc.used_client |
| -> HashAggregate (cost=230.21..234.17 rows=317 width=46) |
| Group Key: sc.id |
| -> Hash Right Join (cost=204.92..228.32 rows=378 width=46) |
| Hash Cond: (sci.project_used_client_id = sc.id) |
| -> Seq Scan on tbl_project_used_client_invoices sci (cost=0.00..17.00 rows=700 width=36) |
| -> Hash (cost=202.78..202.78 rows=171 width=14) |
| -> Hash Join (cost=9.13..202.78 rows=171 width=14) |
| Hash Cond: (ps_1.id = sc.project_id) |
| -> Seq Scan on tbl_projects ps_1 (cost=0.00..185.55 rows=1703 width=4) |
| Filter: (project_status = 3) |
| -> Hash (cost=5.17..5.17 rows=317 width=18) |
| -> Seq Scan on tbl_project_used_clients sc (cost=0.00..5.17 rows=317 width=18) |
| -> Hash (cost=7.76..7.76 rows=50 width=12) |
| -> Subquery Scan on tmp11 (cost=6.76..7.76 rows=50 width=12) |
| -> HashAggregate (cost=6.76..7.26 rows=50 width=44) |
| Group Key: sc_1.used_client |
| -> Seq Scan on tbl_project_used_clients sc_1 (cost=0.00..5.17 rows=317 width=8) |
| -> GroupAggregate (cost=191.77..191.82 rows=2 width=44) |
| Group Key: p_1.used_client |
| -> Sort (cost=191.77..191.78 rows=2 width=14) |
| Sort Key: p_1.used_client |
| -> Hash Join (cost=185.76..191.76 rows=2 width=14) |
| Hash Cond: (p_1.project_id = ps_2.id) |
| -> Seq Scan on tbl_project_used_clients p_1 (cost=0.00..5.17 rows=317 width=18) |
| -> Hash (cost=185.55..185.55 rows=17 width=4) |
| -> Seq Scan on tbl_projects ps_2 (cost=0.00..185.55 rows=17 width=4) |
| Filter: (project_status = 1) |
| -> GroupAggregate (cost=192.22..192.34 rows=5 width=44) |
| Group Key: p_2.used_client |
| -> Sort (cost=192.22..192.24 rows=5 width=14) |
| Sort Key: p_2.used_client |
| -> Hash Join (cost=186.16..192.16 rows=5 width=14) |
| Hash Cond: (p_2.project_id = ps_3.id) |
| -> Seq Scan on tbl_project_used_clients p_2 (cost=0.00..5.17 rows=317 width=18) |
| -> Hash (cost=185.55..185.55 rows=49 width=4) |
| -> Seq Scan on tbl_projects ps_3 (cost=0.00..185.55 rows=49 width=4) |
| Filter: (project_status = 2) |
| -> GroupAggregate (cost=199.33..200.27 rows=46 width=44) |
| Group Key: puc.used_client |
| -> Sort (cost=199.33..199.45 rows=48 width=10) |
| Sort Key: puc.used_client |
| -> Hash Join (cost=6.48..197.99 rows=48 width=10) |
| Hash Cond: (p_3.id = puc.project_id) |
| -> Seq Scan on tbl_projects p_3 (cost=0.00..185.55 rows=1461 width=4) |
| Filter: (project_status <> 3) |
| -> Hash (cost=5.17..5.17 rows=105 width=14) |
| -> Seq Scan on tbl_project_used_clients puc (cost=0.00..5.17 rows=105 width=14) |
| Filter: (used_client IS NOT NULL) |
| -> Hash (cost=1.25..1.25 rows=25 width=150) |
| -> Seq Scan on tbl_client_industries ci (cost=0.00..1.25 rows=25 width=150) |
| -> Hash (cost=200.29..200.29 rows=2 width=68) |
| -> Subquery Scan on tmp13 (cost=200.22..200.29 rows=2 width=68) |
| -> GroupAggregate (cost=200.22..200.27 rows=2 width=68) |
| Group Key: puc_1.used_client |
| -> Sort (cost=200.22..200.22 rows=2 width=14) |
| Sort Key: puc_1.used_client |
| -> Hash Join (cost=6.48..200.21 rows=2 width=14) |
| Hash Cond: (p_4.id = puc_1.project_id) |
| -> Seq Scan on tbl_projects p_4 (cost=0.00..193.46 rows=66 width=4) |
| Filter: ((project_status = 1) OR (project_status = 2)) |
| -> Hash (cost=5.17..5.17 rows=105 width=18) |
| -> Seq Scan on tbl_project_used_clients puc_1 (cost=0.00..5.17 rows=105 width=18) |
| Filter: (used_client IS NOT NULL) |
| -> Hash (cost=1.06..1.06 rows=6 width=150) |
| -> Seq Scan on tbl_client_types ct (cost=0.00..1.06 rows=6 width=150) |
| -> Hash (cost=1.27..1.27 rows=27 width=4) |
| -> Seq Scan on tbl_engineer_group_relationships egr (cost=0.00..1.27 rows=27 width=4) |