diff options
Diffstat (limited to 'src/backend/optimizer/path/pathkeys.c')
-rw-r--r-- | src/backend/optimizer/path/pathkeys.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index 653387e582d..4ff8016666d 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -221,6 +221,11 @@ canonicalize_pathkeys(PlannerInfo *root, List *pathkeys) * If the PathKey is being generated from a SortGroupClause, sortref should be * the SortGroupClause's SortGroupRef; otherwise zero. * + * If rel is not NULL, it identifies a specific relation we're considering + * a path for, and indicates that child EC members for that relation can be + * considered. Otherwise child members are ignored. (See the comments for + * get_eclass_for_sort_expr.) + * * create_it is TRUE if we should create any missing EquivalenceClass * needed to represent the sort key. If it's FALSE, we return NULL if the * sort key isn't already present in any EquivalenceClass. @@ -237,6 +242,7 @@ make_pathkey_from_sortinfo(PlannerInfo *root, bool reverse_sort, bool nulls_first, Index sortref, + Relids rel, bool create_it, bool canonicalize) { @@ -268,7 +274,7 @@ make_pathkey_from_sortinfo(PlannerInfo *root, /* Now find or (optionally) create a matching EquivalenceClass */ eclass = get_eclass_for_sort_expr(root, expr, opfamilies, opcintype, collation, - sortref, create_it); + sortref, rel, create_it); /* Fail if no EC and !create_it */ if (!eclass) @@ -320,6 +326,7 @@ make_pathkey_from_sortop(PlannerInfo *root, (strategy == BTGreaterStrategyNumber), nulls_first, sortref, + NULL, create_it, canonicalize); } @@ -546,6 +553,7 @@ build_index_pathkeys(PlannerInfo *root, reverse_sort, nulls_first, 0, + index->rel->relids, false, true); @@ -636,6 +644,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, sub_member->em_datatype, sub_eclass->ec_collation, 0, + rel->relids, false); /* @@ -680,6 +689,9 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, Oid sub_expr_coll = sub_eclass->ec_collation; ListCell *k; + if (sub_member->em_is_child) + continue; /* ignore children here */ + foreach(k, sub_tlist) { TargetEntry *tle = (TargetEntry *) lfirst(k); @@ -719,6 +731,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel, sub_expr_type, sub_expr_coll, 0, + rel->relids, false); /* @@ -910,6 +923,7 @@ initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo) lefttype, ((OpExpr *) clause)->inputcollid, 0, + NULL, true); restrictinfo->right_ec = get_eclass_for_sort_expr(root, @@ -918,6 +932,7 @@ initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo) righttype, ((OpExpr *) clause)->inputcollid, 0, + NULL, true); } |