此DELETE(以及其他许多内容)需要很长时间。该表有大约1M行,但它们被updatedAt
正确编入索引,并且只有~5k行要删除:
SELECT COUNT(*) FROM "Users" where "_etl" = true and "updatedAt" >= '2015-01-15 15:01:10.454-05'
5163
这里是EXPLAIN:
EXPLAIN DELETE FROM "Users" where "_etl" = true and "updatedAt" >= '2015-01-15 15:01:10.454-05'
Delete on "Users" (cost=0.42..23581.27 rows=38909 width=6)
-> Index Scan using user_updatedat_etl_index on "Users" (cost=0.42..23581.27 rows=38909 width=6)
Index Cond: ("updatedAt" >= '2015-01-15 15:01:10.454-05'::timestamp with time zone)
Filter: _etl
我不确定,但也许是因为Users
表有很多外键?我已经等了大约30分钟才完成这个DELETE
,并且无法想出这应该花费这么长时间的正当理由。