Search Postgresql Archives

delete from ... where not in

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all,

I have a problem with a delete query I'm not sure how to fix.

I've tried this in 8.1.4 & 8.2.3 and get the same behaviour in both.

This is how I've been able to reproduce it:



create table t1(id serial primary key, email text);

insert into t1(email) select 'email' || n || '@address.com' from generate_series(1,50000) as n;

analyze t1;

create table t2(recip int);

insert into t2(recip) select id from t1;

delete from t2 where recip not in (select distinct on (email) id from t1);



If I don't analyze t1 then the query finishes in a couple of seconds.

That happens regardless of whether I analyze t2 or not and regardless of any other indexes (I had one on t1(email) and one on t2(recip) but they didn't make any difference).


I'm sure I'm doing something wrong so a pointer would be great ;)

Thanks!
--
Postgresql & php tutorials
http://www.designmagick.com/


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux