Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 31CF69FA4C2 for ; Tue, 22 May 2007 09:28:31 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 55048-05 for ; Tue, 22 May 2007 09:28:27 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by postgresql.org (Postfix) with ESMTP id 27EAE9FA1A8 for ; Tue, 22 May 2007 09:28:27 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.3 Received: from achille.dalibo.net (achille.dalibo.net [212.85.153.230]) by svr4.postgresql.org (Postfix) with ESMTP id 0400F5AF882 for ; Tue, 22 May 2007 12:28:25 +0000 (GMT) Received: from localhost (localhost.localdomain [127.0.0.1]) by achille.dalibo.net (Postfix) with ESMTP id 3EA3415F76; Tue, 22 May 2007 14:28:11 +0200 (CEST) Received: from achille.dalibo.net ([127.0.0.1]) by localhost (achille [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 24549-09; Tue, 22 May 2007 14:28:10 +0200 (CEST) Received: from asterix.local (AToulouse-152-1-5-247.w82-125.abo.wanadoo.fr [82.125.3.247]) by achille.dalibo.net (Postfix) with ESMTP id 4A38F15F75; Tue, 22 May 2007 14:28:10 +0200 (CEST) From: cedric Organization: dalibo.com To: pgsql-performance@postgresql.org Subject: Re: Key/Value reference table generation: INSERT/UPDATE performance Date: Tue, 22 May 2007 14:28:05 +0200 User-Agent: KMail/1.9.6 Cc: Richard Huxton , valgog References: <1179822183.740891.271130@n59g2000hsh.googlegroups.com> <4652B627.1070109@archonet.com> In-Reply-To: <4652B627.1070109@archonet.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200705221428.09546.cedric.villemain@dalibo.com> X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at dalibo.com X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/432 X-Sequence-Number: 24822 Le mardi 22 mai 2007, Richard Huxton a =E9crit=A0: > 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= =20 perl is very quick.=20 I have also use partioning because of cost of update (copy last partition t= o=20 the new, adding the new count, so there is only insert, and drop old table = if=20 you want)