From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | brendan(dot)curran(at)gmail(dot)com |
Cc: | Pg Performance list <pgsql-performance(at)postgresql(dot)org> |
Subject: | Re: Scrub one large table against another |
Date: | 2006-10-10 22:14:05 |
Message-ID: | 13451.1160518445@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
Brendan Curran <brendan(dot)curran(at)gmail(dot)com> writes:
> CREATE TEMP TABLE temp_list_suppress(email_record_id int8);
> INSERT INTO temp_list_suppress
> SELECT email_record_id from ONLY email_record er
> WHERE email_list_id = 9 AND email IN
> (select email from suppress);
> CREATE INDEX unique_id_index on temp_list_suppress ( email_record_id );
> INSERT INTO er_banned
> SELECT * from ONLY email_record er WHERE EXISTS
> (SELECT 1 from temp_list_suppress ts where er.email_record_id =
> ts.email_record_id)';
> DELETE FROM ONLY email_record WHERE email_list_id = 9 AND email_record_id IN
> (SELECT email_record_id from temp_list_suppress);
> TRUNCATE TABLE temp_list_suppress;
> DROP TABLE temp_list_suppress;
> The performance is dreadful, is there a more efficient way to do this?
Have you tried doing EXPLAIN ANALYZE of each of the INSERT/DELETE steps?
If you don't even know which part is slow, it's hard to improve.
It would probably help to do an "ANALYZE temp_list_suppress" right after
populating the temp table. As you have it, the second insert and delete
are being planned with nothing more than a row count (obtained during
CREATE INDEX) and no stats about distribution of the table contents.
Also, I'd be inclined to try replacing the EXISTS with an IN test;
in recent PG versions the planner is generally smarter about IN.
(Is there a reason why you are doing the INSERT one way and the
DELETE the other?)
BTW, that TRUNCATE right before the DROP seems quite useless,
although it's not the main source of your problem.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Brendan Curran | 2006-10-10 22:37:00 | Re: Scrub one large table against another |
Previous Message | Brendan Curran | 2006-10-10 21:44:23 | Scrub one large table against another |