Received: from localhost (unknown [200.46.204.183]) by developer.postgresql.org (Postfix) with ESMTP id BEB8B2E002E for ; Fri, 16 May 2008 15:27:19 -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 06552-03 for ; Fri, 16 May 2008 15:27:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from po-out-1718.google.com (po-out-1718.google.com [72.14.252.157]) by developer.postgresql.org (Postfix) with ESMTP id 8C9F12E002D for ; Fri, 16 May 2008 15:27:11 -0300 (ADT) Received: by po-out-1718.google.com with SMTP id y22so462816pof.3 for ; Fri, 16 May 2008 11:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=Dh85KfRdoSC8c6+1RhAGZqfVK2dG2uEMCyEpHHeyR8o=; b=ClQQ8dbOnjnWXidTPleNcJiDVR82xJ8YLyTHKDG/eUuw2yGSUnlk5QgB//hRWIMPq6qKMvY8Pr28Va2xQBKmW6upf/coYdRU2rp+RVUC11glNQ0EeoZk8Hx2dHFyIY5ULPTrAQzbVJO+BzR1+OYctXPjIfyG/nsbuLvejEwkXa0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=oTkyPlrSlNtFHE9UoPASAj0d7fWSuV8PYYdNokyCR+mC4onkxoOg/Bw1DxceWhE8b5KF6mBegiHMpGVj6fiesZeqGy3UY/V2NuK3KUFr5TzXchT4bPyK1W3B5MBA8AEtouInBmFjS2XS9y158H5WuKa+7VMMHdj6XCBVQej/Mlk= Received: by 10.114.66.8 with SMTP id o8mr4013303waa.135.1210962429764; Fri, 16 May 2008 11:27:09 -0700 (PDT) Received: by 10.114.137.7 with HTTP; Fri, 16 May 2008 11:27:09 -0700 (PDT) Message-ID: Date: Fri, 16 May 2008 12:27:09 -0600 From: "Scott Marlowe" To: Ben Subject: Re: very slow left join Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/252 X-Sequence-Number: 30220 On Fri, May 16, 2008 at 12:21 PM, Ben wrote: > 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. Well, I'm guessing that you aren't in locale=C and that the text functions in your query aren't indexed. Try creating an index on them something like: create index abc_txtfield_func on mytable (substring(textfield,1,5)); etc and see if that helps. As for the char type, I totally understand the issue, having inherited oracle dbs before...