QUERY PLAN
Limit (cost=675.26..675.27 rows=4 width=452)
-> Sort (cost=675.26..675.27 rows=4 width=452)
Sort Key: "*SELECT* 1".updated_at DESC
-> Append (cost=267.46..675.18 rows=4 width=452)
-> Subquery Scan on "*SELECT* 1" (cost=267.46..275.57 rows=1 width=443)
-> GroupAggregate (cost=267.46..275.56 rows=1 width=387)
Group Key: s.id
-> Nested Loop Left Join (cost=267.46..275.45 rows=1 width=343)
Join Filter: (t_5.client_id = s.id)
-> Nested Loop Left Join (cost=144.45..150.48 rows=1 width=303)
Join Filter: (t_4.client_id = s.id)
-> Nested Loop Left Join (cost=139.51..143.59 rows=1 width=239)
Join Filter: ("*SELECT* 1_1".client_id = s.id)
-> Nested Loop Left Join (cost=135.33..135.73 rows=1 width=175)
Join Filter: (t_1.client_id = s.id)
-> Merge Left Join (cost=132.26..132.28 rows=1 width=111)
Merge Cond: (s.id = ap.client_id)
-> Sort (cost=120.20..120.21 rows=1 width=79)
Sort Key: s.id
-> Seq Scan on tbl_clients s (cost=0.00..120.19 rows=1 width=79)
Filter: ((NOT deleted) AND (((name)::text ~~* '%bjhl%'::text) OR (pinyin_shortcut ~~* '%bjhl%'::text)))
-> Sort (cost=12.05..12.06 rows=1 width=36)
Sort Key: ap.client_id
-> Subquery Scan on ap (cost=12.01..12.04 rows=1 width=36)
-> GroupAggregate (cost=12.01..12.04 rows=1 width=40)
Group Key: t.supplier_id, t.client_id
-> Sort (cost=12.01..12.02 rows=1 width=40)
Sort Key: t.supplier_id, t.client_id
-> Seq Scan on tbl_erp_advance_payment_tickets t (cost=0.00..12.00 rows=1 width=40)
Filter: (is_payment_settle AND (status = 2))
-> HashAggregate (cost=3.07..3.22 rows=10 width=80)
Group Key: t_1.supplier_id, t_1.client_id, t_1.user_id, t_1.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_1 (cost=0.00..2.55 rows=35 width=25)
Filter: ((bank_settle_at IS NOT NULL) AND (status = 2))
-> Append (cost=4.18..7.50 rows=29 width=68)
-> Subquery Scan on "*SELECT* 1_1" (cost=4.18..4.83 rows=26 width=68)
-> HashAggregate (cost=4.18..4.57 rows=26 width=80)
Group Key: t_2.supplier_id, t_2.client_id, t_2.user_id, t_2.contact_id
-> Seq Scan on tbl_erp_other_payment_tickets t_2 (cost=0.00..3.55 rows=42 width=26)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 2_1" (cost=2.60..2.67 rows=3 width=68)
-> HashAggregate (cost=2.60..2.64 rows=3 width=80)
Group Key: t_3.supplier_id, t_3.client_id, t_3.user_id, t_3.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_3 (cost=0.00..2.55 rows=4 width=21)
Filter: ((bank_settle_at IS NULL) AND (status = 2))
-> HashAggregate (cost=4.94..5.72 rows=52 width=76)
Group Key: t_4.supplier_id, t_4.client_id, t_4.contact_id
-> Seq Scan on tbl_erp_cost_tickets t_4 (cost=0.00..4.03 rows=73 width=21)
Filter: (status = 2)
-> HashAggregate (cost=123.01..123.71 rows=56 width=44)
Group Key: t_5.client_id
-> Seq Scan on tbl_sales_contracts t_5 (cost=0.00..122.56 rows=60 width=7)
Filter: (build_by_project AND (client_id IS NOT NULL) AND (erp_un_settle_amount <> '0'::numeric))
-> Subquery Scan on "*SELECT* 2" (cost=180.94..189.22 rows=1 width=440)
-> GroupAggregate (cost=180.94..189.20 rows=1 width=384)
Group Key: s_1.id
-> Nested Loop Left Join (cost=180.94..189.10 rows=1 width=336)
Join Filter: (t_11.supplier_id = s_1.id)
-> Nested Loop Left Join (cost=57.07..63.13 rows=1 width=296)
Join Filter: (t_10.supplier_id = s_1.id)
-> Nested Loop Left Join (cost=52.13..56.24 rows=1 width=232)
Join Filter: ("*SELECT* 1_2".supplier_id = s_1.id)
-> Nested Loop Left Join (cost=47.95..48.38 rows=1 width=168)
Join Filter: (t_7.supplier_id = s_1.id)
-> Merge Left Join (cost=44.88..44.93 rows=1 width=104)
Merge Cond: (s_1.id = t_6.supplier_id)
-> Sort (cost=32.87..32.87 rows=1 width=72)
Sort Key: s_1.id
-> Seq Scan on tbl_suppliers s_1 (cost=0.00..32.86 rows=1 width=72)
Filter: (((name)::text ~~* '%bjhl%'::text) OR (pinyin_shortcut ~~* '%bjhl%'::text))
-> Materialize (cost=12.01..12.05 rows=1 width=36)
-> GroupAggregate (cost=12.01..12.04 rows=1 width=40)
Group Key: t_6.supplier_id, t_6.client_id
-> Sort (cost=12.01..12.02 rows=1 width=40)
Sort Key: t_6.supplier_id, t_6.client_id
-> Seq Scan on tbl_erp_advance_payment_tickets t_6 (cost=0.00..12.00 rows=1 width=40)
Filter: (is_payment_settle AND (status = 2))
-> HashAggregate (cost=3.07..3.22 rows=10 width=80)
Group Key: t_7.supplier_id, t_7.client_id, t_7.user_id, t_7.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_7 (cost=0.00..2.55 rows=35 width=25)
Filter: ((bank_settle_at IS NOT NULL) AND (status = 2))
-> Append (cost=4.18..7.50 rows=29 width=68)
-> Subquery Scan on "*SELECT* 1_2" (cost=4.18..4.83 rows=26 width=68)
-> HashAggregate (cost=4.18..4.57 rows=26 width=80)
Group Key: t_8.supplier_id, t_8.client_id, t_8.user_id, t_8.contact_id
-> Seq Scan on tbl_erp_other_payment_tickets t_8 (cost=0.00..3.55 rows=42 width=26)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 2_2" (cost=2.60..2.67 rows=3 width=68)
-> HashAggregate (cost=2.60..2.64 rows=3 width=80)
Group Key: t_9.supplier_id, t_9.client_id, t_9.user_id, t_9.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_9 (cost=0.00..2.55 rows=4 width=21)
Filter: ((bank_settle_at IS NULL) AND (status = 2))
-> HashAggregate (cost=4.94..5.72 rows=52 width=76)
Group Key: t_10.supplier_id, t_10.client_id, t_10.contact_id
-> Seq Scan on tbl_erp_cost_tickets t_10 (cost=0.00..4.03 rows=73 width=21)
Filter: (status = 2)
-> HashAggregate (cost=123.87..124.62 rows=60 width=44)
Group Key: t_11.supplier_id
-> Seq Scan on tbl_purchase_contracts t_11 (cost=0.00..123.40 rows=63 width=7)
Filter: ((NOT is_draft) AND (NOT is_refuse) AND (supplier_id IS NOT NULL) AND (NOT is_draft) AND (NOT is_refuse) AND (erp_un_settle_amount <> '0'::numeric))
-> Subquery Scan on "*SELECT* 3" (cost=28.14..28.22 rows=1 width=400)
-> GroupAggregate (cost=28.14..28.20 rows=1 width=288)
Group Key: u.id
-> Sort (cost=28.14..28.15 rows=1 width=160)
Sort Key: u.id
-> Hash Right Join (cost=27.83..28.13 rows=1 width=160)
Hash Cond: (t_12.user_id = u.id)
Filter: ((t_12.user_id IS NOT NULL) OR ("*SELECT* 1_3".user_id IS NOT NULL))
-> HashAggregate (cost=3.07..3.22 rows=10 width=80)
Group Key: t_12.supplier_id, t_12.client_id, t_12.user_id, t_12.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_12 (cost=0.00..2.55 rows=35 width=25)
Filter: ((bank_settle_at IS NOT NULL) AND (status = 2))
-> Hash (cost=24.75..24.75 rows=1 width=100)
-> Hash Right Join (cost=21.35..24.75 rows=1 width=100)
Hash Cond: ("*SELECT* 1_3".user_id = u.id)
-> Append (cost=4.18..7.50 rows=29 width=68)
-> Subquery Scan on "*SELECT* 1_3" (cost=4.18..4.83 rows=26 width=68)
-> HashAggregate (cost=4.18..4.57 rows=26 width=80)
Group Key: t_13.supplier_id, t_13.client_id, t_13.user_id, t_13.contact_id
-> Seq Scan on tbl_erp_other_payment_tickets t_13 (cost=0.00..3.55 rows=42 width=26)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 2_3" (cost=2.60..2.67 rows=3 width=68)
-> HashAggregate (cost=2.60..2.64 rows=3 width=80)
Group Key: t_14.supplier_id, t_14.client_id, t_14.user_id, t_14.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_14 (cost=0.00..2.55 rows=4 width=21)
Filter: ((bank_settle_at IS NULL) AND (status = 2))
-> Hash (cost=17.16..17.16 rows=1 width=32)
-> Seq Scan on tbl_users u (cost=0.00..17.16 rows=1 width=32)
Filter: (((name)::text ~~* '%bjhl%'::text) OR (pinyin_shortcut ~~* '%bjhl%'::text))
-> Subquery Scan on "*SELECT* 4" (cost=176.38..182.17 rows=1 width=400)
-> GroupAggregate (cost=176.38..182.15 rows=1 width=288)
Group Key: co.id
-> Nested Loop Left Join (cost=176.38..182.08 rows=1 width=224)
Join Filter: (t_18.contact_id = co.id)
-> Nested Loop Left Join (cost=171.44..175.19 rows=1 width=160)
Join Filter: ("*SELECT* 1_4".contact_id = co.id)
Filter: ((oc.contact_id IS NOT NULL) OR ("*SELECT* 1_4".contact_id IS NOT NULL))
-> Merge Left Join (cost=167.26..167.33 rows=1 width=100)
Merge Cond: (co.id = oc.contact_id)
-> Sort (cost=163.77..163.77 rows=1 width=32)
Sort Key: co.id
-> Seq Scan on tbl_contacts co (cost=0.00..163.76 rows=1 width=32)
Filter: (((name)::text ~~* '%bjhl%'::text) OR (pinyin_shortcut ~~* '%bjhl%'::text))
-> Sort (cost=3.49..3.52 rows=10 width=68)
Sort Key: oc.contact_id
-> Subquery Scan on oc (cost=3.07..3.32 rows=10 width=68)
-> HashAggregate (cost=3.07..3.22 rows=10 width=80)
Group Key: t_15.supplier_id, t_15.client_id, t_15.user_id, t_15.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_15 (cost=0.00..2.55 rows=35 width=25)
Filter: ((bank_settle_at IS NOT NULL) AND (status = 2))
-> Append (cost=4.18..7.50 rows=29 width=68)
-> Subquery Scan on "*SELECT* 1_4" (cost=4.18..4.83 rows=26 width=68)
-> HashAggregate (cost=4.18..4.57 rows=26 width=80)
Group Key: t_16.supplier_id, t_16.client_id, t_16.user_id, t_16.contact_id
-> Seq Scan on tbl_erp_other_payment_tickets t_16 (cost=0.00..3.55 rows=42 width=26)
Filter: (status = 2)
-> Subquery Scan on "*SELECT* 2_4" (cost=2.60..2.67 rows=3 width=68)
-> HashAggregate (cost=2.60..2.64 rows=3 width=80)
Group Key: t_17.supplier_id, t_17.client_id, t_17.user_id, t_17.contact_id
-> Seq Scan on tbl_erp_other_collect_tickets t_17 (cost=0.00..2.55 rows=4 width=21)
Filter: ((bank_settle_at IS NULL) AND (status = 2))
-> HashAggregate (cost=4.94..5.72 rows=52 width=76)
Group Key: t_18.supplier_id, t_18.client_id, t_18.contact_id
-> Seq Scan on tbl_erp_cost_tickets t_18 (cost=0.00..4.03 rows=73 width=21)
Filter: (status = 2)