pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Wheeler <david@kineticode.com>
To: pgsql-performance <pgsql-performance@postgresql.org>
Cc: Tom Lane <tgl@sss.pgh.pa.us>
Subject: Re: PL/pgSQL Loop Vs. Batch Update
Date: Tue, 2 May 2006 16:52:46 -0700
Message-ID: <EB5B93D1-6B57-42F0-A4EB-B5D48A0F57FA@kineticode.com> (raw)
In-Reply-To: <8ABDD0B7-326D-4C6C-BACF-3A4D172FEC56@kineticode.com>
References: <FFF901A7-232A-4140-AE41-89ABE7766A85@kineticode.com>
	<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>

On May 2, 2006, at 16:49, David Wheeler wrote:

> On Apr 25, 2006, at 19:36, Tom Lane wrote:
>
>> Try one of the actual queries from the plpgsql function.
>
> Here we go:
>
> 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=7.78..25.28 rows=500  
> width=4) (actual time=80.982..81.265 rows=7 loops=1)
>    Filter: (NOT (hashed subplan))
>    SubPlan
>      ->  Index Scan using idx_entry_tag_ord on entry_coll_tag ect2   
> (cost=0.00..7.77 rows=5 width=4) (actual time=80.620..80.620 rows=0  
> loops=1)
>            Index Cond: (entry_id = $1)
> Trigger for constraint entry_coll_tag_entry_id_fkey: time=3.210  
> calls=7
> Trigger for constraint entry_coll_tag_tag_id_fkey: time=4.412 calls=7
> Total runtime: 158.672 ms
> (8 rows)
>
> Actually looks pretty good to me. Although is generate_series()  
> being rather slow?

Scratch that:

try=# delete from entry_coll_tag ;
DELETE 7
try=# vacuum;
analyze;
VACUUM
try=# analyze;
ANALYZE
try=# explain analyze execute foo(100100, ARRAY 
[600001,600002,600003,600004,600005,600006,600007], 0);
                                                                    
QUERY PLAN
------------------------------------------------------------------------ 
-----------------------------------------------------------------------
Function Scan on generate_series gs  (cost=7.78..25.28 rows=500  
width=4) (actual time=0.193..0.284 rows=7 loops=1)
    Filter: (NOT (hashed subplan))
    SubPlan
      ->  Index Scan using idx_entry_tag_ord on entry_coll_tag ect2   
(cost=0.00..7.77 rows=5 width=4) (actual time=0.022..0.022 rows=0  
loops=1)
            Index Cond: (entry_id = $1)
Trigger for constraint entry_coll_tag_entry_id_fkey: time=0.858 calls=7
Trigger for constraint entry_coll_tag_tag_id_fkey: time=0.805 calls=7
Total runtime: 3.266 ms
(8 rows)

try=# delete from entry_coll_tag ;DELETE 7
try=# explain analyze execute foo(100100, ARRAY 
[600001,600002,600003,600004,600005,600006,600007], 0);

So my tests are calling this query six hundred times. Could it be  
that it just gets slower over time because the database needs to be  
vacuumed? Or perhaps pg_autovacuum is kicking in during execution and  
*that* slows things down?

Thanks,

David





view thread (8+ messages)  latest in thread

Message-ID: <EB5B93D1-6B57-42F0-A4EB-B5D48A0F57FA@kineticode.com>
Permalink:  ../EB5B93D1-6B57-42F0-A4EB-B5D48A0F57FA@kineticode.com/
Also on:    postgresql.org/message-id/EB5B93D1-6B57-42F0-A4EB-B5D48A0F57FA@kineticode.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: david@kineticode.com, tgl@sss.pgh.pa.us
  Subject: Re: PL/pgSQL Loop Vs. Batch Update
  In-Reply-To: <EB5B93D1-6B57-42F0-A4EB-B5D48A0F57FA@kineticode.com>
  References: <FFF901A7-232A-4140-AE41-89ABE7766A85@kineticode.com> <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> <EB5B93D1-6B57-42F0-A4EB-B5D48A0F57FA@kineticode.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox