我在 Oracle 10g 中有这个查询:
DELETE FROM "BMAN_TP1"."CELLS_ITEM" TABLE1
WHERE EXISTS (
SELECT "CELLS_ITEM".*
FROM "BMAN_TP1"."CELLS_ITEM"
INNER JOIN "BMAN_TP1"."CELLS" ON ("CELLS_ITEM"."SET_ID"="CELLS"."SET_ID") AND ("CELLS_ITEM"."META_CELL_ID"="CELLS"."META_CELL_ID")
INNER JOIN "BMAN_TP1"."META_CELLS" ON ("CELLS"."META_CELL_ID"="META_CELLS"."META_CELL_ID")
WHERE ("META_CELLS"."UDA_ID" = variable)
AND (TABLE1."SET_ID" = "CELLS_ITEM"."SET_ID")
AND (TABLE1."META_CELL_ID" = "CELLS_ITEM"."META_CELL_ID")
)
目前删除 50K 记录大约需要 10 秒(表中大约有 100K 记录)
我知道它会重复 100K 次选择查询,这会减慢它的速度。
TABLE1 也有两个字段的 PK,这使事情变得更加复杂。
有什么想法可以让它更快吗?
编辑:
尝试了这个,但它几乎相同:
DELETE FROM "BMAN_TP1"."CELLS_ITEM" TABLE1
WHERE EXISTS (
SELECT "META_CELL_ID"
FROM "BMAN_TP1"."META_CELLS"
WHERE ("META_CELLS"."UDA_ID"=55823)
AND (TABLE1."META_CELL_ID" = "META_CELLS"."META_CELL_ID")
)