diff options
Diffstat (limited to 'src/backend/optimizer/prep/prepjointree.c')
-rw-r--r-- | src/backend/optimizer/prep/prepjointree.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c index 5d163292c58..ac622a34d9d 100644 --- a/src/backend/optimizer/prep/prepjointree.c +++ b/src/backend/optimizer/prep/prepjointree.c @@ -246,6 +246,7 @@ pull_up_sublinks_jointree_recurse(PlannerInfo *root, Node *jtnode, * as a sublink that is executed only for row pairs that meet the * other join conditions. Fixing this seems to require considerable * restructuring of the executor, but maybe someday it can happen. + * (See also the comparable case in pull_up_sublinks_qual_recurse.) * * We don't expect to see any pre-existing JOIN_SEMI or JOIN_ANTI * nodes here. @@ -331,9 +332,7 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node, j->rarg = pull_up_sublinks_jointree_recurse(root, j->rarg, &child_rels); - /* Pulled-up ANY/EXISTS quals can use those rels too */ - child_rels = bms_add_members(child_rels, available_rels); - /* ... and any inserted joins get stacked onto j->rarg */ + /* Any inserted joins get stacked onto j->rarg */ j->quals = pull_up_sublinks_qual_recurse(root, j->quals, child_rels, @@ -355,9 +354,7 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node, j->rarg = pull_up_sublinks_jointree_recurse(root, j->rarg, &child_rels); - /* Pulled-up ANY/EXISTS quals can use those rels too */ - child_rels = bms_add_members(child_rels, available_rels); - /* ... and any inserted joins get stacked onto j->rarg */ + /* Any inserted joins get stacked onto j->rarg */ j->quals = pull_up_sublinks_qual_recurse(root, j->quals, child_rels, @@ -377,7 +374,6 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node, /* If the immediate argument of NOT is EXISTS, try to convert */ SubLink *sublink = (SubLink *) get_notclausearg((Expr *) node); JoinExpr *j; - Relids child_rels; if (sublink && IsA(sublink, SubLink)) { @@ -387,17 +383,27 @@ pull_up_sublinks_qual_recurse(PlannerInfo *root, Node *node, available_rels); if (j) { + /* + * For the moment, refrain from recursing underneath NOT. + * As in pull_up_sublinks_jointree_recurse, recursing here + * would result in inserting a join underneath an ANTI + * join with which it could not commute, and that could + * easily lead to a worse plan than what we've + * historically generated. + */ +#ifdef NOT_USED /* Yes; recursively process what we pulled up */ + Relids child_rels; + j->rarg = pull_up_sublinks_jointree_recurse(root, j->rarg, &child_rels); - /* Pulled-up ANY/EXISTS quals can use those rels too */ - child_rels = bms_add_members(child_rels, available_rels); - /* ... and any inserted joins get stacked onto j->rarg */ + /* Any inserted joins get stacked onto j->rarg */ j->quals = pull_up_sublinks_qual_recurse(root, j->quals, child_rels, &j->rarg); +#endif /* Now insert the new join node into the join tree */ j->larg = *jtlink; *jtlink = (Node *) j; |