Aggregate (cost=54619.55..54619.56 rows=1 width=128) |
-> Sort (cost=54584.57..54588.06 rows=1399 width=697) |
Sort Key: sc.signed_at DESC |
-> Group (cost=54466.00..54511.47 rows=1399 width=697) |
Group Key: sc.id, scp.collected, sci.invoiced, (max((SubPlan 1))), (max((CASE WHEN (scp_1.collected IS NOT NULL) THEN scp_1.collected ELSE '0'::numeric END))), (max(scpcrd.remind_date)), (CASE WHEN ((sc.amount - scp.collected) > '0'::numeric) THEN CASE WHEN (((max((SubPlan 1))) - (max((CASE WHEN (scp_1.collected IS NOT NULL) THEN scp_1.collected ELSE '0'::numeric END)))) > '0'::numeric) THEN (max(scpcrd_2.remind_date)) ELSE (min(scpcrd_1.remind_date)) END ELSE NULL::date END), (COALESCE(sum(r.amount), '0'::numeric)) |
-> Sort (cost=54466.00..54469.50 rows=1399 width=182) |
Sort Key: sc.id, scp.collected, sci.invoiced, (max((SubPlan 1))), (max((CASE WHEN (scp_1.collected IS NOT NULL) THEN scp_1.collected ELSE '0'::numeric END))), (max(scpcrd.remind_date)), (CASE WHEN ((sc.amount - scp.collected) > '0'::numeric) THEN CASE WHEN (((max((SubPlan 1))) - (max((CASE WHEN (scp_1.collected IS NOT NULL) THEN scp_1.collected ELSE '0'::numeric END)))) > '0'::numeric) THEN (max(scpcrd_2.remind_date)) ELSE (min(scpcrd_1.remind_date)) END ELSE NULL::date END), (COALESCE(sum(r.amount), '0'::numeric)) |
-> Merge Left Join (cost=2985.22..54392.90 rows=1399 width=182) |
Merge Cond: (sc.id = sc_3.id) |
-> Merge Left Join (cost=2658.88..32020.35 rows=1399 width=182) |
Merge Cond: (sc.id = sc_2.id) |
-> Merge Left Join (cost=2290.90..31648.77 rows=1399 width=178) |
Merge Cond: (sc.id = sc_1.id) |
-> Merge Left Join (cost=1964.57..1971.68 rows=1399 width=110) |
Merge Cond: (sc.id = r.purchase_contract_id) |
-> Sort (cost=741.37..744.87 rows=1399 width=78) |
Sort Key: sc.id |
-> Hash Left Join (cost=616.45..668.27 rows=1399 width=78) |
Hash Cond: (sc.id = sci.contract_id) |
-> Hash Left Join (cost=362.36..410.50 rows=1399 width=46) |
Hash Cond: (sc.id = scp.contract_id) |
-> Hash Join (cost=140.58..185.04 rows=1399 width=14) |
Hash Cond: (sc.supplier_id = c.id) |
-> Hash Right Join (cost=107.08..146.45 rows=1923 width=18) |
Hash Cond: (scp2.contract_id = sc.id) |
-> Seq Scan on tbl_purchase_contract_payments scp2 (cost=0.00..34.30 rows=1930 width=4) |
-> Hash (cost=83.74..83.74 rows=1867 width=18) |
-> Seq Scan on tbl_purchase_contracts sc (cost=0.00..83.74 rows=1867 width=18) |
Filter: (NOT is_chargeback) |
-> Hash (cost=28.24..28.24 rows=421 width=4) |
-> Seq Scan on tbl_suppliers c (cost=0.00..28.24 rows=421 width=4) |
Filter: ((name)::text ~~* '%北京%'::text) |
-> Hash (cost=198.36..198.36 rows=1874 width=36) |
-> Subquery Scan on scp (cost=156.19..198.36 rows=1874 width=36) |
-> HashAggregate (cost=156.19..179.62 rows=1874 width=36) |
Group Key: t0.id |
-> Hash Right Join (cost=107.17..146.54 rows=1930 width=10) |
Hash Cond: (t1.contract_id = t0.id) |
-> Seq Scan on tbl_purchase_contract_payments t1 (cost=0.00..34.30 rows=1930 width=10) |
-> Hash (cost=83.74..83.74 rows=1874 width=4) |
-> Seq Scan on tbl_purchase_contracts t0 (cost=0.00..83.74 rows=1874 width=4) |
-> Hash (cost=230.66..230.66 rows=1874 width=36) |
-> Subquery Scan on sci (cost=188.50..230.66 rows=1874 width=36) |
-> HashAggregate (cost=188.50..211.92 rows=1874 width=36) |
Group Key: t0_1.id |
-> Hash Right Join (cost=107.17..178.48 rows=2004 width=10) |
Hash Cond: (t1_1.contract_id = t0_1.id) |
-> Seq Scan on tbl_purchase_contract_invoices t1_1 (cost=0.00..66.04 rows=2004 width=10) |
-> Hash (cost=83.74..83.74 rows=1874 width=4) |
-> Seq Scan on tbl_purchase_contracts t0_1 (cost=0.00..83.74 rows=1874 width=4) |
-> GroupAggregate (cost=1223.19..1223.25 rows=3 width=36) |
Group Key: r.purchase_contract_id |
-> Sort (cost=1223.19..1223.20 rows=3 width=10) |
Sort Key: r.purchase_contract_id |
-> Nested Loop (cost=0.28..1223.17 rows=3 width=10) |
-> Seq Scan on tbl_term_taxonomy_relationships dt1 (cost=0.00..1147.89 rows=11 width=4) |
Filter: ((term_id = 17) AND (taxonomy_id = 2100000000)) |
-> Index Scan using tbl_approves_pkey on tbl_approves r (cost=0.28..6.84 rows=1 width=14) |
Index Cond: (id = dt1.object_id) |
Filter: (status = 2) |
-> GroupAggregate (cost=326.34..29669.60 rows=200 width=72) |
Group Key: sc_1.id |
-> Merge Join (cost=326.34..22345.58 rows=698 width=44) |
Merge Cond: (sc_1.id = scpcrd.contract_id) |
Join Filter: ((CASE WHEN (scp_1.collected IS NOT NULL) THEN scp_1.collected ELSE '0'::numeric END) < (SubPlan 2)) |
-> Group (cost=298.19..312.25 rows=1874 width=487) |
Group Key: sc_1.id, scp_1.collected |
-> Sort (cost=298.19..302.88 rows=1874 width=36) |
Sort Key: sc_1.id, scp_1.collected |
-> Hash Left Join (cost=107.65..196.32 rows=1874 width=36) |
Hash Cond: (sc_1.id = scp_1.contract_id) |
-> Seq Scan on tbl_purchase_contracts sc_1 (cost=0.00..83.74 rows=1874 width=4) |
-> Hash (cost=84.90..84.90 rows=1820 width=36) |
-> Subquery Scan on scp_1 (cost=43.95..84.90 rows=1820 width=36) |
-> HashAggregate (cost=43.95..66.70 rows=1820 width=36) |
Group Key: tbl_purchase_contract_payments.contract_id |
-> Seq Scan on tbl_purchase_contract_payments (cost=0.00..34.30 rows=1930 width=10) |
-> Sort (cost=28.15..29.22 rows=429 width=8) |
Sort Key: scpcrd.contract_id |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrd (cost=0.00..9.39 rows=429 width=8) |
Filter: (remind_date <= '2025-07-03'::date) |
SubPlan 2 |
-> Aggregate (cost=10.47..10.48 rows=1 width=32) |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrdsub_1 (cost=0.00..10.46 rows=1 width=6) |
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id)) |
SubPlan 1 |
-> Aggregate (cost=10.47..10.48 rows=1 width=32) |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrdsub (cost=0.00..10.46 rows=1 width=6) |
Filter: ((remind_date <= scpcrd.remind_date) AND (contract_id = scpcrd.contract_id)) |
-> GroupAggregate (cost=367.98..368.03 rows=3 width=8) |
Group Key: sc_2.id |
-> Sort (cost=367.98..367.99 rows=3 width=8) |
Sort Key: sc_2.id |
-> Hash Join (cost=216.18..367.96 rows=3 width=8) |
Hash Cond: (sc_2.id = scpcrd_1.contract_id) |
Join Filter: ((CASE WHEN (scp_2.collected IS NOT NULL) THEN scp_2.collected ELSE '0'::numeric END) < (SubPlan 3)) |
-> HashAggregate (cost=205.69..224.43 rows=1874 width=487) |
Group Key: sc_2.id, scp_2.collected |
-> Hash Left Join (cost=107.65..196.32 rows=1874 width=36) |
Hash Cond: (sc_2.id = scp_2.contract_id) |
-> Seq Scan on tbl_purchase_contracts sc_2 (cost=0.00..83.74 rows=1874 width=4) |
-> Hash (cost=84.90..84.90 rows=1820 width=36) |
-> Subquery Scan on scp_2 (cost=43.95..84.90 rows=1820 width=36) |
-> HashAggregate (cost=43.95..66.70 rows=1820 width=36) |
Group Key: tbl_purchase_contract_payments_1.contract_id |
-> Seq Scan on tbl_purchase_contract_payments tbl_purchase_contract_payments_1 (cost=0.00..34.30 rows=1930 width=10) |
-> Hash (cost=10.46..10.46 rows=2 width=8) |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrd_1 (cost=0.00..10.46 rows=2 width=8) |
Filter: (remind_date > now()) |
SubPlan 3 |
-> Aggregate (cost=10.47..10.48 rows=1 width=32) |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrdsub_2 (cost=0.00..10.46 rows=1 width=6) |
Filter: ((remind_date <= scpcrd_1.remind_date) AND (contract_id = scpcrd_1.contract_id)) |
-> GroupAggregate (cost=326.34..22351.07 rows=200 width=8) |
Group Key: sc_3.id |
-> Merge Join (cost=326.34..22345.58 rows=698 width=8) |
Merge Cond: (sc_3.id = scpcrd_2.contract_id) |
Join Filter: ((CASE WHEN (scp_3.collected IS NOT NULL) THEN scp_3.collected ELSE '0'::numeric END) < (SubPlan 4)) |
-> Group (cost=298.19..312.25 rows=1874 width=487) |
Group Key: sc_3.id, scp_3.collected |
-> Sort (cost=298.19..302.88 rows=1874 width=36) |
Sort Key: sc_3.id, scp_3.collected |
-> Hash Left Join (cost=107.65..196.32 rows=1874 width=36) |
Hash Cond: (sc_3.id = scp_3.contract_id) |
-> Seq Scan on tbl_purchase_contracts sc_3 (cost=0.00..83.74 rows=1874 width=4) |
-> Hash (cost=84.90..84.90 rows=1820 width=36) |
-> Subquery Scan on scp_3 (cost=43.95..84.90 rows=1820 width=36) |
-> HashAggregate (cost=43.95..66.70 rows=1820 width=36) |
Group Key: tbl_purchase_contract_payments_2.contract_id |
-> Seq Scan on tbl_purchase_contract_payments tbl_purchase_contract_payments_2 (cost=0.00..34.30 rows=1930 width=10) |
-> Sort (cost=28.15..29.22 rows=429 width=8) |
Sort Key: scpcrd_2.contract_id |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrd_2 (cost=0.00..9.39 rows=429 width=8) |
Filter: (remind_date <= '2025-07-03'::date) |
SubPlan 4 |
-> Aggregate (cost=10.47..10.48 rows=1 width=32) |
-> Seq Scan on tbl_purchase_contract_payment_collection_remind_dates scpcrdsub_3 (cost=0.00..10.46 rows=1 width=6) |
Filter: ((remind_date <= scpcrd_2.remind_date) AND (contract_id = scpcrd_2.contract_id)) |