Try these solutions in order:
- 1.Analyze statistics (ANALYZE Table1; ANALYZE Table2;)
- 2.Disable sequential scan (SET enable_seqscan = OFF;)
- 3.Use explicit JOIN instead of , (comma join)
- 4.Use a CTE (WITH t2_indexed AS (...))
- 5.Rewrite with EXISTS or subqueries if applicable
- 6.Increase work_mem
- 7.Add/Reindex t1.uid