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 1hS0n3-0007ad-Mj for pgsql-bugs@arkaria.postgresql.org; Sat, 18 May 2019 14:58:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hS0n1-0000GB-9g for pgsql-bugs@arkaria.postgresql.org; Sat, 18 May 2019 14:58: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 1hS0n1-0000FH-1U for pgsql-bugs@lists.postgresql.org; Sat, 18 May 2019 14:58: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 1hS0mx-0002FJ-SZ for pgsql-bugs@lists.postgresql.org; Sat, 18 May 2019 14:58: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 x4IEwBcm020740; Sat, 18 May 2019 10:58:11 -0400 From: Tom Lane To: David Rowley cc: Amit Langote , Kyotaro HORIGUCHI , Alan Jackson , PostgreSQL mailing lists Subject: Re: inconsistent results querying table partitioned by date In-reply-to: References: <28453.1557867500@sss.pgh.pa.us> <588f56cb-aaed-14b0-8a21-13486bd1c706@lab.ntt.co.jp> <10502.1557941878@sss.pgh.pa.us> <23372.1557966530@sss.pgh.pa.us> <14871.1558022797@sss.pgh.pa.us> <12600.1558034735@sss.pgh.pa.us> <7099.1558047050@sss.pgh.pa.us> <14101.1558128611@sss.pgh.pa.us>! Comments: In-reply-to David Rowley message dated "Sun, 19 May 2019 02:39:06 +1200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20738.1558191491.1@sss.pgh.pa.us> Date: Sat, 18 May 2019 10:58:11 -0400 Message-ID: <20739.1558191491@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk David Rowley writes: > Thanks for working on this. I did have a look and was a bit > disappointed to see the code will end up calling pull_exec_paramids() > 3 times for any expression with exec param IDs. I can knock that down > to just 2 by caching the exec Param IDs of the used quals in > GeneratePruningStepsContext. I imagine you didn't do this since its > possible we reject the qual even after has_exec_param is set, Exactly. > but if > we just delay recording the param IDs until after we're certain we're > using the qual then it should be safe to do this. I thought about that too, but it seems awfully messy/fragile; it's not clear to me at what point this code is really guaranteed to have accepted a clause. The recursion for AND/OR, in particular, seems to make that kind of questionable. If we could be sure about that I'd be inclined to apply the principle to the has_mutable_arg and has_exec_param flags as well as exec_paramids, and change the order of tests in match_clause_to_partition_key back to what it was, relying on the outer control layer to not propagate that data into the overall state until we knew whether the clause was really going to contribute to the steps. regards, tom lane