QUERY PLAN
Aggregate (cost=627.87..627.88 rows=1 width=8)
-> Sort (cost=619.25..620.69 rows=575 width=726)
Sort Key: p.bargain_date DESC, p.updated_at DESC
-> Hash Left Join (cost=552.83..592.89 rows=575 width=726)
Hash Cond: (p.client_id = c.id)
Filter: (((c.name)::text ~~* '%33%'::text) OR (c.pinyin_shortcut ~~* '%33%'::text) OR (p.pinyin_shortcut ~~* '%33%'::text) OR ((p.project_title)::text ~~* '%33%'::text) OR (p.budget = '33'::numeric) OR ((u2.name)::text ~~* '%33%'::text))
-> Hash Left Join (cost=350.38..386.26 rows=1582 width=61)
Hash Cond: ((CASE WHEN (r.user_id IS NOT NULL) THEN r.user_id ELSE p.created_by END) = u2.id)
-> HashAggregate (cost=341.21..357.03 rows=1582 width=396)
Group Key: p.id, r.user_id, (sum(r.pct))
-> Hash Right Join (cost=310.15..329.35 rows=1582 width=96)
Hash Cond: (t.project_id = p.id)
-> HashAggregate (cost=25.64..33.23 rows=607 width=40)
Group Key: t.project_id, r.user_id
-> Hash Right Join (cost=1.20..21.09 rows=607 width=40)
Hash Cond: (r.erp_profit_distribute_id = t.id)
-> Seq Scan on tbl_erp_profit_distribute_pcts r (cost=0.00..17.80 rows=780 width=40)
-> Hash (cost=1.11..1.11 rows=7 width=8)
-> Seq Scan on tbl_erp_profit_distributes t (cost=0.00..1.11 rows=7 width=8)
Filter: ((project_id IS NOT NULL) AND (status = 2))
-> Hash (cost=264.73..264.73 rows=1582 width=60)
-> Hash Right Join (cost=196.62..264.73 rows=1582 width=60)
Hash Cond: (sc.from_project = p.id)
-> Seq Scan on tbl_sales_contracts sc (cost=0.00..63.71 rows=1671 width=4)
-> Hash (cost=176.85..176.85 rows=1582 width=60)
-> Seq Scan on tbl_projects p (cost=0.00..176.85 rows=1582 width=60)
Filter: (project_status = 3)
-> Hash (cost=7.41..7.41 rows=141 width=13)
-> Seq Scan on tbl_users u2 (cost=0.00..7.41 rows=141 width=13)
-> Hash (cost=178.31..178.31 rows=1931 width=59)
-> Seq Scan on tbl_clients c (cost=0.00..178.31 rows=1931 width=59)