diff options
author | Etsuro Fujita <efujita@postgresql.org> | 2022-04-06 15:45:00 +0900 |
---|---|---|
committer | Etsuro Fujita <efujita@postgresql.org> | 2022-04-06 15:45:00 +0900 |
commit | c2bb02bc2e858ba345b8b33f1f3a54628f719d93 (patch) | |
tree | fe742ab96982b0a74ed615d0c1e4c0982715a6e6 /src/backend/optimizer/plan/setrefs.c | |
parent | 376dc437de40bd17e99a37f72f88627a16d7f200 (diff) |
Allow asynchronous execution in more cases.
In commit 27e1f1456, create_append_plan() only allowed the subplan
created from a given subpath to be executed asynchronously when it was
an async-capable ForeignPath. To extend coverage, this patch handles
cases when the given subpath includes some other Path types as well that
can be omitted in the plan processing, such as a ProjectionPath directly
atop an async-capable ForeignPath, allowing asynchronous execution in
partitioned-scan/partitioned-join queries with non-Var tlist expressions
and more UNION queries.
Andrey Lepikhov and Etsuro Fujita, reviewed by Alexander Pyhalov and
Zhihong Yu.
Discussion: https://postgr.es/m/659c37a8-3e71-0ff2-394c-f04428c76f08%40postgrespro.ru
Diffstat (limited to 'src/backend/optimizer/plan/setrefs.c')
-rw-r--r-- | src/backend/optimizer/plan/setrefs.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/backend/optimizer/plan/setrefs.c b/src/backend/optimizer/plan/setrefs.c index bf4c722c028..7519723081d 100644 --- a/src/backend/optimizer/plan/setrefs.c +++ b/src/backend/optimizer/plan/setrefs.c @@ -115,7 +115,6 @@ static Plan *set_indexonlyscan_references(PlannerInfo *root, static Plan *set_subqueryscan_references(PlannerInfo *root, SubqueryScan *plan, int rtoffset); -static bool trivial_subqueryscan(SubqueryScan *plan); static Plan *clean_up_removed_plan_level(Plan *parent, Plan *child); static void set_foreignscan_references(PlannerInfo *root, ForeignScan *fscan, @@ -1319,14 +1318,26 @@ set_subqueryscan_references(PlannerInfo *root, * * We can delete it if it has no qual to check and the targetlist just * regurgitates the output of the child plan. + * + * This might be called repeatedly on a SubqueryScan node, so we cache the + * result in the SubqueryScan node to avoid repeated computation. */ -static bool +bool trivial_subqueryscan(SubqueryScan *plan) { int attrno; ListCell *lp, *lc; + /* We might have detected this already (see mark_async_capable_plan) */ + if (plan->scanstatus == SUBQUERY_SCAN_TRIVIAL) + return true; + if (plan->scanstatus == SUBQUERY_SCAN_NONTRIVIAL) + return false; + Assert(plan->scanstatus == SUBQUERY_SCAN_UNKNOWN); + /* Initially, mark the SubqueryScan as non-deletable from the plan tree */ + plan->scanstatus = SUBQUERY_SCAN_NONTRIVIAL; + if (plan->scan.plan.qual != NIL) return false; @@ -1368,6 +1379,9 @@ trivial_subqueryscan(SubqueryScan *plan) attrno++; } + /* Re-mark the SubqueryScan as deletable from the plan tree */ + plan->scanstatus = SUBQUERY_SCAN_TRIVIAL; + return true; } |