Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 5966D9FA4AD for ; Tue, 22 May 2007 06:23:39 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 41728-07 for ; Tue, 22 May 2007 06:23:32 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by postgresql.org (Postfix) with ESMTP id 96B459FA440 for ; Tue, 22 May 2007 06:23:35 -0300 (ADT) Received: from server3.office.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id F145C75363; Tue, 22 May 2007 10:21:43 +0100 (BST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by server3.office.archonet.com (Postfix) with ESMTP id 3CD85274115; Tue, 22 May 2007 10:21:45 +0100 (BST) Message-ID: <4652B627.1070109@archonet.com> Date: Tue, 22 May 2007 10:21:43 +0100 From: Richard Huxton User-Agent: Thunderbird 2.0.0.0 (X11/20070326) MIME-Version: 1.0 To: valgog Cc: pgsql-performance@postgresql.org Subject: Re: Key/Value reference table generation: INSERT/UPDATE performance References: <1179822183.740891.271130@n59g2000hsh.googlegroups.com> In-Reply-To: <1179822183.740891.271130@n59g2000hsh.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/423 X-Sequence-Number: 24813 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. -- Richard Huxton Archonet Ltd