summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/path/pathkeys.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/optimizer/path/pathkeys.c')
-rw-r--r--src/backend/optimizer/path/pathkeys.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c
index e5228a81c63..991e0965124 100644
--- a/src/backend/optimizer/path/pathkeys.c
+++ b/src/backend/optimizer/path/pathkeys.c
@@ -224,6 +224,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.
@@ -240,6 +245,7 @@ make_pathkey_from_sortinfo(PlannerInfo *root,
bool reverse_sort,
bool nulls_first,
Index sortref,
+ Relids rel,
bool create_it,
bool canonicalize)
{
@@ -271,7 +277,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)
@@ -323,6 +329,7 @@ make_pathkey_from_sortop(PlannerInfo *root,
(strategy == BTGreaterStrategyNumber),
nulls_first,
sortref,
+ NULL,
create_it,
canonicalize);
}
@@ -554,6 +561,7 @@ build_index_pathkeys(PlannerInfo *root,
reverse_sort,
nulls_first,
0,
+ index->rel->relids,
false,
true);
@@ -677,6 +685,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
sub_member->em_datatype,
sub_eclass->ec_collation,
0,
+ rel->relids,
false);
/*
@@ -721,6 +730,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);
@@ -760,6 +772,7 @@ convert_subquery_pathkeys(PlannerInfo *root, RelOptInfo *rel,
sub_expr_type,
sub_expr_coll,
0,
+ rel->relids,
false);
/*
@@ -951,6 +964,7 @@ initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
lefttype,
((OpExpr *) clause)->inputcollid,
0,
+ NULL,
true);
restrictinfo->right_ec =
get_eclass_for_sort_expr(root,
@@ -959,6 +973,7 @@ initialize_mergeclause_eclasses(PlannerInfo *root, RestrictInfo *restrictinfo)
righttype,
((OpExpr *) clause)->inputcollid,
0,
+ NULL,
true);
}