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 1hRIu9-0007BU-L3 for pgsql-bugs@arkaria.postgresql.org; Thu, 16 May 2019 16:06:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hRIu8-00058m-Dq for pgsql-bugs@arkaria.postgresql.org; Thu, 16 May 2019 16:06:48 +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 1hRIu8-00058f-6a for pgsql-bugs@lists.postgresql.org; Thu, 16 May 2019 16:06:48 +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 1hRIu5-0000Zs-WB for pgsql-bugs@lists.postgresql.org; Thu, 16 May 2019 16:06:47 +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 x4GG6bOL014872; Thu, 16 May 2019 12:06:38 -0400 From: Tom Lane To: Amit Langote cc: David Rowley , Kyotaro HORIGUCHI , Alan Jackson , PostgreSQL mailing lists Subject: Re: inconsistent results querying table partitioned by date In-reply-to: References: <90aeaf38-270a-7e45-6b7d-af2e3d1e3719@lab.ntt.co.jp> <20307.1557522309@sss.pgh.pa.us> <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> Comments: In-reply-to Amit Langote message dated "Thu, 16 May 2019 18:31:30 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <14870.1558022797.1@sss.pgh.pa.us> Date: Thu, 16 May 2019 12:06:37 -0400 Message-ID: <14871.1558022797@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > Given the way gen_partprune_steps() is designed [1], while it may be > possible to discard steps generated by run-time pruning that need not be > applied during execution because they would've already been fully applied > during plan-time pruning, it seems hard to keep around *partial* steps > generated during plan-time pruning and use them for run-time pruning after > filling missing expressions from run-time quals. Filling the missing > expressions into existing steps part seems hard. Yeah. It seems like the way to make some progress on this would be to annotate the steps when they're generated as to whether they involve any run-time component or not. However, we might end up making multiple calls anyway because of the possibility of parameterized paths having additional qual clauses to work with, so I'm not clear on exactly how we could reduce the number of times we do gen_partprune_steps. It's not something we could fix now in any case. However, I'm still not real happy with analyze_partkey_exprs(); its analysis seems well short of ideal. I notice that in the sort of case suggested upthread, with more than one opclause contributing to a step, it's entirely possible for it to report that both initial and runtime pruning are needed even though only the latter is really possible. Perhaps this could be improved a bit by making the analysis operate per-step rather than being totally per-expression. Anyway, I've pushed David's patch now, on to look at Amit's. regards, tom lane