Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id B667B9F9F51 for ; Tue, 4 Sep 2007 16:18:13 -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 63168-02 for ; Tue, 4 Sep 2007 16:18:07 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from mir3-fs.mir3.com (mail.mir3.com [65.208.188.100]) by postgresql.org (Postfix) with ESMTP id BE02A9F9FFC for ; Tue, 4 Sep 2007 16:18:06 -0300 (ADT) Received: MIR3-FS.mir3.com 172.16.1.11 from 172.16.2.68 172.16.2.68 via HTTP with MS-WebStorage 6.0.6249 Received: from archimedes by MIR3-FS.mir3.com; 04 Sep 2007 12:18:00 -0700 Subject: Re: join tables vs. denormalization by trigger From: Mark Lewis To: Walter Mauritz Cc: pgsql-performance@postgresql.org In-Reply-To: <20070904185321.221220@gmx.net> References: <20070904185321.221220@gmx.net> Content-Type: text/plain Content-Transfer-Encoding: 7bit Organization: MIR3, Inc. Date: Tue, 04 Sep 2007 12:18:00 -0700 Message-Id: <1188933480.5367.40.camel@archimedes> Mime-Version: 1.0 X-Mailer: Evolution 2.8.1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200709/29 X-Sequence-Number: 26574 On Tue, 2007-09-04 at 20:53 +0200, Walter Mauritz wrote: > Hi, > > I wonder about differences in performance between two scenarios: > > Background: > Table A, ~50,000 records > Table B, ~3,000,000 records (~20 cols) > Table C, ~30,000,000 records (~10 cols) > > a query every 3sec. with limit 10 > > Table C depends on Table B wich depends on Table A, int8 foreign key, btree index > > * consider it a read only scenario (load data only in night, with time for vacuum analyze daily) > * im required to show records from Table C, but also with some (~5cols) info from Table B > * where clause always contains the foreign key to Table A > * where clause may contain further 1-10 search parameter > > > Scenario A) > simply inner join Table B + C > > Scenario B) > with use of trigger on insert/update I could push the required information from table B down to table C. > -> so i would only require to select from table C. > > > My question: > 1) From your experience ... how much faster (approximately) in percent do you regard Scenario B faster than A ? You're assuming that B is always going to be faster than A, which certainly isn't a foregone conclusion. Let's say that you average 10 bytes per column. In scenario A, the total data size is then roughly 3,000,000 * 20 * 10 + 30,000,000 * 10 * 10 = 3.6 GiB. In scenario B due to your denormalization, the total data size is more like 30,000,000 * 30 * 10 = 9 GiB, or 2.5 times more raw data. That's a lot of extra disk IO, unless your database will always fit in memory in both scenarios. Although you didn't provide enough data to answer with certainty, I would go on the assumption that A is going to be faster than B. But even if it weren't, remember that premature optimization is the root of all evil. If you try A and it doesn't perform fast enough, then you can always try B later to see if it works any better. -- Mark Lewis