Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 7E26B632A0A for ; Thu, 7 Jan 2010 23:45:20 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 33424-04 for ; Fri, 8 Jan 2010 03:45:09 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by mail.postgresql.org (Postfix) with ESMTP id 0D4DB6339B1 for ; Thu, 7 Jan 2010 23:45:09 -0400 (AST) Received: from localhost (access [127.0.0.1]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 38DC21E0439; Fri, 8 Jan 2010 11:45:05 +0800 (WST) X-Virus-Scanned: Debian amavisd-new at postnewspapers.com.au Received: from mail.postnewspapers.com.au ([127.0.0.1]) by localhost (access.postnewspapers.com.au [127.0.0.1]) (amavisd-new, port 10024) with LMTP id R4437+puJkre; Fri, 8 Jan 2010 11:45:03 +0800 (WST) Received: from [10.1.1.6] (124-169-133-89.dyn.iinet.net.au [124.169.133.89]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "Craig Ringer", Issuer "POST Certificate Authority" (verified OK)) by mail.postnewspapers.com.au (Postfix) with ESMTPSA id D8A141E0437; Fri, 8 Jan 2010 11:45:01 +0800 (WST) Message-ID: <4B46AA3C.7000107@postnewspapers.com.au> Date: Fri, 08 Jan 2010 11:45:00 +0800 From: Craig Ringer User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: Nikolas Everett CC: "Gurgel, Flavio" , Matthew Wakeling , Lefteris , pgsql-performance@postgresql.org, Ivan Voras Subject: Re: Air-traffic benchmark References: <21301378.46621262884592029.JavaMail.root@mail.4linux.com.br> <27470544.48331262887021660.JavaMail.root@mail.4linux.com.br> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=3.189 tagged_above=-10 required=5 tests=BAYES_50=0.001, FH_DATE_PAST_20XX=3.188 X-Spam-Level: *** X-Archive-Number: 201001/135 X-Sequence-Number: 37015 On 8/01/2010 2:11 AM, Nikolas Everett wrote: > This table is totally unnormalized. Normalize it and try again. You'll > probably see a huge speedup. Maybe even 10x. My mantra has always been > less data stored means less data to scan means faster scans. Sometimes one intentionally denormalizes storage, though. JOIN costs can be considerable too, and if most of the time you're interested in all the data for a record not just a subset of it, storing it denormalized is often faster and cheaper than JOINing for it or using subqueries to fetch it. Normalization or any other splitting of record into multiple separately stored records also has costs in complexity, management, the need for additional indexes, storage of foreign key references, all the extra tuple headers you need to store, etc. It's still generally the right thing to do, but it should be thought about, not just tackled blindly. I only tend to view it as a no-brainer if the alternative is storing numbered fields ("field0", "field1", "field2", etc) ... and even then there are exceptions. One of my schema at the moment has address_line_1 through address_line_4 in a `contact' entity, and there's absolutely *no* way I'm splitting that into a separate table of address_lines accessed by join and sort! (Arguably I should be using a single `text' field with embedded newlines instead, though). Sometimes it's even better to hold your nose and embed an array in a record rather than join to an external table. Purism can be taken too far. Note that Pg's TOAST mechanism plays a part here, too. If you have a big `text' field, it's probably going to get stored out-of-line (TOASTed) anyway, and TOAST is going to be cleverer about fetching it than you will be using a JOIN. So storing it in-line is likely to be the right way to go. You can even force out-of-line storage if you're worried. In the case of this benchmark, even if they split much of this data out into other tables by reference, it's likely to be slower rather than faster if they still want the data they've split out for most of their queries. -- Craig Ringer