Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 110C52E00EC for ; Mon, 21 Jan 2008 11:17:24 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 61820-07 for ; Mon, 21 Jan 2008 11:17:14 -0400 (AST) Received: from nf-out-0910.google.com (nf-out-0910.google.com [64.233.182.191]) by postgresql.org (Postfix) with ESMTP id 165AD2E00C3 for ; Mon, 21 Jan 2008 11:17:19 -0400 (AST) Received: by nf-out-0910.google.com with SMTP id f5so242356nfh.23 for ; Mon, 21 Jan 2008 07:17:16 -0800 (PST) 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=fAGS61GDQc4CTivdEosv7yWVcPUUW0+rl4YoElKw+kc=; b=dcQOFhZyQopZyXTo5ekFkVUnkkCbVMYfcvLBjZ4rYTej8Y39580FWLO5wJQ2dX4ZoNQ6Ey/iS5fiD+C9+7rhza7X4+Jl7l3wD9LPaJtzCV7gPWsy7l3+BV/fRf/l2chJhVtNZuhKDrv9mht6N6xc3cFSRqxdCIrmjpEF7MfLsU8= 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=bjk0QFI9BBSddY/AYzdpBZDrL9PxQAVuktI9xAC51DYrhToHc0i7ZgQPTrged2M0ViJknDc3rBsKlutNxobXEHkitnI5V89GqhTKIkywMwrGxig3OrzGKnhtZ0cXNbsGRr2GLTKcX7SSD8QesF/Qc9LC+PI+OWzWKJD/0Y73Lvw= Received: by 10.78.186.9 with SMTP id j9mr9232556huf.24.1200928636144; Mon, 21 Jan 2008 07:17:16 -0800 (PST) Received: by 10.78.35.7 with HTTP; Mon, 21 Jan 2008 07:17:16 -0800 (PST) Message-ID: <162867790801210717v43c7163eu9b413ae6418b5b5c@mail.gmail.com> Date: Mon, 21 Jan 2008 16:17:16 +0100 From: "Pavel Stehule" To: "Marten Verhoeven" Subject: Re: Slow performance with left outer join Cc: pgsql-performance@postgresql.org In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/159 X-Sequence-Number: 28398 Hello please, send output EXPLAIN ANALYZE statement Regards Pavel Stehule On 21/01/2008, Marten Verhoeven wrote: > > > Hi, > > Since I moved from PostgreSQL 7.3 to 8.2 I have a query which suddenly runs > very slow. In 7.3 it was really fast. It seems that the query analyser makes > other choices, which I don't understand. > > I have the query: > > SELECT * FROM fpuArticle > LEFT OUTER JOIN fpuArticleText ON a_No=at_a_No AND coalesce(at_Type,1)=1 > AND coalesce(at_Language,0)=0 > WHERE strpos(lower(coalesce(a_Code,'') || ' ' || > coalesce(at_Text,'')), 'string')>0 > > when I use a normal join, this query is very fast, but with this left outer > join it is slow. > > This is the query analysis: > > Nested Loop Left Join (cost=1796.69..3327.98 rows=5587 width=516) > Join Filter: (fpuarticle.a_no = fpuarticletext.at_a_no) > Filter: (strpos(lower((((COALESCE(fpuarticle.a_code, ''::character > varying))::text || ' '::text) || (COALESCE(fpuarticletext.at_text, > ''::character varying))::text)), 'string'::text) > 0) > -> Seq Scan on fpuarticle (cost=0.00..944.62 rows=16762 width=386) > -> Materialize (cost=1796.69..1796.70 rows=1 width=130) > -> Seq Scan on fpuarticletext (cost=0.00..1796.69 rows=1 > width=130) > Filter: ((COALESCE((at_type)::integer, 1) = 1) AND > (COALESCE(at_language, 0::numeric) = 0::numeric)) > > It seems that the filter on at_type and at_Language is used at the and, > while it is much faster to use it at the beginning. Why is this, and how can > I influence this? > > With kind regards > > Marten Verhoeven > Van Beek B.V.