Deletes of this type are very slow:
delete from childtbl
where id1 in
(
-a select id1
-a from parenttbl
-a where id2 in
-a (
-a-a select id2
-a-a from othertbl
-a-a where condition
-a )
)
Like 1.5 minutes to delete a couple thousand rows.
How can I speed them up?
On 8/20/2021 1:34 PM, DFS wrote:
Deletes of this type are very slow:
delete from childtbl
where id1 in
(
-a-a select id1
-a-a from parenttbl
-a-a where id2 in
-a-a (
-a-a-a select id2
-a-a-a from othertbl
-a-a-a where condition
-a-a )
)
Like 1.5 minutes to delete a couple thousand rows.
How can I speed them up?
How big are your tables?
Do you have indexes on id1 and id2 in their
appropriate tables?
delete from childtbl
where id1 in
(
-a select id1
-a from parenttbl
-a where id2 in
-a (
-a-a select id2
-a-a from othertbl
-a-a where condition
-a )
)
How can I speed them up?
Deletes of this type are very slow:
delete from childtbl
where id1 in
(
-a select id1
-a from parenttbl
-a where id2 in
-a (
-a-a select id2
-a-a from othertbl
-a-a where condition
-a )
)
Like 1.5 minutes to delete a couple thousand rows.
How can I speed them up?
On 20/08/2021 19.34, DFS wrote:
Deletes of this type are very slow:
delete from childtbl
where id1 in
(
-a-a select id1
-a-a from parenttbl
-a-a where id2 in
-a-a (
-a-a-a select id2
-a-a-a from othertbl
-a-a-a where condition
-a-a )
)
Like 1.5 minutes to delete a couple thousand rows.
How can I speed them up?
Why not join the tables
DELETE childtbl
FROM childtbl
INNER JOIN parenttbl ON parenttbl.id1 =
childtbl.id1
INNER JOIN othertbl.id2 ON parenttbl.id2
WHERE othertbl[condition]
even
DELETE FROM childtbl
WHERE id1 IN(
-a-a-a-aSELECT id1 FROM parenttbl
-a-a-a-aINNER JOIN othertbl ON othertbl.id2 = parenttbl.id2
-a-a-a-aWHERE othertbl[condition]
)
could be faster than the original.
| Sysop: | Amessyroom |
|---|---|
| Location: | Fayetteville, NC |
| Users: | 63 |
| Nodes: | 6 (0 / 6) |
| Uptime: | 492977:05:16 |
| Calls: | 840 |
| Files: | 1,301 |
| D/L today: |
17 files (29,919K bytes) |
| Messages: | 265,073 |