I have query to select all rows from table1 that they are not in tabl2 then insert them in table2. This query is taking log time to execute since I have millions of rows in table2.
Is there better way to optimize or rewrite this query to make it execute faster.
WITH t1 AS (
select *
from table1
where id not in (select id table2))
insert into table2
select * from t1 ;