diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index fc036e1..4835013 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -1545,17 +1545,13 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, } } - /* - * If we found unparameterized paths for all children, build an unordered, - * unparameterized Append path for the rel. (Note: this is correct even - * if we have no live subpaths due to constraint exclusion.) - */ if (subpaths_valid) { /* * If only a single subpath exists then we've no need for the Append * at all. Here we'll generate a "proxy" path in rel for each of the - * subpath rel's paths. + * subpath rel's paths. This allows full flexibility for generating + * plans as if the only-child relation had been queried directly. */ if (list_length(subpaths) == 1) { @@ -1567,6 +1563,11 @@ add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, } else { + /* + * Otherwise, build an unordered, unparameterized Append path for + * the rel. (Note: this is correct even if we have no live + * subpaths due to constraint exclusion.) + */ add_path(rel, (Path *) create_append_path(rel, subpaths, NIL, NULL, 0, false, partitioned_rels, -1, diff --git a/src/backend/optimizer/path/equivclass.c b/src/backend/optimizer/path/equivclass.c index 97a77fe..a9fce91 100644 --- a/src/backend/optimizer/path/equivclass.c +++ b/src/backend/optimizer/path/equivclass.c @@ -2105,39 +2105,38 @@ promote_child_rel_equivalences(PlannerInfo *root, Relids childrelids) foreach(lc1, root->eq_classes) { - EquivalenceClass *cur_ec = (EquivalenceClass *) lfirst(lc1); + EquivalenceClass *ec = lfirst_node(EquivalenceClass, lc1); ListCell *lc2; /* * No need to search in eclasses with volatile expressions, there will * be no child exprs in here. */ - if (cur_ec->ec_has_volatile) + if (ec->ec_has_volatile) continue; - foreach(lc2, cur_ec->ec_members) + foreach(lc2, ec->ec_members) { - EquivalenceMember *cur_em = (EquivalenceMember *) lfirst(lc2); + EquivalenceMember *em = lfirst_node(EquivalenceMember, lc2); - if (!cur_em->em_is_child) + if (!em->em_is_child) continue; /* ignore non-child members */ - if (cur_em->em_is_const) + if (em->em_is_const) continue; /* ignore consts here */ /* skip if it doesn't reference these childrelids */ - if (!bms_overlap(cur_em->em_relids, childrelids)) + if (!bms_overlap(em->em_relids, childrelids)) continue; - cur_em->em_is_child = false; + em->em_is_child = false; /* * The eclass will need to be updated to say which relids it * contains members for. These were previously not set due to the * member belonging to a child rel. */ - cur_ec->ec_relids = bms_add_members(cur_ec->ec_relids, - cur_em->em_relids); + ec->ec_relids = bms_add_members(ec->ec_relids, em->em_relids); } } } diff --git a/src/backend/optimizer/util/pathnode.c b/src/backend/optimizer/util/pathnode.c index b8456f0..de98293 100644 --- a/src/backend/optimizer/util/pathnode.c +++ b/src/backend/optimizer/util/pathnode.c @@ -1208,7 +1208,7 @@ create_tidscan_path(PlannerInfo *root, RelOptInfo *rel, List *tidquals, * pathnode. * * Note that we must handle subpaths = NIL, representing a dummy access path. - * If isproxy is true, then we expect only a single subpath. translate_from + * If is_proxy is true, then we expect only a single subpath. translate_from * and translate_to can be set to allow translation of Exprs between the * subpath and the Append Rel. */ @@ -1219,7 +1219,7 @@ create_append_path(RelOptInfo *rel, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows, List *translate_from, List *translate_to, - bool isproxy) + bool is_proxy) { AppendPath *pathnode = makeNode(AppendPath); ListCell *l; @@ -1240,13 +1240,13 @@ create_append_path(RelOptInfo *rel, pathnode->translate_from = translate_from; pathnode->translate_to = translate_to; pathnode->subpaths = subpaths; - pathnode->isproxy = isproxy; + pathnode->is_proxy = is_proxy; /* * If this is a proxy Append, there can be only one subpath, so we're able * to use its PathKeys. */ - if (isproxy) + if (is_proxy) { Assert(list_length(subpaths) == 1); pathnode->path.pathkeys = ((Path *) linitial(subpaths))->pathkeys; @@ -3600,7 +3600,7 @@ reparameterize_path(PlannerInfo *root, Path *path, -1, apath->translate_from, apath->translate_to, - apath->isproxy); + apath->is_proxy); } default: break; diff --git a/src/include/nodes/relation.h b/src/include/nodes/relation.h index 0def0f8..1c56615 100644 --- a/src/include/nodes/relation.h +++ b/src/include/nodes/relation.h @@ -1279,15 +1279,31 @@ typedef struct CustomPath * * An AppendPath with a single subpath can be set up to become a "proxy" path. * This allows a Path which belongs to one relation to be added to the pathlist - * of some other relation. This is intended as generic infrastructure, but its - * primary use case is to allow Appends with only a single subpath to be - * removed from the final plan. - * + * of some other relation. + * + * Normally, a query has a fixed set of base relations. These base relations + * are the ones which the join search is performed upon. Proxy paths are + * useful as there are some cases where it is possible to scan another + * relation instead of scanning a base relation. In order to make this + * possible the path to the other relation must be added to the base + * relation's pathlist as a sort of "foreign" path, however, the "forign" + * word is already used by foreign data wrappers, so we call these + * "proxy paths" instead. + * + * These proxy paths never actually make it into the final plan, they're + * simply skipped over when the final plan is being created, instead a node is + * created for the real path which the proxy path is storing. This path is + * stored as a single element of the 'subpaths' List. + * * A path's targetlist naturally will contain Vars belonging to its parent * rel, so we must also provide a mechanism to allow the translation of any * Vars which reference the original Append relation's Vars to allow them to * be translated into the proxied path Vars. translate_from and translate_to - * serve this purpose. They must only be set when isproxy is true. + * serve this purpose. They must only be set when is_proxy is true. + * + * This is intended as generic infrastructure to allow paths to be added to + * relations which they don't belong to, however, its primary use case is to + * allow Appends with only a single subpath to be removed from the final plan. */ typedef struct AppendPath { @@ -1300,7 +1316,7 @@ typedef struct AppendPath List *translate_from; List *translate_to; - bool isproxy; + bool is_proxy; } AppendPath; #define IS_DUMMY_PATH(p) \ @@ -1313,7 +1329,7 @@ typedef struct AppendPath /* Append path is acting as a proxy for its single subpath */ #define IS_PROXY_PATH(p) \ - (IsA((p), AppendPath) && ((AppendPath *) (p))->isproxy) + (IsA((p), AppendPath) && ((AppendPath *) (p))->is_proxy) /* * MergeAppendPath represents a MergeAppend plan, ie, the merging of sorted diff --git a/src/include/optimizer/pathnode.h b/src/include/optimizer/pathnode.h index a2dad71..43eed8e 100644 --- a/src/include/optimizer/pathnode.h +++ b/src/include/optimizer/pathnode.h @@ -70,7 +70,7 @@ extern AppendPath *create_append_path(RelOptInfo *rel, int parallel_workers, bool parallel_aware, List *partitioned_rels, double rows, List *translate_from, List *translate_to, - bool isproxy); + bool is_proxy); extern MergeAppendPath *create_merge_append_path(PlannerInfo *root, RelOptInfo *rel, List *subpaths,