QUERY PLAN
Aggregate (cost=508.00..508.01 rows=1 width=8)
-> Sort (cost=507.97..507.97 rows=2 width=870)
Sort Key: p.bargain_date DESC, p.updated_at DESC
-> Hash Left Join (cost=465.15..507.96 rows=2 width=870)
Hash Cond: (p.client_id = c.id)
Filter: (((c.name)::text ~~* '%爱慕%'::text) OR (c.pinyin_shortcut ~~* '%爱慕%'::text) OR (p.pinyin_shortcut ~~* '%爱慕%'::text) OR ((p.project_title)::text ~~* '%爱慕%'::text) OR ((u2.name)::text ~~* '%爱慕%'::text))
-> Hash Left Join (cost=329.85..368.20 rows=1691 width=56)
Hash Cond: ((CASE WHEN (pd.user_id IS NOT NULL) THEN pd.user_id ELSE p.created_by END) = u2.id)
-> HashAggregate (cost=311.61..328.52 rows=1691 width=567)
Group Key: p.id, pd.user_id, pd.pct
-> Hash Left Join (cost=219.53..298.93 rows=1691 width=91)
Hash Cond: (p.id = pd.project_id)
-> Hash Right Join (cost=205.41..278.47 rows=1691 width=55)
Hash Cond: (sc.from_project = p.id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..68.46 rows=1746 width=4)
-> Hash (cost=184.28..184.28 rows=1691 width=55)
-> Seq Scan on tbl_projects p (cost=0.00..184.28 rows=1691 width=55)
Filter: (project_status = 3)
-> Hash (cost=14.10..14.10 rows=1 width=40)
-> Subquery Scan on pd (cost=14.06..14.10 rows=1 width=40)
-> GroupAggregate (cost=14.06..14.09 rows=1 width=40)
Group Key: t.project_id, r.user_id
-> Sort (cost=14.06..14.07 rows=1 width=13)
Sort Key: t.project_id, r.user_id
-> Nested Loop Left Join (cost=0.00..14.05 rows=1 width=13)
Join Filter: (t.id = r.erp_profit_distribute_id)
-> Seq Scan on tbl_erp_profit_distributes t (cost=0.00..12.88 rows=1 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Seq Scan on tbl_erp_profit_distribute_pcts r (cost=0.00..1.08 rows=8 width=13)
-> Hash (cost=16.44..16.44 rows=144 width=13)
-> Seq Scan on tbl_users u2 (cost=0.00..16.44 rows=144 width=13)
-> Hash (cost=110.13..110.13 rows=2013 width=59)
-> Seq Scan on tbl_clients c (cost=0.00..110.13 rows=2013 width=59)