QUERY PLAN Limit (cost=253523.56..253523.57 rows=1 width=176) -> Sort (cost=253523.56..253523.57 rows=1 width=176) Sort Key: c_2.gii_circuitid, c_1.id -> Nested Loop (cost=33190.89..253523.55 rows=1 width=176) Join Filter: (c_1.id = c.id) -> Nested Loop (cost=31724.87..31736.29 rows=1 width=85) Join Filter: (c.status = cst.id) -> Nested Loop (cost=31724.87..31734.84 rows=1 width=74) -> Nested Loop Left Join (cost=31724.45..31734.35 rows=1 width=70) Join Filter: (csc.id = cs.country_id) -> Nested Loop Left Join (cost=31724.45..31726.73 rows=1 width=68) -> Nested Loop (cost=31724.02..31726.27 rows=1 width=30) -> GroupAggregate (cost=31723.60..31723.62 rows=1 width=26) Group Key: c_2.gii_circuitid -> Sort (cost=31723.60..31723.60 rows=1 width=26) Sort Key: c_2.gii_circuitid -> Gather (cost=1000.85..31723.59 rows=1 width=26) Workers Planned: 3 -> Nested Loop (cost=0.85..30723.49 rows=1 width=26) -> Nested Loop (cost=0.42..30722.56 rows=2 width=30) -> Parallel Seq Scan on circuit c_2 (cost=0.00..30714.61 rows=3 width=26) Filter: ((status >= 20) AND (status <> ALL ('{160,999}'::integer[])) AND (status <> 160) AND (service_description = 28)) -> Index Scan using so_pid_idx on service_order so_1 (cost=0.42..2.65 rows=1 width=12) Index Cond: (product_id = c_2.product_id) Filter: (((ordertype_id <> 2) OR (status = 999)) AND ((ordertype_id <> 3) OR (status = 999))) -> Index Scan using master_service_order_id_key on master_service_order mso (cost=0.42..0.46 rows=1 width=4) Index Cond: (id = so_1.master_service_order_id) Filter: (client_id = 11615) -> Index Scan using service_order_id_key on service_order so (cost=0.42..2.64 rows=1 width=12) Index Cond: (id = (max(so_1.id))) -> Index Scan using client_site_pkey on client_site cs (cost=0.42..0.46 rows=1 width=46) Index Cond: (id = so.a_site_id) -> Seq Scan on country csc (cost=0.00..4.50 rows=250 width=6) -> Index Scan using circuit_product_id_idx on circuit c (cost=0.42..0.49 rows=1 width=12) Index Cond: (product_id = so.product_id) -> Seq Scan on circuit_status cst (cost=0.00..1.20 rows=20 width=19) -> Gather (cost=1466.02..221787.23 rows=3 width=75) Workers Planned: 5 -> Hash Join (cost=466.02..220786.93 rows=1 width=75) Hash Cond: (c_1.id = vendor_gtt_pop.gtt_pop_id) -> Hash Join (cost=444.07..219779.19 rows=157724 width=63) Hash Cond: (c_1.pop_support_vendor_id = v.id) -> Merge Join (cost=5.02..217348.87 rows=157724 width=40) Merge Cond: (cl.circuit_id = c_1.id) -> Nested Loop (cost=0.86..171314.49 rows=157724 width=32) -> Parallel Index Only Scan using circuit_layout_idx on circuit_layout cl (cost=0.43..55430.93 rows=157724 width=8) Index Cond: (ordinal = 1) -> Index Scan using uniqid on segment sg (cost=0.43..0.73 rows=1 width=32) Index Cond: (id = cl.segment_id) -> Index Scan using circuit_id_key on circuit c_1 (cost=0.42..41790.58 rows=909014 width=8) -> Hash (cost=325.69..325.69 rows=9069 width=27) -> Seq Scan on vendor v (cost=0.00..325.69 rows=9069 width=27) -> Hash (cost=21.91..21.91 rows=3 width=12) -> Seq Scan on vendor_gtt_pop (cost=0.00..21.91 rows=3 width=12) Filter: (vendor_id = 12346)