| Aggregate (cost=784.42..784.43 rows=1 width=32) |
| -> Group (cost=784.24..784.30 rows=9 width=42) |
| Group Key: sc.id2, tbl_sales_contracts.erp_settle_amount |
| -> Sort (cost=784.24..784.26 rows=9 width=10) |
| Sort Key: sc.id2, tbl_sales_contracts.erp_settle_amount |
| -> Hash Right Join (cost=743.04..784.09 rows=9 width=10) |
| Hash Cond: (tbl_sales_contracts.id = sc.id2) |
| -> HashAggregate (cost=122.56..139.81 rows=1725 width=10) |
| Group Key: tbl_sales_contracts.id |
| -> Seq Scan on tbl_sales_contracts (cost=0.00..118.25 rows=1725 width=10) |
| -> Hash (cost=620.46..620.46 rows=1 width=4) |
| -> Subquery Scan on sc (cost=620.45..620.46 rows=1 width=4) |
| -> Sort (cost=620.45..620.45 rows=1 width=571) |
| Sort Key: (CASE WHEN (scpcrds.id IS NOT NULL) THEN scpcrds.remind_date ELSE sc_1.signed_at END) DESC |
| -> Hash Left Join (cost=500.27..620.44 rows=1 width=571) |
| Hash Cond: (sc_1.id = scpcrds.contract_id) |
| Filter: (((scpcrds.id IS NOT NULL) AND (scpcrds.paid_amount <> '0'::numeric)) OR ((scpcrds.id IS NULL) AND (sc_1.erp_settle_amount > '0'::numeric))) |
| -> Nested Loop (cost=99.40..219.47 rows=1 width=14) |
| -> Hash Join (cost=99.40..217.69 rows=1 width=18) |
| Hash Cond: (sc_1.client_id = c.id) |
| -> Seq Scan on tbl_sales_contracts sc_1 (cost=0.00..118.25 rows=17 width=22) |
| Filter: (build_by_project AND (NOT need_analysis)) |
| -> Hash (cost=98.78..98.78 rows=50 width=8) |
| -> Bitmap Heap Scan on tbl_clients c (cost=4.79..98.78 rows=50 width=8) |
| Recheck Cond: (sales_rep = 1001) |
| -> Bitmap Index Scan on tbl_clients_sales_rep_idx (cost=0.00..4.78 rows=67 width=0) |
| Index Cond: (sales_rep = 1001) |
| -> 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)) |
| -> Hash (cost=393.04..393.04 rows=626 width=18) |
| -> Subquery Scan on scpcrds (cost=380.52..393.04 rows=626 width=18) |
| -> HashAggregate (cost=380.52..386.78 rows=626 width=67) |
| Group Key: t0.id |
| -> Hash Join (cost=180.87..378.96 rows=626 width=18) |
| Hash Cond: (p.id = t1.from_project) |
| -> Seq Scan on tbl_projects p (cost=0.00..185.55 rows=1703 width=4) |
| Filter: (project_status = 3) |
| -> Hash (cost=166.34..166.34 rows=1163 width=22) |
| -> Hash Join (cost=139.24..166.34 rows=1163 width=22) |
| Hash Cond: (t0.contract_id = t1.id) |
| -> Seq Scan on tbl_sales_contract_payment_collection_remind_dates t0 (cost=0.00..23.95 rows=1195 width=18) |
| -> Hash (cost=118.25..118.25 rows=1679 width=8) |
| -> Seq Scan on tbl_sales_contracts t1 (cost=0.00..118.25 rows=1679 width=8) |
| Filter: (need_analysis AND (from_project IS NOT NULL)) |