Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id BA7DC2E003B for ; Fri, 2 May 2008 18:09:59 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 20183-01 for ; Fri, 2 May 2008 18:09:51 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0506.google.com (rv-out-0506.google.com [209.85.198.224]) by developer.postgresql.org (Postfix) with ESMTP id 767932E0031 for ; Fri, 2 May 2008 18:09:56 -0300 (ADT) Received: by rv-out-0506.google.com with SMTP id b25so998907rvf.43 for ; Fri, 02 May 2008 14:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:cc:message-id:from:to:in-reply-to:content-type:content-transfer-encoding:mime-version:subject:date:references:x-mailer; bh=v/h3ADl7BefW0OAWnhu0uHL3KEPhcTqUkpVdh5A48fo=; b=dmnmHTIeB0lroegMy+tOecJy4RnhDK0D0MKpb5h2PLZXZfKKqPaAQmgqASnI0faVzUhY8pPKwKJXFfz+gSzpKTPIXsejV79vPYbJmQuZS31KHwOs890CD+nN64LXiEqjLBM4yZLsnuOJosnhGwNB/vcctgLxzxHXOty/e7KK+9k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=cc:message-id:from:to:in-reply-to:content-type:content-transfer-encoding:mime-version:subject:date:references:x-mailer; b=tjDVzvwwvdS2J8KtS3iA6WN3ObJkqC+RPDOIycPrJRUbQsE/n7ChPAZm7AinRVNuFC961xQPoW4JpxT8vkJsJZPk5/MdkVd6YY5wTStszpkqFm0tZLKJBA60LmH5jKyj6W89Ef30GSI//SfZ1sDvsSE1rS6DMf96k1IfJOFrlpM= Received: by 10.141.69.1 with SMTP id w1mr1545945rvk.185.1209762595418; Fri, 02 May 2008 14:09:55 -0700 (PDT) Received: from ?192.168.1.100? ( [24.19.22.42]) by mx.google.com with ESMTPS id g22sm4712716rvb.7.2008.05.02.14.09.54 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 02 May 2008 14:09:54 -0700 (PDT) Cc: pgsql-performance@postgresql.org Message-Id: From: Alexy Khrabrov To: Craig James In-Reply-To: <481B8160.2090106@emolecules.com> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v919.2) Subject: Re: two memory-consuming postgres processes Date: Fri, 2 May 2008 14:09:52 -0700 References: <27A4D379-2553-496D-A96C-102F2A5E62C2@gmail.com> <21403.1209759217@sss.pgh.pa.us> <72E02D29-848B-467A-AE6B-401568010254@gmail.com> <481B8160.2090106@emolecules.com> X-Mailer: Apple Mail (2.919.2) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.038 tagged_above=0 required=5 tests=AWL=0.038 X-Spam-Level: X-Archive-Number: 200805/31 X-Sequence-Number: 29999 On May 2, 2008, at 2:02 PM, Craig James wrote: > On Fri, May 2, 2008 at 2:26 PM, Alexy Khrabrov > wrote: >> I naively thought that if I have a 100,000,000 row table, of the form >> (integer,integer,smallint,date), and add a real coumn to it, it >> will scroll >> through the memory reasonably fast. > > In Postgres, an update is the same as a delete/insert. That means > that changing the data in one column rewrites ALL of the columns for > that row, and you end up with a table that's 50% dead space, which > you then have to vacuum. > > Sometimes if you have a "volatile" column that goes with several > "static" columns, you're far better off to create a second table for > the volatile data, duplicating the primary key in both tables. In > your case, it would mean the difference between 10^8 inserts of > (int, float), very fast, compared to what you're doing now, which is > 10^8 insert and 10^8 deletes of (int, int, smallint, date, float), > followed by a big vacuum/analyze (also slow). > > The down side of this design is that later on, it requires a join to > fetch all the data for each key. > > You do have a primary key on your data, right? Or some sort of index? I created several indices for the primary table, yes. Sure I can do a table for a volatile column, but then I'll have to create a new such table for each derived column -- that's why I tried to add a column to the existing table. Yet seeing this is really slow, and I need to to many derived analyses like this -- which are later scanned in other computations, so should persist -- I indeed see no other way but to procreate derived tables with the same key, one column per each... Cheers, Alexy