Slow data deletion in DB2

Source: Internet
Author: User

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 :)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.