Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fOmND-0000Sp-IR for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jun 2018 15:53:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fOmNB-0007mU-NR for pgsql-hackers@arkaria.postgresql.org; Fri, 01 Jun 2018 15:53:49 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fOmNB-0007mL-D8 for pgsql-hackers@lists.postgresql.org; Fri, 01 Jun 2018 15:53:49 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fOmN4-0008JS-Px for pgsql-hackers@lists.postgresql.org; Fri, 01 Jun 2018 15:53:48 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w51FrdUO010015; Fri, 1 Jun 2018 11:53:39 -0400 From: Tom Lane To: Ashutosh Bapat cc: Dmitry Dolgov <9erthalion6@gmail.com>, Pavel Stehule , PostgreSQL Hackers Subject: Re: why partition pruning doesn't work? In-reply-to: References: Comments: In-reply-to Ashutosh Bapat message dated "Fri, 01 Jun 2018 11:43:55 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7141.1527868419.1@sss.pgh.pa.us> Date: Fri, 01 Jun 2018 11:53:39 -0400 Message-ID: <7142.1527868419@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ashutosh Bapat writes: > I think the patch is right if we were to handle only SQLValueFunction, > but the bigger picture here is that we aren't evaluating stable > functions before run-time partition pruning happens. I was under the > impression that the stable functions/expressions get evaluated and > folded into a constant just before the execution begins since a stable > function produces the same output for same input during one execution > invocation. But I am not able to find where we do that and probably we > don't do that at all. We don't; there was a patch floating around to make that happen, but it hasn't been updated lately. I agree though that it seems strange to special-case SQLValueFunction rather than any-stable-expression. As long as the evaluation happens at executor start (i.e. with the query's run-time snapshot) it should be reasonable to simplify any stable expression. It's worth questioning whether this is a bug fix or an improvement. If the latter, it probably ought to wait for v12. regards, tom lane