Hi,

Please could you tell me why this query takes a very long time?
DELETE FROM DIPIMA
WHERE ins_SOPInstanceUID IN (
SELECT ins.ins_SOPInstanceUID
FROM DIPINS ins, DIPSER ser
WHERE ser.ser_SeriesInstanceUID=ins.ser_SeriesInstanceUI D AND
ser.stu_StudyInstanceUID IN ('X1', 'X2', 'X3', 'X4', 'X5')
);

See EXPLAIN ANALYE output:
NOTICE: QUERY PLAN:
Seq Scan on dipima (cost=0.00..672183218.19 rows=53914 width=6) (actual time=141419.92..655604.20 rows=1207 loops=1)
SubPlan
-> Materialize (cost=6233.88..6233.88 rows=975 width=165) (actual time=0.01..0.75 rows=1200 loops=107827)
-> Hash Join (cost=104.29..6233.88 rows=975 width=165) (actual time=256.71..929.70 rows=1207 loops=1)
-> Seq Scan on dipins ins (cost=0.00..5578.27 rows=107827 width=111) (actual time=0.14..655.87 rows=107827 loops=1)
-> Hash (cost=104.24..104.24 rows=21 width=54) (actual time=4.80..4.80 rows=0 loops=1)
-> Index Scan using got_series_fk, got_series_fk, got_series_fk, got_series_fk, got_series_fk on dipser ser (cost=0.00..104.24 rows=21 width=54) (actual time=0.83..4.70 rows=25 loops=1)
Total runtime: 655616.36 msec
EXPLAIN

Many thanks for your help,
a postgreSQL novice: Jonathan