I two tables table1 and table2 in postgresql-12:
DELETE FROM table2 WHERE (ddate, itemno) NOT IN (SELECT ddate,itemno FROM table1);
table1 has around 7000000 entries. table2 has around 9500000 entries. Around 100000 matches are expected. This command takes 5 hours to execute. How can I optimize this query?