Db2 has two tables, master table a B is from the table, and the foreign key of B is the primary key of.
Both tables of table A and table B have more than one million data records,
When A record in Table A is deleted and the primary key is used as the deletion condition, there is A significant delay.
If other fields are used as the where condition, hundreds of objects are deleted at a time, and the deletion fails after several minutes.
If you delete table B first, you should join the deleted data and delete several hundred items quickly. However, it is still not feasible to delete the data in table.
Analyze the cause and delete table B data. db2 directly deletes the data, so it is quick.
When data in Table A is deleted, db2 queries associated records in Table B first. The actual operation required to delete hundreds of records in Table A is as follows:
1. Select the record set of Table A according to the conditions.
2. query association records in Table B based on a and record the results as B.
3. Delete the data associated with table B.
4. Delete
Because the deletion involves two tables, the db2 operations from 1 to 4 will add transactions by themselves, which slows down.
Solution:
It's easy to cancel the foreign key of B and then delete it as fast as lightning :)