Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id 2EFB12E0035 for ; Fri, 16 May 2008 15:21:40 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 02978-01 for ; Fri, 16 May 2008 15:21:22 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mail.silentmedia.com (earth.silentmedia.com [216.254.19.12]) by developer.postgresql.org (Postfix) with ESMTP id 04C562E002E for ; Fri, 16 May 2008 15:21:07 -0300 (ADT) Received: by mail.silentmedia.com (Postfix, from userid 99) id 00CD6876A; Fri, 16 May 2008 11:21:05 -0700 (PDT) Received: from GRD (GRD [10.125.42.6]) by mail.silentmedia.com (Postfix) with ESMTP id 4966A873E; Fri, 16 May 2008 11:21:05 -0700 (PDT) Date: Fri, 16 May 2008 11:21:04 -0700 (PDT) From: Ben X-X-Sender: bench@localhost.localdomain To: Scott Marlowe cc: pgsql-performance@postgresql.org Subject: Re: very slow left join In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/250 X-Sequence-Number: 30218 On Fri, 16 May 2008, Scott Marlowe wrote: > Just for giggles, try running the query like so: > > set enable_nestloop = off; > explain analyze ... > > and see what happens. I'm guessing that the nested loops are bad choices here. You guess correctly, sir! Doing so shaves 3 orders of magnitude off the runtime. That's nice. :) But that brings up the question of why postgres thinks nested loops are the way to go? It would be handy if I could make it guess correctly to begin with and didn't have to turn nested loops off each time I run this. >> Table "public.event" >> Column | Type | Modifiers >> ----------------+-----------------------------+------------------------ >> clientkey | character(30) | not null >> premiseskey | character(30) | not null >> eventkey | character(30) | not null >> severitykey | character(30) | > > Do these really need to be character and not varchar? varchar / text > are better optimized in pgsql, and character often need to be cast > anyway, so you might as well start with varchar. Unless you REALLY > need padding in your db, avoid char(x). Unfortuantely, the people who created this database made all keys 30 character strings, and we're not near a place in our release cycle where we can fix that.