SQL在哪里:更好地使用静态数组还是选择?

时间:2015-07-08 14:07:04

标签: mysql sql query-optimization

我有一个MySQL数据库,我需要删除表father的一些内容,但有些FK在我的表father和表child之间有限制,为此,我必须从child表中删除,然后从father表中删除。 我有:

DELETE FROM child WHERE child.id IN (SELECT id FROM father);

我想知道,如果我使用

,它会有性能变化(除了额外的选择)
DELETE FROM child WHERE child.id IN (1,2,...,n)

其中1,2 ... n与'SELECT id FROM father'的结果相同。

1 个答案:

答案 0 :(得分:0)

比使用多表DELETE更快:

int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources().getDisplayMetrics());
cardView.setContentPadding(-padding,-padding,-padding,-padding);

不应该是DELETE FROM child USING father JOIN child ON child.id = father.id; ??不,即使这似乎错了吗?

这似乎更接近你的英语:

child.father_id

DELETE FROM child USING father JOIN child ON child.father_id = father.id -- more likely FK WHERE father...; -- picking the Dads in question DELETE FROM father WHERE father...; -- picking the Dads in question 可能会稍快一些。