Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1htK0i-0004Sw-H3 for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Aug 2019 22:57:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1htK0h-0007hr-7J for pgsql-hackers@arkaria.postgresql.org; Thu, 01 Aug 2019 22:57:23 +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_SHA1:256) (Exim 4.89) (envelope-from ) id 1htK0g-0007hk-VH for pgsql-hackers@lists.postgresql.org; Thu, 01 Aug 2019 22:57:23 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1htK0e-0006pK-BJ for pgsql-hackers@lists.postgresql.org; Thu, 01 Aug 2019 22:57:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x71MvGjR024411; Thu, 1 Aug 2019 18:57:16 -0400 From: Tom Lane To: Anastasia Lubennikova cc: pgsql-hackers@lists.postgresql.org Subject: Re: Optimze usage of immutable functions as relation In-reply-to: <18cbbbf6-5c03-41d5-5bd4-30048c2e5155@postgrespro.ru> References: <402356c32eeb93d4fed01f66d6c7fe2d@postgrespro.ru> <20180906185109.661aaef0@asp437-ThinkPad-L380> <153994199621.10161.17815885396545049364.pgcf@coridan.postgresql.org> <2906.1542395026@sss.pgh.pa.us> <3f7fda2f-1cdc-8ad3-e3c9-c2436fb5d509@postgrespro.ru> <0dd4efb2-22a3-6fef-11f7-1b20dd71a509@postgrespro.ru> <18924.1564165560@sss.pgh.pa.us> <18cbbbf6-5c03-41d5-5bd4-30048c2e5155@postgrespro.ru> Comments: In-reply-to Anastasia Lubennikova message dated "Thu, 01 Aug 2019 20:54:10 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24409.1564700236.1@sss.pgh.pa.us> Date: Thu, 01 Aug 2019 18:57:16 -0400 Message-ID: <24410.1564700236@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Anastasia Lubennikova writes: > Thank you for pointing out on specific of int4() function, > I updated tests to use dummy plpgsql function. > I'm not sure if tests of various join types are redundant but I left them. > As far as I understand, the principal motivation of this patch was to > optimize > function scan joins that occur in FTS queries. For example: > select * from test_tsquery, to_tsquery('english', 'new') q where > txtsample @@ q; > So I also added another test to tsearch.sql to illustrate difference > between optimized and not optimized plans. Fair enough. I've pushed this after a good deal of further hackery on the code. Notably * I had no faith that we still guaranteed to perform eval_const_expressions on every function-RTE expression. Even if that were true today, it'd be awfully easy to break in future, if it only happened somewhere down in the recursion in pull_up_subqueries_recurse. So I moved that responsibility to an earlier spot that clearly traverses all function RTEs. A happy side benefit is that inline_set_returning_function gets simpler because it can assume that that already happened. * It looked to me like the pullup_constant_function code wasn't covering all the places where it might need to replace Vars referencing the function RTE. I refactored things to avoid having a bunch of code duplication while ensuring it hits everyplace that pull_up_simple_subquery does. regards, tom lane