X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id D2F469FA1B0 for ; Tue, 2 May 2006 22:17:06 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 86634-04 for ; Tue, 2 May 2006 22:16:59 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mail8.sea5.speakeasy.net (mail8.sea5.speakeasy.net [69.17.117.10]) by postgresql.org (Postfix) with ESMTP id 993719F9C9E for ; Tue, 2 May 2006 22:16:59 -0300 (ADT) Received: (qmail 29061 invoked from network); 3 May 2006 01:16:57 -0000 Received: from dsl093-038-250.pdx1.dsl.speakeasy.net (HELO [192.168.1.20]) (davidw@[66.93.38.250]) (envelope-sender ) by mail8.sea5.speakeasy.net (qmail-ldap-1.03) with RC4-SHA encrypted SMTP for ; 3 May 2006 01:16:57 -0000 In-Reply-To: References: <11055.1146014387@sss.pgh.pa.us> <8FE57896-2F9B-4838-857B-FA6CC2EE162A@kineticode.com> <11514.1146018981@sss.pgh.pa.us> <8ABDD0B7-326D-4C6C-BACF-3A4D172FEC56@kineticode.com> Mime-Version: 1.0 (Apple Message framework v749.3) Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed Message-Id: <4F5A51D9-3740-49F2-AFC5-B2901101FFB9@kineticode.com> Cc: Tom Lane Content-Transfer-Encoding: 7bit From: David Wheeler Subject: Re: PL/pgSQL Loop Vs. Batch Update Date: Tue, 2 May 2006 18:16:56 -0700 To: pgsql-performance X-Mailer: Apple Mail (2.749.3) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200605/67 X-Sequence-Number: 18854 On May 2, 2006, at 16:52, David Wheeler wrote: >> Actually looks pretty good to me. Although is generate_series() >> being rather slow? > > Scratch that: Bah, dammit, there were no rows in that relevant table. Please disregard my previous EXPLAIN ANALYZE posts. I've re-run my script and populated it with 549,815 rows. *Now* let's see what we've got: try=# VACUUM; VACUUM try=# ANALYZE; ANALYZE try=# PREPARE foo(int, int[], int) AS try-# INSERT INTO entry_coll_tag (entry_id, tag_id, ord ) try-# SELECT $1, $2[gs.ser], gs.ser + $3 try-# FROM generate_series(1, array_upper($2, 1)) AS gs(ser) try-# WHERE $2[gs.ser] NOT IN ( try(# SELECT tag_id FROM entry_coll_tag ect2 try(# WHERE entry_id = $1 try(# ); PREPARE try=# explain analyze execute foo(100100, ARRAY [600001,600002,600003,600004,600005,600006,600007], 0); QUERY PLAN ------------------------------------------------------------------------ ----------------------------------------------------------------------- Function Scan on generate_series gs (cost=9.68..27.18 rows=500 width=4) (actual time=0.965..1.055 rows=7 loops=1) Filter: (NOT (hashed subplan)) SubPlan -> Index Scan using idx_entry_tag_ord on entry_coll_tag ect2 (cost=0.00..9.66 rows=8 width=4) (actual time=0.844..0.844 rows=0 loops=1) Index Cond: (entry_id = $1) Trigger for constraint entry_coll_tag_entry_id_fkey: time=3.872 calls=7 Trigger for constraint entry_coll_tag_tag_id_fkey: time=3.872 calls=7 Total runtime: 12.797 ms (8 rows) try=# delete from entry_coll_tag where entry_id = 100100; DELETE 7 try=# explain analyze execute foo(100100, ARRAY [600001,600002,600003,600004,600005,600006,600007], 0); QUERY PLAN ------------------------------------------------------------------------ ----------------------------------------------------------------------- Function Scan on generate_series gs (cost=9.68..27.18 rows=500 width=4) (actual time=0.117..0.257 rows=7 loops=1) Filter: (NOT (hashed subplan)) SubPlan -> Index Scan using idx_entry_tag_ord on entry_coll_tag ect2 (cost=0.00..9.66 rows=8 width=4) (actual time=0.058..0.058 rows=0 loops=1) Index Cond: (entry_id = $1) Trigger for constraint entry_coll_tag_entry_id_fkey: time=0.542 calls=7 Trigger for constraint entry_coll_tag_tag_id_fkey: time=0.590 calls=7 Total runtime: 2.118 ms (8 rows) Damn, that seems pretty efficient. I wonder if it's the other function, then. I'll have to work EXPLAIN ANALYZEing _it_. Best, David