Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dOQck-0007jJ-HU for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Jun 2017 15:35:54 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dOQck-0000vQ-4J for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Jun 2017 15:35:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dOQc2-00084F-JJ for pgsql-bugs@postgresql.org; Fri, 23 Jun 2017 15:35:10 +0000 Received: from know-smtprelay-omc-7.server.virginmedia.net ([80.0.253.71]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dOQc0-0003W3-0t for pgsql-bugs@postgresql.org; Fri, 23 Jun 2017 15:35:10 +0000 Received: from vm-cliveevans-d03.circle.byhiras.com ([195.110.85.254]) by know-smtprelay-7-imp with bizsmtp id cFb61v00H5VEh2z01Fb6mS; Fri, 23 Jun 2017 16:35:06 +0100 X-Originating-IP: [195.110.85.254] X-Authenticated-User: cliveevans@ntlworld.com X-Spam: 0 X-Authority: v=2.1 cv=Gd7q5ljL c=1 sm=1 tr=0 a=krHGFvvOGbZX40VCRH9Y2g==:117 a=krHGFvvOGbZX40VCRH9Y2g==:17 a=L9H7d07YOLsA:10 a=9cW_t1CCXrUA:10 a=s5jvgZ67dGcA:10 a=IkcTkHD0fZMA:10 a=x7bEGLp0ZPQA:10 a=NLZqzBF-AAAA:8 a=epTmVMiNAAAA:8 a=QUeKKpFT7K-tA0zApRkA:9 a=QEXdDO2ut3YA:10 a=wW_WBVUImv98JQXhvVPZ:22 a=ndEWmUVY6Yapc0oHF_P4:22 Subject: Re: BUG #14715: Constraint exclusion isn't used in function using language sql To: pgsql-bugs@postgresql.org References: <20170621140056.27883.82221@wrigleys.postgresql.org> <20170623.103957.31224862.horiguchi.kyotaro@lab.ntt.co.jp> From: Clive Evans Message-ID: <6b87f600-ef33-b3b7-79b8-f5f1659e1908@ntlworld.com> Date: Fri, 23 Jun 2017 15:35:06 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ntlworld.com; s=meg.feb2017; t=1498232106; bh=dMXVA0gfG+H+264oy1eS4rGVPrz18oNqTOIsnRlpasw=; h=Subject:To:References:From:Date:In-Reply-To; b=nzjWr1VMKoOJEiob4K45pD09In0yh4M/BJv8Gne8JgltuhALJoSVwzdgWr1UTDtpO 9HOjnNQi1zxJhlCR/f81Gh40lQbZS4sXNxo85vGcpDQvApYK0J4Bw/71Rq2uY5G57d Zau2X8jeQlXqmG+rjZ+y7KgTqpEjTmCi/+wzrpoGbkO8EUdOCU2+Kv0AgVRgB2JIjH JEEg9k9a5dFjvDjPZic5C7cOv81eOnuVRkwLorGYRctF3s+snfCgThX6g+BDZKHENW /CdNzH2EKy8oke5DHN38d2dsYkZdRfIJRQ9nDZZ7Fr+qAhLH2TsVua5AZ/JfTxXIlC 5tgl1k8TRGWaw== List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 23/06/17 08:59, Clive Evans wrote: > > > On 23/06/17 01:39, Kyotaro HORIGUCHI wrote: >> Hello, >> >> At Wed, 21 Jun 2017 14:00:56 +0000,cliveevans@ntlworld.com wrote in<20170621140056.27883.82221@wrigleys.postgresql.org> >>> PostgreSQL version: 9.6.3 >> ... >>> The same query written using PL/PGSQL will only scan the expected partition >>> tables. >> The two are different in that the parameters of the PL/PgSQL >> function are regarded as constants at the time of planning of the >> inner SQL statement, while those of the SQL function are >> not. Constraint exclusion is considered while planning so the SQL >> function doesn't get benefit of it. > > I understand this, and I understand why. You can't plan based on what > you don't yet know. I'm not entirely clear why the inner query can > treat the parameter as a constant, whereas the outer one is forced to > treat it as dynamic. > > I assume it's something to do with when the plan is created. Possibly > it's an attempt to save the planning time and re-use the plan in the > case of a 'normal' SQL function, although this seems like a trade off > that may well have significant downsides - in this case obviously, but > also others. > > Perhaps I'm looking for a new feature, rather than reporting a bug. > Something that allows lazy planning, where there's a good chance that > treating the parameters as constants is likely to improve the produced > plan sufficiently to offset the additional overhead of repeatedly > planning. Sorry, mail client went a bit rogue. Here it is again, (hopefully) legibly ... thanks, Clive -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs