Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpvXv-009X6A-Ev for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Mar 2024 19:36:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rpvXu-002a77-FQ for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Mar 2024 19:36:18 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpvXu-002a6f-6R for pgsql-hackers@lists.postgresql.org; Thu, 28 Mar 2024 19:36:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rpvXq-006vqA-K6 for pgsql-hackers@lists.postgresql.org; Thu, 28 Mar 2024 19:36:16 +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 42SJaEWR3703024; Thu, 28 Mar 2024 15:36:14 -0400 From: Tom Lane To: David Rowley cc: Richard Guo , Alexander Lakhin , PostgreSQL Developers Subject: Re: Properly pathify the union planner In-reply-to: References: <242fc7c6-a8aa-2daf-ac4c-0a231e2619c1@gmail.com> <3485967.1711594595@sss.pgh.pa.us> Comments: In-reply-to David Rowley message dated "Thu, 28 Mar 2024 16:06:46 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3703022.1711654574.1@sss.pgh.pa.us> Date: Thu, 28 Mar 2024 15:36:14 -0400 Message-ID: <3703023.1711654574@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > The problem is informing the UNION child query about what it is. I > thought I could do root->parent_root->parse->setOperations for a UNION > child to know what it is, but that breaks for a query such as: Yeah, having grouping_planner poke into the parent level doesn't seem like a great idea here. I continue to not like the name "PlannerContext" but I agree passing down the setop explicitly is the way to go. >> Perhaps "SubqueryContext" or the like would be better? It >> still has the conflict with memory contexts though. > Maybe something with "Parameters" in the name? SubqueryParameters might be OK. Or SubqueryPlannerExtra? Since this is a bespoke struct that will probably only ever be used with subquery_planner, naming it after that function seems like a good idea. (And, given that fact and the fact that it's not a Node, I'm not sure it belongs in pathnodes.h. We could just declare it in planner.h.) Some minor comments now that I've looked at 66c0185a3 a little: * Near the head of grouping_planner is this bit: if (parse->setOperations) { /* * If there's a top-level ORDER BY, assume we have to fetch all the * tuples. This might be too simplistic given all the hackery below * to possibly avoid the sort; but the odds of accurate estimates here * are pretty low anyway. XXX try to get rid of this in favor of * letting plan_set_operations generate both fast-start and * cheapest-total paths. */ if (parse->sortClause) root->tuple_fraction = 0.0; I'm pretty sure this comment is mine, but it's old enough that I don't recall exactly what I had in mind. Still, it seems like your patch has addressed precisely the issue of generating fast-start plans for setops. Should we now remove this reset of tuple_fraction? * generate_setop_child_grouplist does this: /* assign a tleSortGroupRef, or reuse the existing one */ sgc->tleSortGroupRef = assignSortGroupRef(tle, targetlist); tle->ressortgroupref = sgc->tleSortGroupRef; That last line is redundant and confusing. It is not this code's charter to change ressortgroupref. regards, tom lane