pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: cedric <cedric.villemain@dalibo.com>
To: pgsql-performance@postgresql.org
Cc: Richard Huxton <dev@archonet.com>
Cc: valgog <valgog@gmail.com>
Subject: Re: Key/Value reference table generation: INSERT/UPDATE performance
Date: Tue, 22 May 2007 14:28:05 +0200
Message-ID: <200705221428.09546.cedric.villemain@dalibo.com> (raw)
In-Reply-To: <4652B627.1070109@archonet.com>
References: <1179822183.740891.271130@n59g2000hsh.googlegroups.com>
	<4652B627.1070109@archonet.com>

Le mardi 22 mai 2007, Richard Huxton a écrit :
> valgog wrote:
> > I found several post about INSERT/UPDATE performance in this group,
> > but actually it was not really what I am searching an answer for...
> >
> > I have a simple reference table WORD_COUNTS that contains the count of
> > words that appear in a word array storage in another table.
>
> I think this is the root of your problem, I'm afraid. You're trying to
> count individual words when you're storing an array of words. I don't
> think any of the Gist/GIN indexes will help you with this either.
>
> However, since "you don't want to start from here" isn't very useful
> here and now:
>
> 1. See what the performance (explain analyse) of the "select
> distinct...generate_series()" statement is. I think you're right and
> it's going to be slow.
> 2. You're looping through each row of word_storage and counting
> separately. Write it as one query if possible.
> 3. As Peter says, don't insert then update, start with an empty table
> and just insert totals for the lot (see #2).
>
> I'd probably write the query in plperl/python or something else that
> supports hash/dictionary structures. Then just process the whole
> word_storage into the hash - assuming you only have a few thousand
> distinct words that shouldn't take up too much memory.
+1
I made something very similar, and using PL/pgsql is very slow, when using 
perl is very quick. 

I have also use partioning because of cost of update (copy last partition to 
the new, adding the new count, so there is only insert, and drop old table if 
you want)



view thread (9+ messages)  latest in thread

Message-ID: <200705221428.09546.cedric.villemain@dalibo.com>
Permalink:  ../200705221428.09546.cedric.villemain@dalibo.com/
Also on:    postgresql.org/message-id/200705221428.09546.cedric.villemain@dalibo.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: cedric.villemain@dalibo.com, dev@archonet.com, valgog@gmail.com
  Subject: Re: Key/Value reference table generation: INSERT/UPDATE performance
  In-Reply-To: <200705221428.09546.cedric.villemain@dalibo.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