Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id EE2C4AA49B5 for ; Fri, 11 Nov 2011 12:55:52 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 60150-10 for ; Fri, 11 Nov 2011 16:55:47 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from mail.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by mail.postgresql.org (Postfix) with ESMTP id 05998AA49B4 for ; Fri, 11 Nov 2011 12:55:47 -0400 (AST) Received: from [192.168.1.36] (dell36.office.archonet.com [192.168.1.36]) by mail.archonet.com (Postfix) with ESMTP id 28C687C041; Fri, 11 Nov 2011 16:55:44 +0000 (GMT) Message-ID: <4EBD5390.5060804@archonet.com> Date: Fri, 11 Nov 2011 16:55:44 +0000 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Lightning/1.0b2 Thunderbird/3.1.15 MIME-Version: 1.0 To: Sorin Dudui CC: Julius Tuskenis , "pgsql-performance@postgresql.org" Subject: Re: where clause + function, execution order References: <13DE38ECCB7CE74890E7150A7CCB610D3642DD47@exc1.wigeo.lan> <4EBD4518.5070508@nsoft.lt> <4EBD4675.2060604@archonet.com> <13DE38ECCB7CE74890E7150A7CCB610D3642DD75@exc1.wigeo.lan> In-Reply-To: <13DE38ECCB7CE74890E7150A7CCB610D3642DD75@exc1.wigeo.lan> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.918 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RDNS_DYNAMIC=0.982 X-Spam-Level: X-Archive-Number: 201111/144 X-Sequence-Number: 45655 On 11/11/11 16:28, Sorin Dudui wrote: > Hi, > > this is the EXPLAIN ANALYSE output: > > > "Merge Left Join (cost=0.00..2820.34 rows=23138 width=777) (actual time=0.049..317.935 rows=26809 loops=1)" > " Merge Cond: ((a.admin10)::text = (b.link_id)::text)" > " -> Index Scan using admin_lookup_admin10 on admin_lookup a (cost=0.00..845.04 rows=5224 width=742) (actual time=0.015..40.263 rows=8100 loops=1)" > " Filter: (((admin40)::text<> '-1'::text) AND (((admin40)::text = 'ITA10'::text) OR ((admin40)::text = 'ITA15'::text) OR ((admin40)::text = 'ITA19'::text) OR ((admin40)::text = 'ITA04'::text) OR ((admin40)::text = 'ITA09'::text) OR ((admin40)::text = 'ITA03'::text) OR ((admin40)::text = 'ITA08'::text) OR ((admin40)::text = 'ITA17'::text) OR ((admin40)::text = 'ITA02'::text) OR ((admin40)::text = 'ITA18'::text) OR ((admin40)::text = 'ITA01'::text) OR ((admin40)::text = 'ITA20'::text) OR ((admin40)::text = 'ITA13'::text) OR ((admin40)::text = 'ITA11'::text) OR ((admin40)::text = 'ITA14'::text) OR ((admin40)::text = 'ITA16'::text) OR ((admin40)::text = 'ITA07'::text) OR ((admin40)::text = 'ITA06'::text) OR ((admin40)::text = 'ITA12'::text) OR ((admin40)::text = 'ITA05'::text)))" > " -> Index Scan using reg_data_a08id_copy on registrations_data b (cost=0.00..1496.89 rows=24174 width=45) (actual time=0.008..70.408 rows=24174 loops=1)" > "Total runtime: 372.765 ms" That certainly looks like it's been inlined. You are testing for "ITA10", "ITA15" etc outside the function-call, no? It's pushing those tests down, using index "admin_lookup_admin10" to test for them then joining afterwards. -- Richard Huxton Archonet Ltd