QUERY PLAN
Limit (cost=143.98..146.33 rows=20 width=784)
-> Unique (cost=143.98..155.73 rows=100 width=784)
-> Sort (cost=143.98..144.23 rows=100 width=784)
Sort Key: s.updated_at DESC, s.id, s.sales_order_id, s.product_id, s.parent, s.sn, s.supplier_id, s."order", s.created_by, s.created_at, s.pn, s.product_type, s.product_component, s.product_brand, s.product_serie, s.product_misc, s.hardware_from, s.software_from, s.maintenance_from, s.hardware_to, s.software_to, s.maintenance_to, s.new_hardware_deadline, s.new_software_deadline, s.new_maintenance_deadline, s.client_id, s.project_id, s.sales_rep, s.sales_date, s.description, s.software_reminded, s.hardware_reminded, s.maintenance_reminded, s.software_advance_reminded, s.hardware_advance_reminded, s.maintenance_advance_reminded, s.is_system, s.amount, s.cost, s.is_renew, s.renew_to_sales_order_item_id, s.number, s.is_merge, s.need_sn, s.erp_sales_outbound_id, s.erp_sales_gift_id
-> HashAggregate (cost=139.65..140.65 rows=100 width=784)
Group Key: s.id
-> Hash Join (cost=90.29..134.04 rows=2244 width=784)
Hash Cond: (client.id = s.client_id)
-> Hash Right Join (cost=45.89..84.45 rows=51 width=4)
Hash Cond: (sgr.sales_id = client.sales_rep)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..30.40 rows=2040 width=4)
-> Hash (cost=45.82..45.82 rows=5 width=8)
-> Seq Scan on tbl_clients client (cost=35.52..45.82 rows=5 width=8)
Filter: ((NOT deleted) AND ((sales_rep = 5493) OR (sales_rep IS NULL) OR (hashed SubPlan 1)))
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)
-> Hash (cost=33.40..33.40 rows=880 width=784)
-> Hash Right Join (cost=12.25..33.40 rows=880 width=784)
Hash Cond: (log.sales_order_item_id = s.id)
-> Seq Scan on tbl_sales_order_item_renew_logs log (cost=0.00..18.80 rows=880 width=4)
-> Hash (cost=11.00..11.00 rows=100 width=784)
-> Seq Scan on tbl_sales_order_items s (cost=0.00..11.00 rows=100 width=784)