Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4a8a5dd

Browse files
author
Etsuro Fujita
committed
Improve comments for trivial_subqueryscan().
This function can be called from mark_async_capable_plan(), a helper function for create_append_plan(), before set_subqueryscan_references(), to determine the triviality of a SubqueryScan that is a child of an Append plan node, which is done before doing finalize_plan() on the SubqueryScan (if necessary) and set_plan_references() on the subplan, unlike when called from set_subqueryscan_references(). The reason why this is safe wouldn't be that obvious, so add comments explaining this. Follow-up for commit c2bb02b. Reviewed by Zhihong Yu. Discussion: https://postgr.es/m/CAPmGK17%2BGiJBthC6va7%2B9n6t75e-M1N0U18YB2G1B%2BE5OdrNTA%40mail.gmail.com
1 parent e77de23 commit 4a8a5dd

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/backend/optimizer/plan/setrefs.c

+18-3
Original file line numberDiff line numberDiff line change
@@ -1349,8 +1349,23 @@ set_subqueryscan_references(PlannerInfo *root,
13491349
* We can delete it if it has no qual to check and the targetlist just
13501350
* regurgitates the output of the child plan.
13511351
*
1352-
* This might be called repeatedly on a SubqueryScan node, so we cache the
1353-
* result in the SubqueryScan node to avoid repeated computation.
1352+
* This can be called from mark_async_capable_plan(), a helper function for
1353+
* create_append_plan(), before set_subqueryscan_references(), to determine
1354+
* triviality of a SubqueryScan that is a child of an Append node. So we
1355+
* cache the result in the SubqueryScan node to avoid repeated computation.
1356+
*
1357+
* Note: when called from mark_async_capable_plan(), we determine the result
1358+
* before running finalize_plan() on the SubqueryScan node (if needed) and
1359+
* set_plan_references() on the subplan tree, but this would be safe, because
1360+
* 1) finalize_plan() doesn't modify the tlist or quals for the SubqueryScan
1361+
* node (or that for any plan node in the subplan tree), and
1362+
* 2) set_plan_references() modifies the tlist for every plan node in the
1363+
* subplan tree, but keeps const/resjunk columns as const/resjunk ones and
1364+
* preserves the length and order of the tlist, and
1365+
* 3) set_plan_references() might delete the topmost plan node like an Append
1366+
* or MergeAppend from the subplan tree and pull up the child plan node,
1367+
* but in that case, the tlist for the child plan node exactly matches the
1368+
* parent.
13541369
*/
13551370
bool
13561371
trivial_subqueryscan(SubqueryScan *plan)
@@ -1359,7 +1374,7 @@ trivial_subqueryscan(SubqueryScan *plan)
13591374
ListCell *lp,
13601375
*lc;
13611376

1362-
/* We might have detected this already (see mark_async_capable_plan) */
1377+
/* We might have detected this already; in which case reuse the result */
13631378
if (plan->scanstatus == SUBQUERY_SCAN_TRIVIAL)
13641379
return true;
13651380
if (plan->scanstatus == SUBQUERY_SCAN_NONTRIVIAL)

0 commit comments

Comments
 (0)