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 1ffmaS-0002wN-JQ for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Jul 2018 13:33:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1ffmaR-0004Qu-BZ for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Jul 2018 13:33:47 +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 1ffmZt-0001qn-6Y for pgsql-hackers@lists.postgresql.org; Wed, 18 Jul 2018 13:33:13 +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 1ffmZi-0005k8-40 for pgsql-hackers@lists.postgresql.org; Wed, 18 Jul 2018 13:33:11 +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 w6IDWqDP007501; Wed, 18 Jul 2018 09:32:52 -0400 From: Tom Lane To: Amit Langote cc: Robert Haas , David Rowley , Dmitry Dolgov <9erthalion6@gmail.com>, Jeff Janes , Ashutosh Bapat , Pavel Stehule , PostgreSQL Hackers Subject: Re: why partition pruning doesn't work? In-reply-to: References: <21787.1528428171@sss.pgh.pa.us> <17850.1528755844@sss.pgh.pa.us> <19365.1528820758@sss.pgh.pa.us> <30981.1528822481@sss.pgh.pa.us> <637.1528863347@sss.pgh.pa.us> <28597.1528900759@sss.pgh.pa.us> <27099.1528987211@sss.pgh.pa.us> <56f1556c-6d6e-aaf8-de4f-a790a1efa5a3@l! ab.ntt.co.jp> <29987.1529341511@sss.pgh.pa.us> <4114.1531674142@sss.pgh.pa.us> Comments: In-reply-to Amit Langote message dated "Wed, 18 Jul 2018 17:59:52 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <7499.1531920772.1@sss.pgh.pa.us> Date: Wed, 18 Jul 2018 09:32:52 -0400 Message-ID: <7500.1531920772@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Amit Langote writes: > On 2018/07/16 2:02, Tom Lane wrote: >> BTW, there'd be a lot to be said for having InitPlan just open all >> the rels and build an array of Relation pointers that parallels the >> RTE list, rather than doing heap_opens in random places elsewhere. > +1 to this. Actually I had written such a patch in place of the one I > posted on this thread, but wasn't confident enough that I had found and > fixed all the places in the executor that would use the Relation pointer > from there instead of fetching it themselves. Well, it doesn't have to be a 100% conversion, especially not to start out with. As long as we ensure that common code paths through the executor have only one open/close per rel, I don't think it matters too much if there are some corner cases with more. Also, tracking down places like that wouldn't be that hard to do. One could instrument the relcache to report situations where a rel's refcount gets above 1. (The infrastructure for logging backtraces that's being discussed in other threads would help here.) We might decide that particular cases weren't worth fixing --- eg if the extra open is happening in code that doesn't have easy access to the EState --- but I doubt that finding them is impractical. regards, tom lane