Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOPdP-00013V-Jr for pgsql-general@arkaria.postgresql.org; Mon, 11 Dec 2017 15:04:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eOPdO-0001an-Mm for pgsql-general@arkaria.postgresql.org; Mon, 11 Dec 2017 15:04:46 +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.84_2) (envelope-from ) id 1eOPdO-0001ac-CG for pgsql-general@lists.postgresql.org; Mon, 11 Dec 2017 15:04:46 +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 1eOPdH-0006pE-Jf for pgsql-general@postgresql.org; Mon, 11 Dec 2017 15:04:45 +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 vBBF4bga024893; Mon, 11 Dec 2017 10:04:37 -0500 From: Tom Lane To: Jim Finnerty cc: pgsql-general@postgresql.org Subject: Re: Removing INNER JOINs In-reply-to: <1512999483420-0.post@n3.nabble.com> References: <1512966801439-0.post@n3.nabble.com> <1512999483420-0.post@n3.nabble.com> Comments: In-reply-to Jim Finnerty message dated "Mon, 11 Dec 2017 06:38:03 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <24891.1513004677.1@sss.pgh.pa.us> Date: Mon, 11 Dec 2017 10:04:37 -0500 Message-ID: <24892.1513004677@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jim Finnerty writes: > Great example, David. The planner can detect whether a SELECT statement > contains a volatile function, and can disable the proposed redundant > inner-join optimization in that case. > If necessary, the planner could also check that the FK constraint is not > DEFERRED, but if there are no volatile functions and the SELECT statement > can't see an inconsistent state created by any other transaction, I think > that just checking for volatile functions and not being inside a DML > transaction would be sufficient. I don't think you're thinking nearly hard enough about what would break this. The planner does not have much insight into the context a statement is being used in (e.g. whether we're inside some kind of PL function). Nor does it get to make assumptions about whether the plan will be used inside a transaction block or not. regards, tom lane