Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id AE7929FB2A6 for ; Tue, 22 May 2007 07:12:27 -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 23010-07 for ; Tue, 22 May 2007 07:12:23 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from h07.llord.com (unknown [195.140.142.194]) by postgresql.org (Postfix) with ESMTP id 539209FB340 for ; Tue, 22 May 2007 07:12:23 -0300 (ADT) Received: from par69-8-88-161-102-87.fbx.proxad.net ([88.161.102.87] helo=apollo13) by h07.llord.com with esmtpa (Exim 4.63) (envelope-from ) id 1HqRLm-0001vp-NI; Tue, 22 May 2007 12:12:18 +0200 Date: Tue, 22 May 2007 12:14:48 +0200 To: valgog , pgsql-performance@postgresql.org Subject: Re: Key/Value reference table generation: INSERT/UPDATE performance From: PFC Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8 MIME-Version: 1.0 References: <1179822183.740891.271130@n59g2000hsh.googlegroups.com> Content-Transfer-Encoding: 7bit Message-ID: In-Reply-To: <1179822183.740891.271130@n59g2000hsh.googlegroups.com> User-Agent: Opera Mail/9.10 (Linux) X-PopBeforeSMTPSenders: junk@peufeu.com, lists@peufeu.com, peufeu@peufeu.com, pfcaillaud@peufeu.com X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - h07.llord.com X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - peufeu.com X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.009 tagged_above=0 required=5 tests=AWL=0.833, BAYES_00=-2.599, RCVD_IN_NJABL_SPAM=2.775 X-Spam-Level: * X-Archive-Number: 200705/428 X-Sequence-Number: 24818 On Tue, 22 May 2007 10:23:03 +0200, 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. Mmm. If I were you, I would : - Create a procedure that flattens all the arrays and returns all the words : PROCEDURE flatten_arrays RETURNS SETOF TEXT FOR word_array IN SELECT word_array FROM your_table LOOP FOR i IN 1...array_upper( word_array ) LOOP RETURN NEXT tolower( word_array[ i ] ) So, SELECT * FROM flatten_arrays() returns all the words in all the arrays. To get the counts quickly I'd do this : SELECT word, count(*) FROM flatten_arrays() AS word GROUP BY word You can then populate your counts table very easily and quickly, since it's just a seq scan and hash aggregate. One second for 10.000 rows would be slow.