QUERY PLAN
Result (cost=51.86..51.87 rows=1 width=1)
InitPlan 2 (returns $2)
-> Nested Loop Left Join (cost=35.80..51.86 rows=1 width=0)
Filter: ((client.sales_rep = 5493) OR (client.sales_rep IS NULL) OR (hashed SubPlan 1))
-> Index Scan using tbl_sales_order_items_pkey on tbl_sales_order_items s (cost=0.14..8.16 rows=1 width=4)
Index Cond: (id = 1)
-> Index Scan using tbl_clients_pkey on tbl_clients client (cost=0.14..8.15 rows=1 width=8)
Index Cond: (id = s.client_id)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..35.50 rows=10 width=4)
Filter: (user_id = 5495)