Insert on public.orphaned_matches (cost=204030825.83..204247350.03 rows=8660968 width=264) CTE removed -> Delete on public.match m (cost=0.00..204030825.83 rows=8660968 width=6) Output: m.id, m.created_at, m.modified_at, m.household_id, m.property_id, m.match_reason, m.full_name, m.first_name, m.middle_name, m.last_name, m.account_id, m.candidate_id, m.match_category, m.confidence, m.owner_id, m.match_resource -> Seq Scan on public.match m (cost=0.00..204030825.83 rows=8660968 width=6) Output: m.ctid Filter: ((NOT (SubPlan 1)) OR ((m.property_id IS NOT NULL) AND (NOT (SubPlan 2)))) SubPlan 1 -> Index Only Scan using uq_household_id on build.household h (cost=0.57..8.59 rows=1 width=0) Index Cond: (h.household_id = (m.household_id)::text) SubPlan 2 -> Index Scan using property_property_id_idx on build.property p (cost=0.57..8.59 rows=1 width=0) Index Cond: (p.property_id = m.property_id) Filter: (p.household_id = (m.household_id)::text) -> CTE Scan on removed (cost=0.00..216524.20 rows=8660968 width=264) Output: nextval('orphaned_matches_id_seq'::regclass), now(), removed.household_id, removed.account_id, removed.candidate_id, removed.created_at, removed.full_name, removed.first_name, removed.last_name, removed.match_reason, removed.property_id, removed.owner_id (16 rows)