Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnACO-0004Or-MY for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jun 2020 00:20:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jnACN-0003A3-G4 for pgsql-hackers@arkaria.postgresql.org; Mon, 22 Jun 2020 00:20:31 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnACN-00039c-90 for pgsql-hackers@lists.postgresql.org; Mon, 22 Jun 2020 00:20:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jnACK-0001Xu-9E for pgsql-hackers@lists.postgresql.org; Mon, 22 Jun 2020 00:20:30 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 05M0KPe71992953 for ; Sun, 21 Jun 2020 20:20:25 -0400 From: Tom Lane To: pgsql-hackers@lists.postgresql.org Subject: Get rid of runtime handling of AlternativeSubPlan? MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1992951.1592785225.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 21 Jun 2020 20:20:25 -0400 Message-ID: <1992952.1592785225@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Back in bd3daddaf232d95b0c9ba6f99b0170a0147dd8af, which introduced AlternativeSubPlans, I wrote: = There is a lot more that could be done based on this infrastructure: in particular it's interesting to consider switching to the hash plan if we= start out using the non-hashed plan but find a lot more upper rows going by th= an we expected. I have therefore left some minor inefficiencies in place, suc= h as initializing both subplans even though we will currently only use one. That commit will be twelve years old come August, and nobody has either built anything else atop it or shown any interest in making the plan choic= e switchable mid-run. So it seems like kind of a failed experiment. Therefore, I'm considering the idea of ripping out all executor support for AlternativeSubPlan and instead having the planner replace an AlternativeSubPlan with the desired specific SubPlan somewhere late in planning, possibly setrefs.c. Admittedly, the relevant executor support only amounts to a couple hundred lines, but that's not nothing. A perhaps-more-useful effect is to get rid of the confusing and poorly documented EXPLAIN output that you get for an AlternativeSubPlan. I also noted that the existing subplan-selection logic in ExecInitAlternativeSubPlan is really pretty darn bogus, in that it uses a one-size-fits-all execution count estimate of parent->plan->plan_rows, no matter which subexpression the subplan is in. This is only appropriate for subplans in the plan node's targetlist, and can be either too high or too low elsewhere. It'd be relatively easy for setrefs.c to do better, I think, since it knows which subexpression it's working on at any point. Thoughts? regards, tom lane