Received: from localhost (maia-1.hub.org [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id A65E49FA31B for ; Tue, 22 May 2007 07:35:50 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 69846-05 for ; Tue, 22 May 2007 07:35:47 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by postgresql.org (Postfix) with ESMTP id E61F79FA1A6 for ; Tue, 22 May 2007 07:35:46 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 98ECF3090B; Tue, 22 May 2007 12:35:45 +0200 (MET DST) From: valgog X-Newsgroups: pgsql.performance Subject: Re: Key/Value reference table generation: INSERT/UPDATE performance Date: 22 May 2007 03:35:29 -0700 Organization: http://groups.google.com Lines: 36 Message-ID: <1179830129.622698.240380@x35g2000prf.googlegroups.com> References: <1179822183.740891.271130@n59g2000hsh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Complaints-To: groups-abuse@google.com In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: x35g2000prf.googlegroups.com; posting-host=62.220.8.122; posting-account=VhGBRA0AAAAPUct5VN1tGkfI2QuiqXqC To: pgsql-performance@postgresql.org X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/429 X-Sequence-Number: 24819 On May 22, 12:14 pm, l...@peufeu.com (PFC) wrote: > 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. > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq good idea indeed! will try this approach.