I have two tables tableA(33M records) and tableB (270K records), I want to delete all records in tableA which also exist in tableB. So write a SQL statement below. I think It should be modified since it table more than 1 hour to remove them all. Do you have an idea if it is usual for these kind of operation. Note: primary key of both tables is id.
delete from tableA where id in (select id from tableB);
Here is the sql statement explain
| 0 | DELETE STATEMENT | | 289K| 7341K| | 85624 (1)| 00:17:08 |
| 1 | DELETE | tableA | | | | | |
| 2 | MERGE JOIN | | 289K| 7341K| | 85624 (1)| 00:17:08 |
| 3 | INDEX FULL SCAN | SYS_C0015397 | 36M| 455M| | 84050 (1)| 00:16:49 |
|* 4 | SORT JOIN | | 289K| 3670K| 11M| 1574 (1)| 00:00:19 |
| 5 | INDEX FAST FULL SCAN| SYS_C0015401 | 289K| 3670K| | 193 (2)| 00:00:03 |
---------------------------------------------------------------------------------------------------
EXEC DBMS_STATS.GATHER_TABLE_STATS ('tableA')andEXEC DBMS_STATS.GATHER_TABLE_STATS ('tableB')