document headers in omdok table:
create table omdok ( dokumnr serial primary key, ... );
document rows in omrid table
create table omrid ( id serial not null, reanr serial not null, dokumnr integer not null, constraint omrid_pkey primary key (id), constraint omrid_dokumnr_fkey foreign key (dokumnr) references omdok (dokumnr) match simple on update cascade on delete cascade deferrable immediate, .... );
records in omdok not have child rows in omrid needs deleted
i tried
delete omdok dokumnr not in (select dokumnr omrid)
query running 15 hours , still running. postgres.exe using 50% cpu time (this 2 core cpu).
explain delete omdok dokumnr not in (select dokumnr omrid)
returns:
"delete (cost=0.00..21971079433.34 rows=220815 width=6)" " -> seq scan on omdok (cost=0.00..21971079433.34 rows=220815 width=6)" " filter: (not (subplan 1))" " subplan 1" " -> materialize (cost=0.00..94756.92 rows=1897261 width=4)" " -> seq scan on omrid (cost=0.00..77858.61 rows=1897261 width=4)"
- how delete parents without child rows fast?
- will command finish or postgres hanging ?
- currently running 15 hours. how many hours takes finish ? how speed query ?
using
postgresql 9.0.1, compiled visual c++ build 1500, 64-bit windows 2003 x64 server 4 gb ram.
another alternative create index on omrid(dokumnr)
:
create index idx_omrid_dokumnr on omrid(dokumnr);
this should speed processing of not in
in original query.
Comments
Post a Comment