I have two tables
Table1 and Table2
..and so on
...and so on
I am comparing both the tables in following way:
If Id of Table2 does not exists in Id of Table1
delte that Id from Table2.
My logic is
I am getting a collection of Table1 Ids and Table2 Ids
Looping through each Table2 id
Check if each Table2 id exists in Table1 Id collection
If not exists delete the id using this sql:
DELETE FROM table2 WHERE id = :id
There are 1 million Id in Table1 and more than 1 million Id in Table2
My overall process takes a long time (more than an hour)
what could be the reason for this?
Right now ID column is not indexed. Will indexing help?
Any sugessions will be great.